Using systemd

Note that systemd is available only from the Jessie versions of Raspbian OS.

To use systemd to start a program at boot up you need to create a .service file.

sudo nano /lib/systemd/system/chicken.service
[Unit]
Description=Chicken Service
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python /home/pi/bin/coop

[Install]
WantedBy=multi-user.target

Press Ctrl o and save then Ctrl x to exit

sudo systemctl daemon-reload
sudo systemctl enable chicken.service
sudo reboot

Useful systemd commands

List all running services

systemctl

Start/stop or enable/disable services

Activates a service immediately:

systemctl start foo.service

Deactivates a service immediately:

systemctl stop foo.service

Restarts a service:

systemctl restart foo.service

Shows status of a service including whether it is running or not:

systemctl status foo.service

Enables a service to be started on bootup:

systemctl enable foo.service

Disables a service to not start during bootup:

systemctl disable foo.service

Check whether a service is already enabled or not:

systemctl is-enabled foo.service; echo $?

0 indicates that it is enabled. 1 indicates that it is disabled