1 #!/bin/sh /etc/rc.common
5 PIDFILE="/tmp/run/watchcat"
8 local varname="$1"; local add="$2"; local separator="${3:- }"; local actual
9 eval "actual=\$$varname"
11 new="${actual:+$actual$separator}$add"
19 { [ "$time" -ge 1 ] 2> /dev/null && seconds="$time"; } || \
20 { [ "${time%s}" -ge 1 ] 2> /dev/null && seconds="${time%s}"; } || \
21 { [ "${time%m}" -ge 1 ] 2> /dev/null && seconds=$((${time%m}*60)); } || \
22 { [ "${time%h}" -ge 1 ] 2> /dev/null && seconds=$((${time%h}*3600)); } || \
23 { [ "${time%d}" -ge 1 ] 2> /dev/null && seconds=$((${time%d}*86400)); }
27 config_get period $1 period
28 config_get mode $1 mode "allways"
29 config_get pinghosts $1 pinghosts "8.8.8.8"
30 config_get pingperiod $1 pingperiod "600"
31 config_get forcedelay $1 forcedelay "0"
35 timetoseconds "$period"
38 || append_string "error" "period is not set or not recognized" "; "
39 [ "$mode" = "allways" -o "$mode" = "ping" ] \
40 || append_string "error" "mode must be 'allways' or 'ping'" "; "
41 [ -n "$pinghosts" -o "$mode" = "allways" ] \
42 || append_string "error" "pinghosts must be set in 'ping' mode" "; "
43 timetoseconds "$pingperiod"
45 [ "$pingperiod" -lt "$period" -o "$mode" = "allways" ] \
46 || append_string "error" "pingperiod is not recognized" "; "
47 [ "$forcedelay" -ge 0 ] \
48 || append_string "error" "forcedelay must be a integer greater or equal than 0, where 0 means disabled" "; "
50 [ -n "$error" ] && { logger -p user.err -t "watchcat" "reboot program $1 not started - $error"; return; }
52 if [ "$mode" = "allways" ]
54 /usr/bin/watchcat.sh "allways" "$period" "$forcedelay" &
55 logger -p user.info -t "wathchat" "started task (mode=$mode;period=$period;forcedelay=$forcedelay)"
57 /usr/bin/watchcat.sh "period" "$period" "$forcedelay" "$pinghosts" "$pingperiod" &
58 logger -p user.info -t "wathchat" "started task (mode=$mode;pinghosts=$pinghosts;pingperiod=$pingperiod;forcedelay=$forcedelay)"
61 echo $! >> "${PIDFILE}.pids"
65 if [ -f "${PIDFILE}.pids" ]
67 logger -p user.info -t "watchcat" "stopping all tasks"
72 done < "${PIDFILE}.pids"
76 logger -p user.info -t "watchcat" "all tasks stopped"
78 logger -p user.info -t "watchcat" "no tasks running"
83 [ -f "${PIDFILE}.pids" ] && stop
86 if [ -n "$(uci show system.@watchcat[0])" ] # at least one watchcat section exists
88 logger -p user.info -t "watchcat" "starting all tasks"
89 config_foreach load_watchcat watchcat
90 logger -p user.info -t "watchcat" "all tasks started"
92 logger -p user.info -t "watchcat" "no tasks defined"