Systemd Service / Timer
Create Systemd Service File (e.g.
wan-failover.service
):
Purpose: Defines how the failover script is run and managed by systemd.
Key Sections:
[Unit]
: Description, dependencies (e.g., network target)[Service]
: Specifies the script to execute (ExecStart
), user/group, restart policy (e.g., always restart on failure)[Install]
: Defines when the service should be enabled (e.g.,multi-user.target
)
[Unit]
Description=WAN Failover Service
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/path/to/wan-failover.sh
Restart=on-failure
RestartSec=10
User=cardano
[Install]
WantedBy=multi-user.target
ExecStartPre=/bin/sleep 10
: You might add a delay to allow network to initialize before running the script.
Create Systemd Timer File (e.g. wan-failover.timer):
Purpose: Periodically triggers the failover script.
[Unit]
Description=Timer for WAN Failover Script
[Timer]
OnBootSec=1min
OnUnitActiveSec=30
AccuracySec=10
[Install]
WantedBy=timers.target
This example runs the timer 1 minute after boot and then every 30 seconds. You can adjust these settings
Installation:
Save the script: Place the
wan-failover.sh
script in a suitable location (e.g.,/usr/local/bin
)Create the service file: Save the
wan-failover.service
file in/etc/systemd/system/
Create the timer file: Save the
wan-failover.timer
file in/etc/systemd/system/
Enable and start
To start WAN Failover as a service when the computer boots, type:
sudo systemctl daemon-reload
sudo systemctl enable wan-failover.service
Managing Services
To help administer an instance of WAN Failover running as a systemd
service, use the following commands:
To view the status of the WAN Failover service, type:
sudo systemctl status wan-failover.service
To restart the WAN Failover service, type:
sudo systemctl reload-or-restart wan-failover.service
To stop the WAN Failover service, type:
sudo systemctl stop wan-failover.service
To display the logs of WAN Failover service, type:
sudo journalctl -u wan-failover.service -f -o cat
Last updated