systemd notes

Start service on boot, but with delay

Use a timer on boot or active. This avoids annoying delay when restarting service manually from the basic ExecStartPre=/bin/sleep 15 solution.

[Unit]
Description=Start service after delay

[Timer]
OnBootSec=15sec
OnActiveSec=15sec
AccuracySec=1s
Unit=example.service

[Install]
WantedBy=timers.target

Misc tips

  • systemctl edit --full can be useful when writing custom units. Also --force if creating the unit.
  • If your service depends on samba mounts, use After=your-mount.mount (perhaps even Requires)
  • Use systemd-nspawn for containerization. machinectl edit my-container can be used to edit the unit (e.g. to setup networking or bind mounts).

TODO

  • Container VLAN setup