Skip to content

Instantly share code, notes, and snippets.

@TheRealEdDawson
Last active June 20, 2020 19:28
Show Gist options
  • Save TheRealEdDawson/5351939 to your computer and use it in GitHub Desktop.
Save TheRealEdDawson/5351939 to your computer and use it in GitHub Desktop.
A simple shell script to run a Python program at boot time on Raspberry Pi.
#! /bin/sh
# /etc/init.d/BootPython
### BEGIN INIT INFO
# Provides: Runs a Python script on startup
# Required-Start: BootPython start
# Required-Stop: BootPython stop
# Default-Start: 2 3 4 5
# Default-stop: 0 1 6
# Short-Description: Simple script to run python program at boot
# Description: Runs a python program at boot
### END INIT INFO
case "$1" in
start)
echo "Starting BootPython"
sudo python /home/pi/Ed-Python-Code/photocell/photocell.py
;;
stop)
echo "Stopping BootPython"
sudo killall Python
;;
*)
echo "Usage: /etc/init.d/BootPython {start|stop}"
exit 1
;;
esac
exit 0
@tsturzl
Copy link

tsturzl commented Jun 6, 2016

Incredibly quick and dirty. It could just end up killing all of your python processes when you stop the service.

@TheRealEdDawson
Copy link
Author

Yes. ;-) I suppose I could track the process ids and only halt those related to the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment