This short blog post details how you can run a python script on boot using systemd.
Using Systemd to manage the python script
Systemd is a daemon that is used to control various aspects of services and initialization scripts that run on and after boot. It is used by a wide range of Linux systems and provides a simple interface to define services that it will launch on boot.
In this case I am going to use it to launch a python script when the Raspberry Pi boots, to turn on the scripts for the Raspberry Pi Cluster.
Creating the Service file
The service file should live under the folder /etc/systemd/system and should end in .service. My example file is:
The ExecStart references the script that you want to run to start the service. It is recommended to use the full paths to all executables so they can be launched by the process which might not have the location in its path variable.
In my case I also put the User field in the configuration so it will be launched as the pi user. By default it will launch as root.
Starting and enabling the service
Once your service file has been created you will need to enable and start the service.