RaspberryPi start program on boot

security device - connect wire jumpers to GPIO raspberry pi pins

RaspberryPi start program on boot

Using raspberry-pi as an autonomous device will require automatic execution of your programs at boot time.  In this post we will explain a way to setup the raspberry-pi device to run programs automatically on boot.

RaspberryPi start program on boot

Auto start programs using /etc/rc.local

Edit the /etc/rc.local file

sudo nano /etc/rc.local

Important:

  • If your command runs continuously (for example running the door security project), be sure to end the command with an “&”  (that will allow execution as a new process  – fork)
  • Reference the absolute filename instead of relative path to your home folder; for example  /home/pi/doorsensor-1.0.0-SNAPSHOT/door.sh  rather than door.sh .

Example of rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
 printf "My IP address is %s\n" "$_IP"
fi

sudo /home/pi/doorsensor-1.0.0-SNAPSHOT/door.sh &

exit 0

Reference documentation: https://www.raspberrypi.org/documentation/linux/usage/rc-local.md

Leave a Reply

Your email address will not be published. Required fields are marked *