Skip to content

Instantly share code, notes, and snippets.

@Benoss
Last active April 19, 2016 23:51
Show Gist options
  • Save Benoss/492c817d8dc4c087f12673d9b7b229e8 to your computer and use it in GitHub Desktop.
Save Benoss/492c817d8dc4c087f12673d9b7b229e8 to your computer and use it in GitHub Desktop.
Simple Systemd blocking service auto start
#/etc/systemd/system/foo.service
[Unit]
#Description of the service
Description=foo
#Auto start on reboot when the target user target is availaible
After=multi-user.target
[Service]
#Switching the working directory (not needed, just an example)
WorkingDirectory=/usr/local
#Simple blocking call in python
ExecStart=/usr/bin/python -c "while 1:import time;time.sleep(1)"
[Install]
#Install as a multi user target (default)
WantedBy=multi-user.target
# need to enable the service after creating the file this will create a simlink from the service to the multi-user.target directory
# sudo systemctl enable foo.service
# Get the status of the service (should be loaded but inactive/dead)
# sudo systemctl status foo
# Start the service
# sudo systemctl start foo
# Stop the service
# sudo systemctl stop foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment