大网数据广告活动
服务器运维问答

Managing daemons with supervisor: no foreground mode available

· 52CE 我爱测

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 wil…

问题原文

原帖链接 · kolypto · CC BY-SA 3.0

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?

已采纳解答

原帖链接 · kolypto · CC BY-SA 3.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-06-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。