Thanks for the suggestion.
I tried doing something similar but it doesnt seem to be working. It doesnt restart the dietpi-nordvpn.service after it went down, so i still need to restart the service manually.
This is what i have, perhaps there are n00bie mistakes?
/etc/systemd/system/auto-reconnect-vpn.service
[Unit]
Description=Auto-Reconnect-VPN (NordVPN)
After=dietpi-nordvpn.service
[Service]
RemainAfterExit=yes
Type=simple
ExecStart=systemctl restart dietpi-nordvpn
[Install]
WantedBy=default.target
i then did:
sudo chmod 644 /etc/systemd/system/auto-reconnect-vpn.service
Followed by
sudo systemctl enable /etc/systemd/system/auto-reconnect-vpn.service
and
sudo systemctl enable /etc/systemd/system/auto-reconnect-vpn.service
I also added it to dietpi’s custom autostart script /var/lib/dietpi/dietpi-autostart/custom.sh
systemctl /etc/systemd/system/auto-reconnect-vpn.service
To test he above i did a
sudo systemctl stop dietpi-nordvpn.service
syslog shows the following:
Jul 4 02:15:28 BeastiPi openvpn[1275]: Sat Jul 4 02:15:28 2020 event_wait : Interrupted system call (code=4)
Jul 4 02:15:28 BeastiPi openvpn[1275]: Sat Jul 4 02:15:28 2020 SIGTERM received, sending exit notification to peer
Jul 4 02:15:28 BeastiPi systemd[1]: Stopping NordVPN (DietPi)...
Jul 4 02:15:29 BeastiPi openvpn[1275]: Sat Jul 4 02:15:29 2020 /var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/down.sh tun0 1500 1585 XXX.XXX.XXX.XXX 255.255.255.0 init
Jul 4 02:15:29 BeastiPi systemd[1]: Stopping Deluge Daemon (DietPi)...
Jul 4 02:15:29 BeastiPi systemd[1]: deluged.service: Succeeded.
Jul 4 02:15:29 BeastiPi systemd[1]: Stopped Deluge Daemon (DietPi).
Jul 4 02:15:29 BeastiPi systemd[1]: Stopping NZBget (DietPi)...
Jul 4 02:15:29 BeastiPi systemd[1]: nzbget.service: Succeeded.
Jul 4 02:15:29 BeastiPi systemd[1]: Stopped NZBget (DietPi).
Jul 4 02:15:29 BeastiPi openvpn[1275]: Sat Jul 4 02:15:29 2020 /sbin/ip route del XXX.XXX.XXX.XXX/32
Jul 4 02:15:29 BeastiPi openvpn[1275]: Sat Jul 4 02:15:29 2020 /sbin/ip route del 0.0.0.0/1
Jul 4 02:15:29 BeastiPi openvpn[1275]: Sat Jul 4 02:15:29 2020 /sbin/ip route del 128.0.0.0/1
Jul 4 02:15:29 BeastiPi openvpn[1275]: Sat Jul 4 02:15:29 2020 Closing TUN/TAP interface
Jul 4 02:15:29 BeastiPi openvpn[1275]: Sat Jul 4 02:15:29 2020 /sbin/ip addr del dev tun0 XXX.XXX.XXX.XXX/24
Jul 4 02:15:29 BeastiPi openvpn[1275]: Sat Jul 4 02:15:29 2020 SIGTERM[soft,exit-with-notification] received, process exiting
Jul 4 02:15:29 BeastiPi systemd[1]: dietpi-nordvpn.service: Succeeded.
Jul 4 02:15:29 BeastiPi systemd[1]: Stopped NordVPN (DietPi).
The dietpi-nordvpn.service stops successfully, and the down-script works as expected by shutting down deluge and nzbget. But as mentioned, the VPN doesnt come back up.
While trying to search a reason, I noticed that other services remain up after starting, my /etc/systemd/system/auto-reconnect-vpn.service does not.
dietpi@BeastiPi:~$ systemctl --type=service --state=active
UNIT LOAD ACTIVE SUB DESCRIPTION
argononed.service loaded active running Argon One Fan and Button Service
auto-reconnect-vpn.service loaded active [color=#00BF00]exited [/color] Auto-Reconnect-VPN (NordVPN)
...
i thought that by adding
[Service]
RemainAfterExit=yes
to the auto-reconnect-vpn.service it would stay up, but i was wrong.
I also noticed that services that are running exist in multiple locations. Some seem to be backups, but others i’m not sure.
For example: argononed.service
dietpi@BeastiPi:~$ sudo find / -name argononed.service
/etc/systemd/system/multi-user.target.wants/argononed.service
/mnt/dietpi-backup/data/etc/systemd/system/multi-user.target.wants/argononed.service
/mnt/dietpi-backup/data/lib/systemd/system/argononed.service
/sys/fs/cgroup/memory/system.slice/argononed.service
/sys/fs/cgroup/pids/system.slice/argononed.service
/sys/fs/cgroup/devices/system.slice/argononed.service
/sys/fs/cgroup/systemd/system.slice/argononed.service
/sys/fs/cgroup/unified/system.slice/argononed.service
/lib/systemd/system/argononed.service
Do i need to add my newly created service to these other locations. like /etc/systemd/system/multi-user.target.wants, /sys/fs/, /lib/systemd/system/, etc do have the service active – and – would this make the service work as intended, i.e., restart the “dietpi-nordvpn.service” should i go down?
Thanks