Embedded Linux Process Supervision
For making a real world product, robustness is very important, some process may crash occasionally, this is possible even if the system is passed all kinds of tests, for this case, we have to make sure it will be restarted if it is the key process for the system.
In embedded linux world there are many options to fullfil this intention, one of the easiest choice maybe runit in busybox.
Busybox provides a minimal implementation of runit that can be used for serving this purpose.
To enable it, add the following config options to default configuration or select
relevant options in make menuconfig
:
+CONFIG_RUNSV=y
+CONFIG_RUNSVDIR=y
+CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service"
+CONFIG_SVC=y
To start services on start Add line below to /etc/inittab:
:5:respawn:/bin/runsvdir /var/service
And add this in the startup script such as rcS:
+mkdir /var/service
+ln -s /etc/sv/gatewayupgrade /var/service
+ln -s /etc/sv/ntp /var/service
+ln -s /etc/sv/keyprocess /var/service
+ln -s /etc/sv/smarthome /var/service
To start a service run
file is mandatory, there are many example files in the
following directory:
busybox/examples/var_service
This is an example run
for helloworld:
#!/bin/sh
#exec >/dev/null
exec 2>&1
exec </dev/null
exec \
env - \
helloworld
For systems using systemd, refer to Runit.
There are also choices such as monit to provides more features to meet complicated situations, consider the following if possible:
- monit
- watchdogd
- minit
- supervisor was written in python, integrated in buildroot
- nagios mainly used for monitoring servers
- upstart developed by Ubuntu
- supervise supervise monitors a service. It starts the service and restarts the service if it dies. Setting up a new service is easy: all supervise needs is a directory with a run script that runs the service.