-
Notifications
You must be signed in to change notification settings - Fork 3.8k
watchcat: fix ping argument bug, add enabled option #28116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/bin/sh /etc/rc.common | ||
| # shellcheck shell=busybox | ||
|
|
||
| USE_PROCD=1 | ||
|
|
||
|
|
@@ -17,21 +18,23 @@ append_string() { | |
| } | ||
|
|
||
| time_to_seconds() { | ||
| time=$1 | ||
| time="$1" | ||
|
|
||
| { [ "$time" -ge 1 ] 2> /dev/null && seconds="$time"; } || | ||
| { [ "${time%s}" -ge 1 ] 2> /dev/null && seconds="${time%s}"; } || | ||
| { [ "${time%m}" -ge 1 ] 2> /dev/null && seconds=$((${time%m} * 60)); } || | ||
| { [ "${time%h}" -ge 1 ] 2> /dev/null && seconds=$((${time%h} * 3600)); } || | ||
| { [ "${time%d}" -ge 1 ] 2> /dev/null && seconds=$((${time%d} * 86400)); } | ||
|
|
||
| echo $seconds | ||
| echo "$seconds" | ||
| unset seconds | ||
| unset time | ||
| } | ||
|
|
||
| config_watchcat() { | ||
| # Read config | ||
| local enabled period mode pinghosts pingperiod forcedelay pingsize interface mmifacename unlockbands addressfamily script | ||
| config_get_bool enabled "$1" enabled 1 | ||
| config_get period "$1" period "120" | ||
| config_get mode "$1" mode "ping_reboot" | ||
| config_get pinghosts "$1" pinghosts "8.8.8.8" | ||
|
|
@@ -44,11 +47,17 @@ config_watchcat() { | |
| config_get addressfamily "$1" addressfamily "any" | ||
| config_get script "$1" script | ||
|
|
||
| # Skip disabled instances | ||
| [ "$enabled" = 1 ] || return | ||
|
|
||
| # Fix potential typo in mode and provide backward compatibility. | ||
| [ "$mode" = "allways" ] && mode="periodic_reboot" | ||
| [ "$mode" = "always" ] && mode="periodic_reboot" | ||
| [ "$mode" = "ping" ] && mode="ping_reboot" | ||
|
|
||
| # forward declaration for append_string | ||
| export error warn | ||
|
|
||
| # Checks for settings common to all operation modes | ||
| if [ "$mode" != "periodic_reboot" ] && [ "$mode" != "ping_reboot" ] && [ "$mode" != "restart_iface" ] && [ "$mode" != "run_script" ]; then | ||
| append_string "error" "mode must be 'periodic_reboot' or 'ping_reboot' or 'restart_iface' or 'run_script'" "; " | ||
|
|
@@ -61,7 +70,7 @@ config_watchcat() { | |
| # ping_reboot mode and restart_iface mode specific checks | ||
| if [ "$mode" = "ping_reboot" ] || [ "$mode" = "restart_iface" ] || [ "$mode" = "run_script" ]; then | ||
| if [ -z "$error" ]; then | ||
| pingperiod_default="$((period / 5))" | ||
| local pingperiod_default="$((period / 5))" | ||
| pingperiod="$(time_to_seconds "$pingperiod")" | ||
|
|
||
| if [ "$pingperiod" -ge 0 ] && [ "$pingperiod" -ge "$period" ]; then | ||
|
|
@@ -90,40 +99,36 @@ config_watchcat() { | |
|
|
||
| [ -n "$warn" ] && logger -p user.warn -t "watchcat" "$1: $warn" | ||
| [ -n "$error" ] && { | ||
| logger -p user.err -t "watchcat" "reboot program $1 not started - $error" | ||
| logger -s -p user.err -t "watchcat" "reboot program $1 not started - $error" | ||
| return | ||
| } | ||
|
|
||
| procd_open_instance "watchcat_${1}" | ||
|
|
||
| # Need to conditionally run mode functions because they have different signatures | ||
| case "$mode" in | ||
| periodic_reboot) | ||
| procd_open_instance "watchcat_${1}" | ||
| procd_set_param command /usr/bin/watchcat.sh "periodic_reboot" "$period" "$forcedelay" | ||
| procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" | ||
| procd_close_instance | ||
| ;; | ||
| ping_reboot) | ||
| procd_open_instance "watchcat_${1}" | ||
| procd_set_param command /usr/bin/watchcat.sh "ping_reboot" "$period" "$forcedelay" \"$pinghosts\" "$pingperiod" "$pingsize" "$addressfamily" "$interface" | ||
| procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" | ||
| procd_close_instance | ||
| procd_set_param command /usr/bin/watchcat.sh "ping_reboot" "$period" "$forcedelay" "$pinghosts" "$pingperiod" "$pingsize" "$addressfamily" "$interface" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This a code regression to v17 without any fix proposal, please correct me if I'm wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're wrong.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, thanks for providing the details. |
||
| ;; | ||
| restart_iface) | ||
| procd_open_instance "watchcat_${1}" | ||
| procd_set_param command /usr/bin/watchcat.sh "restart_iface" "$period" \"$pinghosts\" "$pingperiod" "$pingsize" "$interface" "$mmifacename" "$unlockbands" "$addressfamily" | ||
| procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" | ||
| procd_close_instance | ||
| procd_set_param command /usr/bin/watchcat.sh "restart_iface" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$mmifacename" "$unlockbands" "$addressfamily" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this a code regression to v17 without any fix proposal, please correct me if I'm wrong. |
||
| ;; | ||
| run_script) | ||
| procd_open_instance "watchcat_${1}" | ||
| procd_set_param command /usr/bin/watchcat.sh "run_script" "$period" \"$pinghosts\" "$pingperiod" "$pingsize" "$interface" "$addressfamily" "$script" | ||
| procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" | ||
| procd_close_instance | ||
| ;; | ||
| *) | ||
| echo "Error starting Watchcat service. Invalid mode selection: $mode" | ||
| procd_set_param command /usr/bin/watchcat.sh "run_script" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$addressfamily" "$script" | ||
| ;; | ||
| # *) # impossible case: checked above | ||
| # echo "Error starting Watchcat service. Invalid mode selection: $mode" | ||
| # ;; | ||
| esac | ||
|
|
||
| procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" | ||
| # simplify debugging | ||
| procd_set_param stdout 1 | ||
| procd_set_param stderr 1 | ||
| procd_close_instance | ||
| } | ||
|
|
||
| start_service() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.