Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43929736ca | |||
| f0e0bf4db8 | |||
| bd12ee9e49 | |||
| 6f77993798 | |||
| bfa68743da | |||
| dbd73958cf |
140
Manifest.toml
140
Manifest.toml
@@ -1,62 +1,14 @@
|
|||||||
# This file is machine-generated - editing it directly is not advised
|
# This file is machine-generated - editing it directly is not advised
|
||||||
|
|
||||||
julia_version = "1.12.1"
|
julia_version = "1.12.5"
|
||||||
manifest_format = "2.0"
|
manifest_format = "2.0"
|
||||||
project_hash = "324e0aa322681a327b337bcd7a8530af39c981d0"
|
project_hash = "9b274fc74610c14aa65af9a9d85650d80d379917"
|
||||||
|
|
||||||
[[deps.Artifacts]]
|
|
||||||
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.Base64]]
|
|
||||||
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.BitFlags]]
|
|
||||||
git-tree-sha1 = "0691e34b3bb8be9307330f88d1a3c3f25466c24d"
|
|
||||||
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
|
|
||||||
version = "0.1.9"
|
|
||||||
|
|
||||||
[[deps.CodecZlib]]
|
|
||||||
deps = ["TranscodingStreams", "Zlib_jll"]
|
|
||||||
git-tree-sha1 = "962834c22b66e32aa10f7611c08c8ca4e20749a9"
|
|
||||||
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
|
|
||||||
version = "0.7.8"
|
|
||||||
|
|
||||||
[[deps.ConcurrentUtilities]]
|
|
||||||
deps = ["Serialization", "Sockets"]
|
|
||||||
git-tree-sha1 = "d9d26935a0bcffc87d2613ce14c527c99fc543fd"
|
|
||||||
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
|
|
||||||
version = "2.5.0"
|
|
||||||
|
|
||||||
[[deps.Dates]]
|
[[deps.Dates]]
|
||||||
deps = ["Printf"]
|
deps = ["Printf"]
|
||||||
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
|
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
|
||||||
version = "1.11.0"
|
version = "1.11.0"
|
||||||
|
|
||||||
[[deps.ExceptionUnwrapping]]
|
|
||||||
deps = ["Test"]
|
|
||||||
git-tree-sha1 = "d36f682e590a83d63d1c7dbd287573764682d12a"
|
|
||||||
uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4"
|
|
||||||
version = "0.1.11"
|
|
||||||
|
|
||||||
[[deps.HTTP]]
|
|
||||||
deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "PrecompileTools", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
|
|
||||||
git-tree-sha1 = "5e6fe50ae7f23d171f44e311c2960294aaa0beb5"
|
|
||||||
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
|
|
||||||
version = "1.10.19"
|
|
||||||
|
|
||||||
[[deps.InteractiveUtils]]
|
|
||||||
deps = ["Markdown"]
|
|
||||||
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.JLLWrappers]]
|
|
||||||
deps = ["Artifacts", "Preferences"]
|
|
||||||
git-tree-sha1 = "0533e564aae234aff59ab625543145446d8b6ec2"
|
|
||||||
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
|
|
||||||
version = "1.7.1"
|
|
||||||
|
|
||||||
[[deps.JSON]]
|
[[deps.JSON]]
|
||||||
deps = ["Dates", "Logging", "Parsers", "PrecompileTools", "StructUtils", "UUIDs", "Unicode"]
|
deps = ["Dates", "Logging", "Parsers", "PrecompileTools", "StructUtils", "UUIDs", "Unicode"]
|
||||||
git-tree-sha1 = "eb04df293213df64ddd720c86de3c431f5f8ccf1"
|
git-tree-sha1 = "eb04df293213df64ddd720c86de3c431f5f8ccf1"
|
||||||
@@ -69,61 +21,10 @@ version = "1.2.1"
|
|||||||
[deps.JSON.weakdeps]
|
[deps.JSON.weakdeps]
|
||||||
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
|
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
|
||||||
|
|
||||||
[[deps.JuliaSyntaxHighlighting]]
|
|
||||||
deps = ["StyledStrings"]
|
|
||||||
uuid = "ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"
|
|
||||||
version = "1.12.0"
|
|
||||||
|
|
||||||
[[deps.Libdl]]
|
|
||||||
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.Logging]]
|
[[deps.Logging]]
|
||||||
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
|
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
|
||||||
version = "1.11.0"
|
version = "1.11.0"
|
||||||
|
|
||||||
[[deps.LoggingExtras]]
|
|
||||||
deps = ["Dates", "Logging"]
|
|
||||||
git-tree-sha1 = "f00544d95982ea270145636c181ceda21c4e2575"
|
|
||||||
uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36"
|
|
||||||
version = "1.2.0"
|
|
||||||
|
|
||||||
[[deps.Markdown]]
|
|
||||||
deps = ["Base64", "JuliaSyntaxHighlighting", "StyledStrings"]
|
|
||||||
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.MbedTLS]]
|
|
||||||
deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "NetworkOptions", "Random", "Sockets"]
|
|
||||||
git-tree-sha1 = "c067a280ddc25f196b5e7df3877c6b226d390aaf"
|
|
||||||
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
|
|
||||||
version = "1.1.9"
|
|
||||||
|
|
||||||
[[deps.MbedTLS_jll]]
|
|
||||||
deps = ["Artifacts", "JLLWrappers", "Libdl"]
|
|
||||||
git-tree-sha1 = "3cce3511ca2c6f87b19c34ffc623417ed2798cbd"
|
|
||||||
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
|
|
||||||
version = "2.28.10+0"
|
|
||||||
|
|
||||||
[[deps.MozillaCACerts_jll]]
|
|
||||||
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
|
|
||||||
version = "2025.5.20"
|
|
||||||
|
|
||||||
[[deps.NetworkOptions]]
|
|
||||||
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
|
|
||||||
version = "1.3.0"
|
|
||||||
|
|
||||||
[[deps.OpenSSL]]
|
|
||||||
deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "NetworkOptions", "OpenSSL_jll", "Sockets"]
|
|
||||||
git-tree-sha1 = "386b47442468acfb1add94bf2d85365dea10cbab"
|
|
||||||
uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c"
|
|
||||||
version = "1.6.0"
|
|
||||||
|
|
||||||
[[deps.OpenSSL_jll]]
|
|
||||||
deps = ["Artifacts", "Libdl"]
|
|
||||||
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
|
|
||||||
version = "3.5.1+0"
|
|
||||||
|
|
||||||
[[deps.Parsers]]
|
[[deps.Parsers]]
|
||||||
deps = ["Dates", "PrecompileTools", "UUIDs"]
|
deps = ["Dates", "PrecompileTools", "UUIDs"]
|
||||||
git-tree-sha1 = "7d2f8f21da5db6a806faf7b9b292296da42b2810"
|
git-tree-sha1 = "7d2f8f21da5db6a806faf7b9b292296da42b2810"
|
||||||
@@ -156,19 +57,6 @@ version = "1.11.0"
|
|||||||
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
|
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
|
||||||
[[deps.Serialization]]
|
|
||||||
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.SimpleBufferStream]]
|
|
||||||
git-tree-sha1 = "f305871d2f381d21527c770d4788c06c097c9bc1"
|
|
||||||
uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7"
|
|
||||||
version = "1.2.0"
|
|
||||||
|
|
||||||
[[deps.Sockets]]
|
|
||||||
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.StructUtils]]
|
[[deps.StructUtils]]
|
||||||
deps = ["Dates", "UUIDs"]
|
deps = ["Dates", "UUIDs"]
|
||||||
git-tree-sha1 = "79529b493a44927dd5b13dde1c7ce957c2d049e4"
|
git-tree-sha1 = "79529b493a44927dd5b13dde1c7ce957c2d049e4"
|
||||||
@@ -183,30 +71,11 @@ version = "2.6.0"
|
|||||||
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
|
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
|
||||||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
||||||
|
|
||||||
[[deps.StyledStrings]]
|
|
||||||
uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.TOML]]
|
[[deps.TOML]]
|
||||||
deps = ["Dates"]
|
deps = ["Dates"]
|
||||||
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
|
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
|
||||||
version = "1.0.3"
|
version = "1.0.3"
|
||||||
|
|
||||||
[[deps.Test]]
|
|
||||||
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
|
|
||||||
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
|
||||||
version = "1.11.0"
|
|
||||||
|
|
||||||
[[deps.TranscodingStreams]]
|
|
||||||
git-tree-sha1 = "0c45878dcfdcfa8480052b6ab162cdd138781742"
|
|
||||||
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
|
|
||||||
version = "0.11.3"
|
|
||||||
|
|
||||||
[[deps.URIs]]
|
|
||||||
git-tree-sha1 = "bef26fb046d031353ef97a82e3fdb6afe7f21b1a"
|
|
||||||
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
|
|
||||||
version = "1.6.1"
|
|
||||||
|
|
||||||
[[deps.UUIDs]]
|
[[deps.UUIDs]]
|
||||||
deps = ["Random", "SHA"]
|
deps = ["Random", "SHA"]
|
||||||
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
|
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
|
||||||
@@ -215,8 +84,3 @@ version = "1.11.0"
|
|||||||
[[deps.Unicode]]
|
[[deps.Unicode]]
|
||||||
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
|
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
|
||||||
version = "1.11.0"
|
version = "1.11.0"
|
||||||
|
|
||||||
[[deps.Zlib_jll]]
|
|
||||||
deps = ["Libdl"]
|
|
||||||
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
|
|
||||||
version = "1.3.1+2"
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
[deps]
|
[deps]
|
||||||
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
|
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
|
||||||
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ Both scripts run continuously in the background, performing periodic health chec
|
|||||||
```julia
|
```julia
|
||||||
const ROUTER_IP = "192.168.88.1" # Target router IP address
|
const ROUTER_IP = "192.168.88.1" # Target router IP address
|
||||||
const TIMEOUT_SECS = 30 # Request timeout in seconds
|
const TIMEOUT_SECS = 30 # Request timeout in seconds
|
||||||
const ATTEMPTS_PER_CHECK = 3 # Number of ping attempts per check
|
const ATTEMPTS_PER_CHECK = 1 # Number of ping attempts per check
|
||||||
const BACKOFF_BETWEEN_ATTEMPTS = 60 # Seconds between retry attempts
|
const BACKOFF_BETWEEN_ATTEMPTS = 1 # Seconds between retry attempts
|
||||||
const FAILS_TO_REBOOT = 3 # Consecutive failures before reboot
|
const FAILS_TO_REBOOT = 3 # Consecutive failures before reboot
|
||||||
const COOLDOWN_AFTER_REBOOT_SECS = 600 # Minimum seconds between reboots
|
const COOLDOWN_AFTER_REBOOT_SECS = 600 # Minimum seconds between reboots
|
||||||
const DRY_RUN = true # Set false to enable actual reboots
|
const DRY_RUN = false # Set false to enable actual reboots
|
||||||
const CHECK_INTERVAL_SECS = 60 # Check interval in seconds
|
const CHECK_INTERVAL_SECS = 60 # Check interval in seconds
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"last_reboot_datetime":"2026-01-31T12:56:40.834","consecutive_fails":0}
|
{"last_reboot_datetime":"2026-03-20T08:56:37.673","consecutive_fails":0}
|
||||||
@@ -9,15 +9,15 @@
|
|||||||
# ------------------------------------------------------------------------------------------------ #
|
# ------------------------------------------------------------------------------------------------ #
|
||||||
# *** juliar is root's julia (sudo crontab -e) but I symlinked to juliar because I want to seperate it from user's julia
|
# *** juliar is root's julia (sudo crontab -e) but I symlinked to juliar because I want to seperate it from user's julia
|
||||||
# @reboot /usr/local/bin/juliar /home/ton/docker-programs/check_and_reboot/check_router_reboot.jl >> /var/log/check_reboot.log 2>&1
|
# @reboot /usr/local/bin/juliar /home/ton/docker-programs/check_and_reboot/check_router_reboot.jl >> /var/log/check_reboot.log 2>&1
|
||||||
# @reboot /root/.juliaup/bin/julia /root/docker-apps/check_and_reboot/check_router_reboot.jl >> /var/log/check_reboot.log 2>&1
|
# @reboot sleep 30 && /root/.juliaup/bin/julia /root/docker-apps/check_and_reboot/check_router_reboot.jl >> /var/log/check_reboot.log 2>&1
|
||||||
|
|
||||||
using Dates, Printf, JSON
|
using Dates, Printf, JSON
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
const ROUTER_IP = "192.168.88.1"
|
const ROUTER_IP = "192.168.88.1"
|
||||||
const TIMEOUT_SECS = 30 # request timeout
|
const TIMEOUT_SECS = 30 # request timeout
|
||||||
const ATTEMPTS_PER_CHECK = 3 # number of ping attempts per check
|
const ATTEMPTS_PER_CHECK = 1 # number of ping attempts per check
|
||||||
const BACKOFF_BETWEEN_ATTEMPTS = 60 # seconds between attempts
|
const BACKOFF_BETWEEN_ATTEMPTS = 1 # seconds between ping attempts
|
||||||
const FAILS_TO_REBOOT = 3 # consecutive failed checks required to trigger reboot
|
const FAILS_TO_REBOOT = 3 # consecutive failed checks required to trigger reboot
|
||||||
const COOLDOWN_AFTER_REBOOT_SECS = 600 # do not reboot again within this many seconds
|
const COOLDOWN_AFTER_REBOOT_SECS = 600 # do not reboot again within this many seconds
|
||||||
const DRY_RUN = false # set false to actually reboot
|
const DRY_RUN = false # set false to actually reboot
|
||||||
@@ -128,7 +128,6 @@ end
|
|||||||
function save_state(st::State, StateFilePath)
|
function save_state(st::State, StateFilePath)
|
||||||
obj = Dict("consecutive_fails" => st.consecutive_fails,
|
obj = Dict("consecutive_fails" => st.consecutive_fails,
|
||||||
"last_reboot_datetime" => st.last_reboot_datetime)
|
"last_reboot_datetime" => st.last_reboot_datetime)
|
||||||
@show StateFilePath
|
|
||||||
JSON.json(StateFilePath, obj)
|
JSON.json(StateFilePath, obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -157,18 +156,40 @@ function check_router_once(ip::AbstractString; timeout=TIMEOUT_SECS)
|
|||||||
end
|
end
|
||||||
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
|
# Reboot command selection
|
||||||
# Return program and separate args as plain strings
|
# Return program and separate args as plain strings
|
||||||
function reboot_command()
|
function reboot_command()
|
||||||
if Sys.iswindows()
|
if Sys.iswindows()
|
||||||
return ("/usr/bin/cmd", "/C", "shutdown /r /t 0")
|
return ("/usr/bin/cmd", "/C", "shutdown /r /t 0")
|
||||||
elseif Sys.isapple()
|
elseif Sys.isapple()
|
||||||
return ("/usr/bin/sudo", "shutdown", "-r", "now")
|
if is_root()
|
||||||
elseif Sys.islinux()
|
return ("/sbin/reboot")
|
||||||
if isfile("/bin/systemctl") || isfile("/usr/bin/systemctl")
|
|
||||||
return ("/usr/bin/sudo", "systemctl", "reboot")
|
|
||||||
else
|
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
|
end
|
||||||
else
|
else
|
||||||
return nothing
|
return nothing
|
||||||
@@ -205,45 +226,48 @@ end
|
|||||||
|
|
||||||
# Single check iteration
|
# Single check iteration
|
||||||
function perform_check!(st::State)
|
function perform_check!(st::State)
|
||||||
if st.last_reboot_datetime !== nothing
|
|
||||||
timepass = ((Dates.now() - st.last_reboot_datetime).value / 1000) |> floor |> Int
|
|
||||||
|
|
||||||
if timepass < COOLDOWN_AFTER_REBOOT_SECS
|
success = false
|
||||||
logmsg("In cooldown after recent reboot; skipping check. $timepass/$COOLDOWN_AFTER_REBOOT_SECS seconds")
|
last_result = nothing
|
||||||
return
|
for i in 1:ATTEMPTS_PER_CHECK
|
||||||
|
ok, result = check_router_once(ROUTER_IP)
|
||||||
|
# ok, result = values(JSON.parsefile("test_ping_result.json")) # for testing without actual ping
|
||||||
|
if ok
|
||||||
|
success = true
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
sleep(BACKOFF_BETWEEN_ATTEMPTS)
|
||||||
|
end
|
||||||
|
routerresult = isnothing(last_result) ? "no response" : last_result
|
||||||
|
|
||||||
|
# Check if we're in cooldown period
|
||||||
|
in_cooldown = false
|
||||||
|
if st.last_reboot_datetime !== nothing
|
||||||
|
timepass = ((Dates.now() - st.last_reboot_datetime).value / 1000) |> floor |> Int
|
||||||
|
|
||||||
|
if timepass < COOLDOWN_AFTER_REBOOT_SECS
|
||||||
|
in_cooldown = true
|
||||||
end
|
end
|
||||||
success = false
|
end
|
||||||
last_result = nothing
|
|
||||||
for i in 1:ATTEMPTS_PER_CHECK
|
if in_cooldown
|
||||||
ok, result = check_router_once(ROUTER_IP)
|
# During cooldown, track failures but don't trigger reboot yet
|
||||||
last_result = result
|
|
||||||
if ok
|
|
||||||
success = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
sleep(BACKOFF_BETWEEN_ATTEMPTS)
|
|
||||||
end
|
|
||||||
if success
|
if success
|
||||||
if st.consecutive_fails > 0
|
logmsg("$ROUTER_IP is reachable during cooldown. Router is back online! Resetting state.")
|
||||||
logmsg("$ROUTER_IP is reachable; resetting consecutive failure counter.")
|
st.consecutive_fails = 0
|
||||||
else
|
save_state(st, StateFilePath)
|
||||||
# logmsg("$ROUTER_IP is reachable.")
|
|
||||||
end
|
|
||||||
st.consecutive_fails = 0
|
|
||||||
save_state(st, StateFilePath)
|
|
||||||
return
|
|
||||||
else
|
else
|
||||||
st.consecutive_fails += 1
|
st.consecutive_fails += 1
|
||||||
routerresult = isnothing(last_result) ? "no response" : last_result
|
|
||||||
logmsg("$ROUTER_IP is unreachable (last result: $routerresult). Consecutive fails: $(st.consecutive_fails)/$FAILS_TO_REBOOT.")
|
logmsg("$ROUTER_IP is unreachable during cooldown. Consecutive fails: $(st.consecutive_fails)/$FAILS_TO_REBOOT.")
|
||||||
save_state(st, StateFilePath)
|
save_state(st, StateFilePath)
|
||||||
end
|
|
||||||
if st.consecutive_fails >= FAILS_TO_REBOOT
|
# Check if we've reached threshold by now
|
||||||
save_state(st, StateFilePath)
|
if st.consecutive_fails >= FAILS_TO_REBOOT
|
||||||
|
logmsg("Cooldown has expired and router is still unreachable. Triggering reboot.")
|
||||||
ok = do_reboot()
|
ok = do_reboot()
|
||||||
if ok
|
if ok
|
||||||
thisFilePath = @__FILE__
|
thisFilePath = @__FILE__
|
||||||
broadcast_msg("Broadcasting from file: $thisFilePath")
|
broadcast_msg("Broadcasting from file: $thisFilePath")
|
||||||
logmsg("Reboot executed (or simulated). Resetting failure counter.")
|
logmsg("Reboot executed (or simulated). Resetting failure counter.")
|
||||||
st.consecutive_fails = 0
|
st.consecutive_fails = 0
|
||||||
@@ -252,7 +276,40 @@ function perform_check!(st::State)
|
|||||||
else
|
else
|
||||||
logmsg("Reboot attempt failed; will retry after next interval.")
|
logmsg("Reboot attempt failed; will retry after next interval.")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Outside cooldown - full check with potential reboot
|
||||||
|
if success
|
||||||
|
if st.consecutive_fails > 0
|
||||||
|
logmsg("$ROUTER_IP is reachable; resetting consecutive failure counter.")
|
||||||
|
else
|
||||||
|
# logmsg("$ROUTER_IP is reachable.")
|
||||||
|
end
|
||||||
|
st.consecutive_fails = 0
|
||||||
|
save_state(st, StateFilePath)
|
||||||
|
return
|
||||||
|
else
|
||||||
|
st.consecutive_fails += 1
|
||||||
|
logmsg("$ROUTER_IP is unreachable (last result: $routerresult). Consecutive fails: $(st.consecutive_fails)/$FAILS_TO_REBOOT.")
|
||||||
|
save_state(st, StateFilePath)
|
||||||
|
end
|
||||||
|
if st.consecutive_fails >= FAILS_TO_REBOOT
|
||||||
|
save_state(st, StateFilePath)
|
||||||
|
ok = do_reboot()
|
||||||
|
if ok
|
||||||
|
thisFilePath = @__FILE__
|
||||||
|
broadcast_msg("Broadcasting from file: $thisFilePath")
|
||||||
|
logmsg("Reboot executed (or simulated). Resetting failure counter.")
|
||||||
|
st.consecutive_fails = 0
|
||||||
|
st.last_reboot_datetime = Dates.now()
|
||||||
|
save_state(st, StateFilePath)
|
||||||
|
else
|
||||||
|
logmsg("Reboot attempt failed; will retry after next interval.")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,110 @@
|
|||||||
[2026-03-11T15:44:25.256] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T07:22:26.223] DRY RUN: would run reboot command: /bin/systemctl reboot
|
||||||
[2026-03-11T15:44:26.277] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T07:22:26.224] Reboot executed (or simulated). Resetting failure counter.
|
||||||
[2026-03-11T15:45:26.318] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T07:34:46.993] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
[2026-03-11T15:49:03.012] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T07:34:48.140] 192.168.88.1 is unreachable (last result: no response). Consecutive fails: 1/3.
|
||||||
[2026-03-11T15:49:03.985] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T07:35:48.328] 192.168.88.1 is reachable; resetting consecutive failure counter.
|
||||||
[2026-03-11T15:50:04.059] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T07:36:49.337] 192.168.88.1 is unreachable (last result: no response). Consecutive fails: 1/3.
|
||||||
[2026-03-11T15:51:04.131] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T07:37:50.385] 192.168.88.1 is unreachable (last result: no response). Consecutive fails: 2/3.
|
||||||
[2026-03-11T15:52:04.197] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T07:38:51.439] 192.168.88.1 is unreachable (last result: no response). Consecutive fails: 3/3.
|
||||||
[2026-03-11T15:53:04.266] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T07:38:51.451] DRY RUN: would run reboot command: /bin/systemctl reboot
|
||||||
[2026-03-11T16:10:04.474] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T07:38:51.452] Reboot executed (or simulated). Resetting failure counter.
|
||||||
[2026-03-11T16:10:05.449] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T08:01:26.083] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
[2026-03-11T16:12:13.704] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:03:30.730] 192.168.88.1 is unreachable (last result: no response). Consecutive fails: 1/3.
|
||||||
[2026-03-11T16:12:14.671] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T08:04:34.872] 192.168.88.1 is unreachable (last result: no response). Consecutive fails: 2/3.
|
||||||
[2026-03-11T16:13:14.215] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:05:39] 192.168.88.1 is unreachable (last result: no response). Consecutive fails: 3/3.
|
||||||
[2026-03-11T16:13:15.192] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T08:05:39.012] Executing reboot command: /bin/systemctl reboot
|
||||||
[2026-03-11T16:14:19.623] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:05:39.019] Reboot executed (or simulated). Resetting failure counter.
|
||||||
[2026-03-11T16:14:20.610] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T08:07:37.784] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
[2026-03-11T16:14:54.601] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:07:42.190] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
[2026-03-11T16:14:55.573] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T08:08:42.390] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
[2026-03-11T16:15:48.563] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:10:13.455] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
[2026-03-11T16:15:49.540] Error during check: SystemError("opening file \"/home/ton/docker-programs/check_and_reboot/check_and_reboot_state.json\"", 13, nothing)
|
[2026-03-20T08:11:17.576] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
[2026-03-11T16:27:47.181] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:12:21.703] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
[2026-03-11T16:30:28.572] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:12:21.703] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
[2026-03-11T16:43:50.213] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:12:21.715] Executing reboot command: /bin/systemctl reboot
|
||||||
[2026-03-11T17:37:15.954] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:12:21.722] Reboot executed (or simulated). Resetting failure counter.
|
||||||
[2026-03-11T20:38:46.720] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
[2026-03-20T08:14:14.104] 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-20T08:14:14.238] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T08:15:14.374] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T08:16:14.436] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T08:17:14.458] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T08:18:14.474] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T08:19:45.773] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:20:49.912] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:21:53.976] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:21:53.976] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:21:53.988] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:21:53.995] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:24:02.098] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:24:06.510] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:25:10.722] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:26:14.850] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:26:14.851] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:26:14.862] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:26:14.869] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:27:50.027] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:27:54.438] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:28:58.658] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:30:02.786] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:30:02.787] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:30:02.797] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:30:02.804] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:31:38.059] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:31:42.504] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:32:46.784] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:33:50.912] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:33:50.912] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:33:50.923] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:33:50.930] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:35:25.114] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:35:29.577] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:36:33.792] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:37:37.920] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:37:37.952] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:37:37.962] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:37:37.969] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:39:12.910] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:39:17.371] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:40:21.592] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:41:25.719] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:41:25.720] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:41:25.731] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:41:25.738] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:43:02.074] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:43:06.506] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:44:10.719] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:45:14.847] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:45:14.848] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:45:14.859] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:45:14.866] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:46:49.831] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:46:54.237] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:47:58.458] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:49:02.586] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:49:02.586] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:49:02.597] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:49:02.604] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:50:37.054] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:50:41.498] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:51:45.720] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:52:49.848] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:52:49.849] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:52:49.859] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:52:49.867] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:54:24.890] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:54:29.366] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 1/3.
|
||||||
|
[2026-03-20T08:55:33.590] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 2/3.
|
||||||
|
[2026-03-20T08:56:37.653] 192.168.88.1 is unreachable during cooldown. Consecutive fails: 3/3.
|
||||||
|
[2026-03-20T08:56:37.654] Cooldown has expired and router is still unreachable. Triggering reboot.
|
||||||
|
[2026-03-20T08:56:37.666] Executing reboot command: /bin/systemctl reboot
|
||||||
|
[2026-03-20T08:56:37.673] Reboot executed (or simulated). Resetting failure counter.
|
||||||
|
[2026-03-20T08:58:14.067] Starting check loop. Checking router 192.168.88.1 every 60 seconds.
|
||||||
|
[2026-03-20T08:58:14.202] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T08:59:14.320] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T09:00:14.415] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T09:01:14.477] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T09:02:14.534] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T09:03:14.597] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T09:04:14.660] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T09:05:14.722] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
[2026-03-20T09:06:14.784] 192.168.88.1 is reachable during cooldown. Router is back online! Resetting state.
|
||||||
|
|||||||
1
test_ping_result.json
Normal file
1
test_ping_result.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"ok": false, "result": "no response"}
|
||||||
Reference in New Issue
Block a user