Via systemd units, I have my VPN app (PIA VPN) set up to be terminated when my laptop suspends, and set-up to re-initialise when the network comes back up (the network automatically goes down when the system suspends and automatically comes back up when it wakes).
Thus I have a systemd unit like this for killing VPN on suspend:
Code:
[Unit]
Description=User suspend actions
Before=suspend.target
[Service]
User=%I
Environment=DISPLAY=:0
Type=oneshot
ExecStart=-/usr/bin/pkill -f pia
ExecStartPost=/usr/bin/sleep 5
[Install]
WantedBy=sleep.target
And a systemd unit like this for initialising the VPN on network resume:
Code:
[Unit]
Description=Restart PIA VPN
Requires=network.target
After=network.target
[Service]
Environment=DISPLAY=:0
User=%I
Type=forking
ExecStart=/usr/bin/sh /home/emacsomancer/pia.sh
Restart=always
RestartSec=5
[Install]
WantedBy=network.target
But what I additionally want (or perhaps in place of the first systemd unit above) is to kill the VPN when the network goes down. I can't figure out how to do this though.