@ -25,20 +25,23 @@ timetoseconds() {
load_watchcat() {
config_get period $1 period
config_get mode $1 mode "all ways"
config_get mode $1 mode "always"
config_get pinghosts $1 pinghosts "8.8.8.8"
config_get pingperiod $1 pingperiod
config_get forcedelay $1 forcedelay "0"
# Fix potential typo in mode (backward compatibility).
[ "$mode" = "allways" ] && mode="always"
error=""
timetoseconds "$period"
period="$seconds"
[ "$period" -ge 1 ] \
|| append_string "error" 'period is not a valid time value (ex: "30"; "4m"; "6h"; "2d")' "; "
[ "$mode" = "all ways" -o "$mode" = "ping" ] \
|| append_string "error" "mode must be 'all ways' or 'ping'" "; "
[ -n "$pinghosts" -o "$mode" = "all ways" ] \
[ "$mode" = "always" -o "$mode" = "ping" ] \
|| append_string "error" "mode must be 'always' or 'ping'" "; "
[ -n "$pinghosts" -o "$mode" = "always" ] \
|| append_string "error" "pinghosts must be set when in 'ping' mode" "; "
[ "$mode" = "ping" ] && {
if [ -n "$pingperiod" ]
@ -56,20 +59,20 @@ load_watchcat() {
pingperiod="$((period/20))"
fi
}
[ "$pingperiod" -lt "$period" -o "$mode" = "all ways" ] \
[ "$pingperiod" -lt "$period" -o "$mode" = "always" ] \
|| append_string "error" "pingperiod is not recognized" "; "
[ "$forcedelay" -ge 0 ] \
|| append_string "error" "forcedelay must be a integer greater or equal than 0, where 0 means disabled" "; "
[ -n "$error" ] && { logger -p user.err -t "watchcat" "reboot program $1 not started - $error"; return; }
if [ "$mode" = "all ways" ]
if [ "$mode" = "always" ]
then
/usr/bin/watchcat.sh "all ways" "$period" "$forcedelay" &
logger -p user.info -t "wath chat" "started task (mode=$mode;period=$period;forcedelay=$forcedelay)"
/usr/bin/watchcat.sh "always" "$period" "$forcedelay" &
logger -p user.info -t "watchc at" "started task (mode=$mode;period=$period;forcedelay=$forcedelay)"
else
/usr/bin/watchcat.sh "period" "$period" "$forcedelay" "$pinghosts" "$pingperiod" &
logger -p user.info -t "wath chat" "started task (mode=$mode;period=$period;pinghosts=$pinghosts;pingperiod=$pingperiod;forcedelay=$forcedelay)"
logger -p user.info -t "watchc at" "started task (mode=$mode;period=$period;pinghosts=$pinghosts;pingperiod=$pingperiod;forcedelay=$forcedelay)"
fi
echo $! >> "${PIDFILE}.pids"