Skip to content

Instantly share code, notes, and snippets.

@aerobless
Created April 7, 2019 11:54
Show Gist options
  • Save aerobless/2c466e1643c26b2081f4ff0afec5f1a2 to your computer and use it in GitHub Desktop.
Save aerobless/2c466e1643c26b2081f4ff0afec5f1a2 to your computer and use it in GitHub Desktop.
Add service to raspberry pi to start automatically

1. Create unit file

sudo vim /lib/systemd/system/servicename.service

2. Insert config

 [Unit]
 Description=My Service
 After=multi-user.target

 [Service]
 Type=idle
 ExecStart=/usr/bin/python3 /home/pi/server.py

 [Install]
 WantedBy=multi-user.target

3. Set file permissions

sudo chmod 644 /lib/systemd/system/servicename.service

4. Enable service

  1. sudo systemctl daemon-reload
  2. sudo systemctl enable servicename.service
  3. sudo systemctl start servicename.service
  4. sudo systemctl status servicename.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment