Skip to content
Bruce Schubert edited this page Aug 18, 2020 · 16 revisions

Run as a Service

We're going to define a service to automatically run the Call Attendant on the Raspberry Pi at start up. Our simple service will run the callattendant.py script and if by any means is aborted it is going to be restarted automatically.

Create the Service

Step 1. Create the Unit File

The service definition must be on the /lib/systemd/system folder. Our service is going to be called "callattendant.service":

cd /lib/systemd/system/
sudo nano callattendant.service

Copy the following text into the callattendant.service unit file:

[Unit]
Description=Call Attendant
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/python3 -u /home/pi/callattendant/src/callattendant.py
WorkingDirectory=/home/pi/callattendant/src
Restart=on-abort

[Install]
WantedBy=multi-user.target

You can check more on service's options in the next wiki: https://wiki.archlinux.org/index.php/systemd.

Step 2. Activate the Service

Now that we have our service we need to activate it:

sudo chmod 644 /lib/systemd/system/callattendant.service
chmod +x /home/pi/callattendant/src/callattendant.py
sudo systemctl daemon-reload
sudo systemctl enable callattendant.service
sudo systemctl start callattendant.service

Service Tasks

For every change that we do on the /lib/systemd/system folder we need to execute a daemon-reload (third line of previous code). Execute the following commands as needed to check the status, start and stop the service, or check the logs.

Check status

sudo systemctl status callattendant.service

Start service

sudo systemctl start callattendant.service

Stop service

sudo systemctl stop callattendant.service

Check/Monitor service's log

sudo journalctl -f -u callattendant.service

REFERENCES


Record Audio Files

You can record your own audio wav files for playback to your callers.

See: (https://iotbytes.wordpress.com/play-audio-file-on-phone-line-with-raspberry-pi/)