Skip to content

Instantly share code, notes, and snippets.

@connorjan
Last active January 8, 2018 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connorjan/56b41e2dc69d80b321db1388fe438ac7 to your computer and use it in GitHub Desktop.
Save connorjan/56b41e2dc69d80b321db1388fe438ac7 to your computer and use it in GitHub Desktop.
Making a systemd service
[Unit]
Description=My service
After=network.target
[Service]
ExecStart=/usr/bin/python3 -u example.py
WorkingDirectory=/home/user/example/
Restart=always
User=username
[Install]
WantedBy=multi-user.target

Making a systemd service

  1. Take the example file and copy it into /lib/systemd/system/ as root:

sudo cp example.service /lib/systemd/system

  1. Modify it so it fits your needs. A good resource for this is: https://fedoramagazine.org/what-is-an-init-system/ and https://fedoraproject.org/wiki/Systemd

  2. Enable the service so it will start on boot and restart on crash:

sudo systemctl enable example.service

  1. Start the service:

sudo systemctl start example.service

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