Skip to content

Instantly share code, notes, and snippets.

@nanusdad
Last active May 30, 2024 05:50
Show Gist options
  • Save nanusdad/1b5a06b1d058bd5a7e603ffdf3b66a96 to your computer and use it in GitHub Desktop.
Save nanusdad/1b5a06b1d058bd5a7e603ffdf3b66a96 to your computer and use it in GitHub Desktop.
Creating systemd service

Creating systemd service

Create Systemd Service File

sudo touch /etc/systemd/system/foo-daemon.service
sudo chmod 664 /etc/systemd/system/foo-daemon.service

Edit service file

vi /etc/systemd/system/foo-daemon.service

[Unit]
Description=Foo

[Service]
ExecStart=/usr/sbin/foo-daemon

[Install]
WantedBy=multi-user.target

Reload systemd

sudo systemctl daemon-reload

Manage daemon

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

Configure a service to start automatically on boot

sudo systemctl enable foo-daemon

Check the service logs

journalctl -u foo-daemon

More info

Visit the systemd.service and systemd.unit man pages.

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