diff --git a/check_router_reboot.jl b/check_router_reboot.jl index 3633f18..62bd1cc 100644 --- a/check_router_reboot.jl +++ b/check_router_reboot.jl @@ -157,18 +157,40 @@ function check_router_once(ip::AbstractString; timeout=TIMEOUT_SECS) end end +# Check if running as root +function is_root()::Bool + try + result = read(`whoami`, String) + return strip(result) == "root" + catch + return false + end +end + # Reboot command selection # Return program and separate args as plain strings function reboot_command() if Sys.iswindows() return ("/usr/bin/cmd", "/C", "shutdown /r /t 0") elseif Sys.isapple() - return ("/usr/bin/sudo", "shutdown", "-r", "now") - elseif Sys.islinux() - if isfile("/bin/systemctl") || isfile("/usr/bin/systemctl") - return ("/usr/bin/sudo", "systemctl", "reboot") + if is_root() + return ("/sbin/reboot") else - return ("/usr/bin/sudo", "reboot") + return ("/usr/bin/sudo", "shutdown", "-r", "now") + end + elseif Sys.islinux() + if is_root() + if isfile("/bin/systemctl") + return ("/bin/systemctl", "reboot") + else + return ("/usr/sbin/reboot") + end + else + if isfile("/bin/systemctl") || isfile("/usr/bin/systemctl") + return ("/usr/bin/sudo", "systemctl", "reboot") + else + return ("/usr/bin/sudo", "reboot") + end end else return nothing diff --git a/check_router_reboot_log.txt b/check_router_reboot_log.txt index bc1e9ec..a7f6eb1 100644 --- a/check_router_reboot_log.txt +++ b/check_router_reboot_log.txt @@ -25,3 +25,49 @@ [2026-03-11T17:37:15.954] Starting check loop. Checking router 192.168.88.1 every 60 seconds. [2026-03-11T20:38:46.720] Starting check loop. Checking router 192.168.88.1 every 60 seconds. [2026-03-11T20:50:40.732] Starting check loop. Checking router 192.168.88.1 every 60 seconds. +[2026-03-12T18:00:51.749] Starting check loop. Checking router 192.168.88.1 every 60 seconds. +[2026-03-18T15:31:58.643] Starting check loop. Checking router 192.168.88.1 every 60 seconds. +[2026-03-19T15:08:25.431] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 1/3. +[2026-03-19T15:12:34.906] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 2/3. +[2026-03-19T15:16:44.259] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 3/3. +[2026-03-19T15:16:44.266] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:16:44.304] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:16:44.305] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:20:53.852] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 4/3. +[2026-03-19T15:20:53.853] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:20:53.853] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:20:53.853] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:25:00.572] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 5/3. +[2026-03-19T15:25:00.573] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:25:00.573] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:25:00.574] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:29:10.082] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 6/3. +[2026-03-19T15:29:10.084] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:29:10.084] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:29:10.084] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:33:19.474] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 7/3. +[2026-03-19T15:33:19.475] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:33:19.475] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:33:19.475] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:37:28.886] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 8/3. +[2026-03-19T15:37:28.886] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:37:28.887] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:37:28.887] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:41:38.214] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 9/3. +[2026-03-19T15:41:38.215] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:41:38.215] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:41:38.215] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:45:47.554] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 10/3. +[2026-03-19T15:45:47.555] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:45:47.556] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:45:47.556] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:49:57.051] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 11/3. +[2026-03-19T15:49:57.051] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:49:57.052] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:49:57.052] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:54:06.519] 192.168.88.1 is unreachable (last result: ProcessFailedException(Base.Process[Process(`ping -c 1 -W 30 192.168.88.1`, ProcessExited(1))])). Consecutive fails: 12/3. +[2026-03-19T15:54:06.520] Executing reboot command: /usr/bin/sudo systemctl reboot +[2026-03-19T15:54:06.553] Failed to execute reboot command: Base.IOError("could not spawn `/usr/bin/sudo systemctl reboot`: no such file or directory (ENOENT)", -2) +[2026-03-19T15:54:06.554] Reboot attempt failed; will retry after next interval. +[2026-03-19T15:58:26.336] Starting check loop. Checking router 192.168.88.1 every 60 seconds. +[2026-03-19T15:58:26.462] 192.168.88.1 is reachable; resetting consecutive failure counter.