skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.

hpr1563 :: Starting Programs at boot on the Raspberry Pi

How I start programs at boot on my Raspberry Pi

<< First, < Previous, Latest >>

Hosted by MrX on 2014-07-30 and released under a CC-BY-SA license.
Listen in ogg, spx, or mp3 format. | Comments (1)

How I start programs at boot on my Raspberry Pi. Below is a copy of the /etc/rc.local file I use on my raspberry pi.

#!/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

################## Added by MrX 28/12/12, ############################################################
#  V1, 21/03/14, titied up script, added explination, run didiwiki and got detached screen working at boot

# items are run in a subshell enclosing command in ( and )
# the commands are terminted with a & to run as background task
# by default programs are run as root if this is not required "su" is used to switch user to pi
# becuse each program is run as a subsheel they all run in parallel this is why the sleep
# command is needed, each sleep command must be longer than the sum of the sleeps before
# which ensures the commands are run in sequence and not together
# exit 0 was from the original file to ensure the file exited with status 0
# if the script doesn't exit with status 0 then the pi will not fully boot


# At boot fources audio aoutput to headphones socket (Analogue output)
# from magpie magazine pdf, issue 3 page 4
(sleep 1; /usr/bin/amixer cset numid=3 1) &


# At boot run the command didiwiki as user pi, listening on IP 192.168.1.13 port 8000
(sleep 3; su pi -c "/usr/bin/didiwiki -l 192.168.1.13 -p 8000") &


# run a detached screen session at boot
(sleep 6; su pi -c "cd /home/pi ; /usr/bin/screen -dmS pi-debian -c /home/pi/.screenrc.multiwin") &

exit 0

Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2014-07-31T07:59:58Z by etalas

You know, you could just put a little function for your incremental sleep and subshelling/backgrounding on top of your rc.local executing the cmd passed as parameters and then use this w/o needing to remember to increase the sleep parameter.

Leave Comment

Name
E-mail (Will not appear online)
Website
Title
Comment
Powered by Comment Script