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 ...

Get Building a Home Security System with Raspberry Pi now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.