If I have it right. To answer the question anything in the directory /etc/init named xxx.conf will load when the machine boots it basically just points to your python file and says start this file when the pi boots. (Like the Start Up folder in Windows if your familiar with it.) the respawn at the end of the file says run if it ends so if it is one time script you would remove that.
Hope I got all this correct. If not someone will educate me
To break down how the file needs to be setup:
The sample provided just needs to be done the same but with your script:
Have you tried using upstart? This simple upstart script will start on boot and respawn if it crashes.
The example given goes like this if I got it correct.
To run a python file on startup you need a conf file to point to the .py file you created.
This conf file needs to be in /etc/init/ and should be named the name of the service you like .conf
So to make your own service (name it what you want gps was just an example)
Code: Select all
cd /etc/init/
nano nameofpythonfile.conf
nameofpythonfile = is any name you want to call the service so pick what ever you think your service should be called
paste the code into it or type it out:
Code: Select all
# gps data logger service
description "GPS Data Logger service"
author "User"
start on runlevel [2345]
stop on runlevel [016]
chdir /home/user/
exec python /home/user/gps_data.py
respawn
The following is what you change to reflect the program you want to run or just leave it alone if you don't have a gps going
Code: Select all
# gps data logger service
description "GPS Data Logger service"
author "User"
This part points to where the file is and what it is named change it to what you have and it must be correct or it won't be able to find your file
Code: Select all
chdir /home/user/
exec python /home/user/gps_data.py
respawn just says if it dies start it again
Test your settings by typing
replace gps with the name you chose for your .conf file.
If it errors go back to step one cd to the .conf file edit it save it then suso service whatever start til no errors and you program loads.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)