Created
October 20, 2017 18:42
-
-
Save raspi/54bd758a6e981d3379ad83c9458b0bcc to your computer and use it in GitHub Desktop.
Systemd service for pinging default gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save in /etc/systemd/system/network-ping-gateway.service | |
[Unit] | |
Description=Ping default network gateway service | |
After=network-online.target | |
[Service] | |
# Wait time if process hangs | |
TimeoutStopSec=1m | |
# Command to run | |
ExecStart=/bin/bash -c 'read _ _ gateway _ < <(ip route list match 0/0); ping -c 1 "$gateway"' | |
Type=simple | |
KillMode=process | |
KillSignal=SIGINT | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Timer which runs service | |
# Save in /etc/systemd/system/network-ping-gateway.timer | |
# Enable: | |
# systemctl enable /etc/systemd/system/network-ping-gateway.timer | |
# Start: | |
# systemctl start network-ping-gateway.timer | |
# Next run time: | |
# systemctl list-timers --all | |
[Unit] | |
Description=Ping network gateway timer | |
[Timer] | |
# Uptime after it's first ran | |
OnBootSec=1min | |
# Wait time for next run | |
OnUnitInactiveSec=1min | |
Unit=network-ping-gateway.service | |
Persistent=true | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment