systemd - ah01/linux-setup GitHub Wiki

Commands

sudo systemctl start foo-daemon
sudo systemctl stop foo-daemon
sudo systemctl restart foo-daemon
sudo systemctl reload foo-daemon
systemctl status foo-daemon

Realod after chnage

sudo systemctl daemon-reload

Enable/disable

sudo systemctl enable foo-daemon

Journald

journalctl -u foo-daemon

Paths

  • /lib/systemd/system - where applications put their units, do not edit here (copy to etc and edit there)
  • /etc/systemd/system - where to put edited and custom units

Sample

[Unit]
Description=<description>
After=network.target

[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=<>
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Path in ExecStart= shoudl be full path (which xxx)

Ref