Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


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 is flagged as Clean and is released under a CC-BY-SA license.
raspberry pi, rc.local, bootstrap. 1.
The show is available on the Internet Archive at: https://archive.org/details/hpr1563

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:15:43

general.

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-31 07:59:58 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

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?