RaspberryPi: Running a Python script on boot

Published on Author adventurerLeave a comment

To run a script called myproject/myscript.py on boot, first create the script and ensure it has execute permissions. Then create a config file for systemctl as follows:

% sudo vi /lib/systemd/system/myscript.service

containing the following

Description=My Script

ExecStart=/usr/bin/python /home/pi/myproject/myscript.py


Set the correct permissions on the config file

% sudo chmod 644 /lib/systemd/system/myscript.service

Then reload the daemon, enable the service to start on boot, and start the service now:

sudo systemctl daemon-reload
sudo systemctl enable myscript.service
sudo systemctl status myscript.service

All done!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *