Skip to content

Instantly share code, notes, and snippets.

@toggenation
Forked from magnetikonline/README.md
Last active October 17, 2023 20:02
Show Gist options
  • Save toggenation/76d3bc2a5559af2a34e0b2d0901f68c4 to your computer and use it in GitHub Desktop.
Save toggenation/76d3bc2a5559af2a34e0b2d0901f68c4 to your computer and use it in GitHub Desktop.
Creating a 'run once' systemd unit.

Unit file for bringing up vxlan tunnel and adding it to a bridge after Zero Tier Interface is available

Creating a 'run once' systemd unit

Systemd unit template which calls a script exactly once on startup and keeps unit status active after script exits.

Unit file placed in /etc/systemd/system and enabled with:

$ sudo systemctl enable runonce.service
$ sudo systemctl start runonce.service

Reference

[Unit]
Description=Toggen VXLAN
# After=zerotier-one.service
# Wants=network-online.target
BindsTo=sys-devices-virtual-net-ztabcdefgh.device
After=sys-devices-virtual-net-ztabcdefgh.device
[Service]
# ExecPreStart=/bin/sleep 30
ExecStart=/usr/local/sbin/zt_install.sh
RemainAfterExit=true
Type=oneshot
[Install]
WantedBy=multi-user.target
@toggenation
Copy link
Author

toggenation commented Sep 28, 2023

ZT Interface was NOT fully up when the zerotier-one.service was live so had to change to look for the interface being up.

use this command to find the zero tier interface unit

 systemctl list-units | grep zt

Output

 sys-devices-virtual-net-ztabcdefgh.device                                                 loaded active plugged   /sys/devices/virtual/net/ztabcdefgh
 sys-subsystem-net-devices-ztabcdefgh.device                                               loaded active plugged   /sys/subsystem/net/devices/ztabcdefgh

Add BindsTo and After

[Unit]
Description=Toggen VXLAN
# After=zerotier-one.service
# Wants=network-online.target
BindsTo=sys-devices-virtual-net-ztabcdefgh.device
After=sys-devices-virtual-net-ztabcdefgh.device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment