utils/watchcat: Fix some typos (mostly found by codespell)
Note that this implies an API change (allways -> always). The wrong spelling "allways" is still accepted for backward compatibility. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
717f467f15
commit
afbe8dcb87
2 changed files with 18 additions and 12 deletions
|
@ -25,20 +25,23 @@ timetoseconds() {
|
||||||
|
|
||||||
load_watchcat() {
|
load_watchcat() {
|
||||||
config_get period $1 period
|
config_get period $1 period
|
||||||
config_get mode $1 mode "allways"
|
config_get mode $1 mode "always"
|
||||||
config_get pinghosts $1 pinghosts "8.8.8.8"
|
config_get pinghosts $1 pinghosts "8.8.8.8"
|
||||||
config_get pingperiod $1 pingperiod
|
config_get pingperiod $1 pingperiod
|
||||||
config_get forcedelay $1 forcedelay "0"
|
config_get forcedelay $1 forcedelay "0"
|
||||||
|
|
||||||
|
# Fix potential typo in mode (backward compatibility).
|
||||||
|
[ "$mode" = "allways" ] && mode="always"
|
||||||
|
|
||||||
error=""
|
error=""
|
||||||
|
|
||||||
timetoseconds "$period"
|
timetoseconds "$period"
|
||||||
period="$seconds"
|
period="$seconds"
|
||||||
[ "$period" -ge 1 ] \
|
[ "$period" -ge 1 ] \
|
||||||
|| append_string "error" 'period is not a valid time value (ex: "30"; "4m"; "6h"; "2d")' "; "
|
|| append_string "error" 'period is not a valid time value (ex: "30"; "4m"; "6h"; "2d")' "; "
|
||||||
[ "$mode" = "allways" -o "$mode" = "ping" ] \
|
[ "$mode" = "always" -o "$mode" = "ping" ] \
|
||||||
|| append_string "error" "mode must be 'allways' or 'ping'" "; "
|
|| append_string "error" "mode must be 'always' or 'ping'" "; "
|
||||||
[ -n "$pinghosts" -o "$mode" = "allways" ] \
|
[ -n "$pinghosts" -o "$mode" = "always" ] \
|
||||||
|| append_string "error" "pinghosts must be set when in 'ping' mode" "; "
|
|| append_string "error" "pinghosts must be set when in 'ping' mode" "; "
|
||||||
[ "$mode" = "ping" ] && {
|
[ "$mode" = "ping" ] && {
|
||||||
if [ -n "$pingperiod" ]
|
if [ -n "$pingperiod" ]
|
||||||
|
@ -56,20 +59,20 @@ load_watchcat() {
|
||||||
pingperiod="$((period/20))"
|
pingperiod="$((period/20))"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
[ "$pingperiod" -lt "$period" -o "$mode" = "allways" ] \
|
[ "$pingperiod" -lt "$period" -o "$mode" = "always" ] \
|
||||||
|| append_string "error" "pingperiod is not recognized" "; "
|
|| append_string "error" "pingperiod is not recognized" "; "
|
||||||
[ "$forcedelay" -ge 0 ] \
|
[ "$forcedelay" -ge 0 ] \
|
||||||
|| append_string "error" "forcedelay must be a integer greater or equal than 0, where 0 means disabled" "; "
|
|| 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; }
|
[ -n "$error" ] && { logger -p user.err -t "watchcat" "reboot program $1 not started - $error"; return; }
|
||||||
|
|
||||||
if [ "$mode" = "allways" ]
|
if [ "$mode" = "always" ]
|
||||||
then
|
then
|
||||||
/usr/bin/watchcat.sh "allways" "$period" "$forcedelay" &
|
/usr/bin/watchcat.sh "always" "$period" "$forcedelay" &
|
||||||
logger -p user.info -t "wathchat" "started task (mode=$mode;period=$period;forcedelay=$forcedelay)"
|
logger -p user.info -t "watchcat" "started task (mode=$mode;period=$period;forcedelay=$forcedelay)"
|
||||||
else
|
else
|
||||||
/usr/bin/watchcat.sh "period" "$period" "$forcedelay" "$pinghosts" "$pingperiod" &
|
/usr/bin/watchcat.sh "period" "$period" "$forcedelay" "$pinghosts" "$pingperiod" &
|
||||||
logger -p user.info -t "wathchat" "started task (mode=$mode;period=$period;pinghosts=$pinghosts;pingperiod=$pingperiod;forcedelay=$forcedelay)"
|
logger -p user.info -t "watchcat" "started task (mode=$mode;period=$period;pinghosts=$pinghosts;pingperiod=$pingperiod;forcedelay=$forcedelay)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $! >> "${PIDFILE}.pids"
|
echo $! >> "${PIDFILE}.pids"
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
mode="$1"
|
mode="$1"
|
||||||
|
|
||||||
|
# Fix potential typo in mode (backward compatibility).
|
||||||
|
[ "$mode" = "allways" ] && mode="always"
|
||||||
|
|
||||||
shutdown_now() {
|
shutdown_now() {
|
||||||
local forcedelay="$1"
|
local forcedelay="$1"
|
||||||
|
|
||||||
|
@ -19,7 +22,7 @@ shutdown_now() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watchcat_allways() {
|
watchcat_always() {
|
||||||
local period="$1"; local forcedelay="$2"
|
local period="$1"; local forcedelay="$2"
|
||||||
|
|
||||||
sleep "$period" && shutdown_now "$forcedelay"
|
sleep "$period" && shutdown_now "$forcedelay"
|
||||||
|
@ -66,9 +69,9 @@ watchcat_ping() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$mode" = "allways" ]
|
if [ "$mode" = "always" ]
|
||||||
then
|
then
|
||||||
watchcat_allways "$2" "$3"
|
watchcat_always "$2" "$3"
|
||||||
else
|
else
|
||||||
watchcat_ping "$2" "$3" "$4" "$5"
|
watchcat_ping "$2" "$3" "$4" "$5"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue