Managing daemons with supervisor: no foreground mode available
I'm trying to manage a process with supervisord, but the process does not have an option to run in foreground: it always daemonizes. (That's Zabbix Server).
Is there any way to manage daemons with supervisor? Any tools which will make it run in foreground? Or maybe, use the pidfile somehow?
Solution 1:
In order to deal with the problem, we'll need some program running in foreground, which exits whenever the daemon exits, and which also proxies signals to the daemon.
Consider using the following script bash script:
#! /usr/bin/env bash
set -eu
pidfile="/var/run/your-daemon.pid"
command=/usr/sbin/your-daemon
# Proxy signals
function kill_app(){
kill $(cat $pidfile)
exit 0 # exit okay
}
trap "kill_app" SIGINT SIGTERM
# Launch daemon
$command
sleep 2
# Loop while the pidfile and the process exist
while [ -f $pidfile ] && kill -0 $(cat $pidfile) ; do
sleep 0.5
done
exit 1000 # exit unexpected
Solution 2:
just in case someone comes around this question using search engines as I just did.
Zabbix offers since v3.0.0beta1 the "-f" option to run in foreground (https://support.zabbix.com/browse/ZBXNEXT-611)
As you can see below, we start the process using the absolute path to binary (we compiled it from sources), providing our configuration-file using the "-c" switch and absolute path to the configuration file. And then the mentioned "-f" switch to run the process in foreground.
The supervisord configuration file we use looks like:
[program:zabbix-server]
command=/opt/application/zabbix-server/3.2.7/zabbix_server -c /opt/application/zabbix-server/3.2.7/zabbix-server.conf -f
startsecs=5
startretries=3
autostart=true
autorestart=true
user=zabbix
stdout_logfile=/data/application/zabbix-server/3.2.7/log/zabbix-server.log
stderr_logfile=/data/application/zabbix-server/3.2.7/log/zabbix-server-stderr.log
Please note that we configured in the zabbix-server.conf
LogType=console
All the best