Automatically starting the system

Now, obviously, we don't want to have to manually start the alarm control script each time the Raspberry Pi boots up, for example, after a power failure—for a start, we may not even be there. Therefore, we need to set up our operating system so that it will automatically start up the alarm-control.sh script at boot time.

To do this, we need to edit the rc.local file using Nano:

$ sudo nano /etc/rc.local

Before the line containing exit 0, insert the following line:

sudo /etc/pi-alarm/alarm-control.sh &

Note

The & symbol at the end of the line is important because it will then make the script run in a different process, otherwise the rc.local script would never exit.

Your rc.local file should now look something like this:

#!/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
" "$_IP"
fi

sudo /etc/pi-alarm/alarm-control.sh &
exit 0

The operating system runs the rc.local script after the system boots up, so you can put anything in there that you want to happen automatically at this time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.1.156