Skip to content

Instantly share code, notes, and snippets.

@connorjan
Last active July 4, 2019 08:48
Show Gist options
  • Save connorjan/01f995511cfd0fee1cfae2387024b54a to your computer and use it in GitHub Desktop.
Save connorjan/01f995511cfd0fee1cfae2387024b54a to your computer and use it in GitHub Desktop.
How to setup daemontools to monitor processes on Raspberry Pi

Monitoring Processes on Raspberry Pi

  1. Install daemontools

$ sudo apt-get install daemontools daemontools-run

  1. Create the service directory if not created by daemontools

$ sudo mkdir -p /etc/service

  1. Create the directory for the service you want to be monitored

$ sudo mkdir /etc/service/testservice

  1. Create the run script that will be used by daemontools to start the service automatically. This can be created by using the following command (or similar), however the filename must be run:

$ sudo vi /etc/service/testservice/run

#!/bin/bash

 exec <command to run>

Then give the run script execute access:

$ sudo chmod u+x /etc/service/testservice/run

 The daemontools will start the run script which will then become the command specified.

 You can use $ sudo svstat /etc/service/testservice to check the status of the service. Additionally you can use the svc command to start, stop, restart, and provide other control to services. Just use $ man svc to see what it is capable of.

If you want to run the service as a user other than root (e.g. the pi user), look at the following example:

#!/bin/bash

exec sudo -u pi bash -e /home/pi/test.sh

 This run script will cause daemontools to monitor the /home/pi/test.sh script running as the pi user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment