small-package/ddnsto/files/ddnsto-monitor.sh

50 lines
982 B
Bash
Raw Permalink Normal View History

2022-05-27 23:44:25 +08:00
#!/bin/sh
DEVICE_IDX=0
LOG_LEVEL=2
while getopts u:x:l: flag
do
case "${flag}" in
u) TOKEN=${OPTARG};;
x) DEVICE_IDX=${OPTARG};;
l) LOG_LEVEL=${OPTARG};;
esac
done
if [ -z "${TOKEN}" ]; then
2022-07-05 20:20:41 +08:00
logger "ddnsto: the token is empty, get token from https://www.ddnsto.com/ "
2022-05-27 23:44:25 +08:00
exit 2
fi
echo "ddnsto version device_id is is:"
/usr/sbin/ddnsto -u ${TOKEN} -w
_term() {
2022-07-05 20:20:41 +08:00
logger "ddnsto: SIGTERM"
2022-05-27 23:44:25 +08:00
killall ddnsto 2>/dev/null
2022-06-20 20:22:04 +08:00
killall ddwebdav 2>/dev/null
2022-05-30 08:56:54 +08:00
rm -f /tmp/.ddnsto.pid
rm -f /tmp/.ddnsto.status
rm -f /tmp/.ddnsto.up
2022-05-27 23:44:25 +08:00
exit
}
trap "_term;" SIGTERM
while true ; do
if ! pidof "ddnsto" > /dev/null ; then
2022-07-05 20:20:41 +08:00
logger "ddnsto try running"
2022-05-27 23:44:25 +08:00
/usr/sbin/ddnsto -u ${TOKEN} -x ${DEVICE_IDX} &
PID=$!
wait $PID
RET=$?
2022-07-05 20:20:41 +08:00
logger "ddnsto EXIT CODE: ${RET}"
2022-05-27 23:44:25 +08:00
if [ "${RET}" == "100" ]; then
2022-07-05 20:20:41 +08:00
logger "ddnsto token error, please set a correct token from https://www.ddnsto.com/ "
2022-05-27 23:44:25 +08:00
exit 100
fi
fi
sleep 20
done