stay up wifi daemon
This commit is contained in:
@@ -46,11 +46,12 @@
|
|||||||
|
|
||||||
./system-modules/simple-postgres.nix
|
./system-modules/simple-postgres.nix
|
||||||
] ++ (if hyper.isServer then [
|
] ++ (if hyper.isServer then [
|
||||||
|
./system-modules/stay-up.nix
|
||||||
|
|
||||||
./system-modules/nx2site.nix
|
./system-modules/nx2site.nix
|
||||||
./system-modules/hugo.nix
|
./system-modules/hugo.nix
|
||||||
./system-modules/postgres.nix
|
./system-modules/postgres.nix
|
||||||
./system-modules/nx2site/proxy.nix
|
./system-modules/nx2site/proxy.nix
|
||||||
|
|
||||||
# ./system-modules/nx2site/smtp.nix
|
# ./system-modules/nx2site/smtp.nix
|
||||||
# ./system-modules/nx2site/imap.nix
|
# ./system-modules/nx2site/imap.nix
|
||||||
# ./system-modules/nx2site/vmail.nix
|
# ./system-modules/nx2site/vmail.nix
|
||||||
|
|||||||
36
system-modules/stay-up.nix
Normal file
36
system-modules/stay-up.nix
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{ config, pkgs, ... }@all: with all; let
|
||||||
|
target = "1.1.1.1";
|
||||||
|
timeoutMinutes = 5;
|
||||||
|
logFile = "/var/log/stay-up.log";
|
||||||
|
in {
|
||||||
|
systemd.services.wifi-watchdog = {
|
||||||
|
description = "Wi-Fi Watchdog Service";
|
||||||
|
after = [ "network.target" "NetworkManager.service" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
path = with pkgs; [ iputils networkmanager coreutils ];
|
||||||
|
script = /* bash */ ''
|
||||||
|
FAIL_COUNT=0
|
||||||
|
touch "${logFile}"
|
||||||
|
while true; do
|
||||||
|
if ping -c 1 -W 5 "${target}" > /dev/null 2>&1; then
|
||||||
|
FAIL_COUNT=0
|
||||||
|
else
|
||||||
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||||||
|
if [ "$FAIL_COUNT" -ge "${toString timeoutMinutes}" ]; then
|
||||||
|
echo "$(date -Iseconds): Network unreachable for ${toString timeoutMinutes} minutes. Restarting Wi-Fi." >> "${logFile}"
|
||||||
|
nmcli radio wifi off
|
||||||
|
sleep 5
|
||||||
|
nmcli radio wifi on
|
||||||
|
FAIL_COUNT=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep 60
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = "10";
|
||||||
|
User = "root"; # Root is required to execute nmcli radio commands and write to /var/log/
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user