Running a Python Script at Startup on a Linux Machine

2016-09-06
code

Background

I’m using a Raspberry Pi to collect data from a couple sensors and then send the data to an API. I have a python script that sets up a couple GPIO pins, collects the data, and makes the http requests.

Problem

I needed the python script to run when the Raspberry Pi started up.

Solution

I created

References

Post about running a script using an init.d script

Great post about running a python script at boot
http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/

Debian wiki on LSBInitScripts
https://wiki.debian.org/LSBInitScripts

Post on the difference between –exec and –startas with start-stop-daemon
https://chris-lamb.co.uk/posts/start-stop-daemon-exec-vs-startas

Checking internet connection in python
http://stackoverflow.com/questions/3764291/checking-network-connection

Running code before exit in python
http://stackoverflow.com/questions/3850261/doing-something-before-program-exit