I have a custom upstart job that triggers a series of services:
description "Auto-GateWay" author "email@example.com" emits gw-is-up emits gw-is-down start on (net-device-up or net-device-down) task script if route | grep -q "default"; then initctl emit -n gw-is-up else initctl emit -n gw-is-down fi end script
This works works extremely well on laptops that frequently disconnect and connect from networks, or when they sleep & wakeup. It also works on my servers when the network changes.
I am trying to convert this simple upstart job to systemd. My first attempt is:
[Unit] Description=Auto-Gateway service After=network-online.target [Service] ExecStart=/usr/sbin/auto-gateway KillMode=process Restart=always Type=forking TimeoutStartSec=infinity [Install] WantedBy=multi-user.target
#!/bin/bash while true; do if route | grep "default"; then start some services (if not running) else stop some services (if running) fi sleep 30 done >/dev/null
I find this to be a poor substitute to the upstart version. I dislike the fixed timer, and hard coding the secondary services into auto-gateway.
Is there any way systemd can monitor netdev instead?