Supervisor is a process manager which provides a singular interface for managing and monitoring a number of long-running programs.
HOW TO INSTALL SUPERVISOR
You have to update your package sources apt-get installand install the app Supervisor:
$ sudo apt update
$ sudo apt install supervisor
The supervisor service runs automatically after installation. You can check its status:
$ sudo systemctl status supervisor
● supervisor.service - Supervisor process control system for UNIX
Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-06-25 14:27:40 CEST; 1min 15s ago
...
HOW TO MONITOR AN APPLICATION
We are going to use as an example, the Paho MQTT-SN Gateway and the Paho MQTT-SN Gateway Logmonitor.
Firstly, we need to create and configure our .conf file for the Paho MQTT-SN Gateway:
$ sudo nano /etc/supervisor/conf.d/paho_mqtt_sn_gatway.conf
Besides, we need to add the following features to the .conf file /etc/supervisor/conf.d/paho_mqtt_sn_gatway.conf:
[program:paho_mqtt_sn_gateway]
directory=/root/paho.mqtt-sn.embedded-c/MQTTSNGateway/bin
command=bash -c "./MQTT-SNGateway -f gateway.conf"
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stdout_logfile_maxbytes = 128MB
stdout_logfile_backups = 4
redirect_stderr = true
Secondly, we need to create and configure our .conf file for the Paho MQTT-SN Gateway Logmonitor:
$ sudo nano /etc/supervisor/conf.d/paho_mqtt_sn_gatway_logmonitor.conf
We need to add the following features to de .conf file /etc/supervisor/conf.d/paho_mqtt_sn_gatway_logmonitor.conf:
[program:paho_mqtt_sn_gateway_logmonitor]
directory=/root/paho.mqtt-sn.embedded-c/MQTTSNGateway/bin
command=bash -c "./MQTT-SNLogmonitor"
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stdout_logfile_maxbytes = 128MB
stdout_logfile_backups = 4
redirect_stderr = true
The final two lines define the locations of the two main log files for the program. As suggested by the option names, stdout and stderr will be directed to the stdout_logfile and stderr_logfile locations respectively. The specified directories must already exist, as Supervisor will not attempt to create any missing directories.
Once our configuration file is created and saved, we can inform supervisor of our new program through the supervisorctl command. First. we tell supervisor to look for any new or changed program configurations in the /etc/supervisor/conf.d directory with the following command:
$ sudo supervisorctl reread
paho_mqtt_sn_gateway: available
paho_mqtt_sn_gateway_logmonitor: available
The following command will update the changes:
$ sudo supervisorctl update
paho_mqtt_sn_gateway: added process group
paho_mqtt_sn_gateway_logmonitor: added process group
The following command will watch the current staus:
$ sudo supervisorctl status
paho_mqtt_sn_gateway RUNNING pid 31830, uptime 0:02:48
paho_mqtt_sn_gateway_logmonitor RUNNING pid 31867, uptime 0:00:10