Home Linux Tailscale Watchdog
Post
Cancel

Linux Tailscale Watchdog

Installing a software watch dog

Useful on a linux (debian or ubuntu in this case) system, relies on a kernel software watchdog.

This one attempts to ensure tailscale is always running.

1
sudo apt -y install watchdog

Create a watchdog.conf file:

1
2
3
4
5
6
7
8
9
cat <<'EOF' | sudo tee -a /etc/watchdog.conf

realtime            = yes
priority            = 1
interval            = 14
interface           = enp0s9
repair-binary       = /etc/watchdog.d/tailscale.sh
repair-maximum      = 3
EOF

Create a check script /etc/watchdog.d/tailscale.sh:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
sudo mkdir -p /etc/watchdog.d

cat <<'EOF' | sudo tee /etc/watchdog.d/tailscale.sh
#!/usr/bin/bash

if [[ "test" == "$1" ]]; then
    /usr/bin/tailscale status >/dev/null && exit 0

    logger Attempting to restart tailscaled
    /usr/bin/systemctl restart tailscaled && exit 0

    /usr/bin/tailscale status |& logger
    exit 1
elif [[ "repair" == "$1" ]]; then
    logger Attempting to repair tailscaled
    /usr/bin/systemctl restart tailscaled && exit 0

    /usr/bin/tailscale status |& logger
    exit 2
else
    logger Unexpected tailscale.sh command: $0 $*
    exit 3
fi
EOF

sudo chmod +x /etc/watchdog.d/tailscale.sh

Enable it:

1
2
3
sudo systemctl enable watchdog
sudo systemctl start watchdog
sudo systemctl status watchdog
This post is licensed under CC BY 4.0 by the author.