我有[program:A],[program:B]在我的 supervisord.conf
B依赖A,意味着:
A应该在之前开始B。
主管如何确保这一点?
我有[program:A],[program:B]在我的 supervisord.conf
B依赖A,意味着:
A应该在之前开始B。
主管如何确保这一点?
supervisord不直接支持依赖。您的选择是:
使用优先级。设置priority为A较低的值,它将在之前启动B,在之后关闭B。priority的默认值为999。
如果您将这两个程序也放在一个组中,那么您可以同时启动和停止它们,并通过优先级来调节它们的启动和停止顺序。
编写一个事件监听器来监听PROCESS_STATE STARTING-to-RUNNING转换和STOPPING事件,然后根据这些事件A指示supervisord开始和停止。B有A自动启动,但禁用自动启动B,以便事件处理程序控制它。
如果您想走捷径,跳过阅读有关事件侦听器的文档并跳过修改程序以便它们理解事件,那么:
除了直接启动程序B(取决于A),您可以启动一个 Bash 脚本,该脚本A在启动之前一直处于休眠状态,然后再启动B. 例如,如果您有一个 PostgreSQL 数据库和一个不应在 PostgreSQL 之前启动的服务器:
[program:server]
autorestart=true
command=/.../start-server.sh
[program:postgres]
user=postgres
autorestart=true
command=/usr/lib/postgresql/9.3/bin/postgres ...
然后在里面start-server.sh:
#!/bin/bash
# Wait until PostgreSQL started and listens on port 5432.
while [ -z "`netstat -tln | grep 5432`" ]; do
echo 'Waiting for PostgreSQL to start ...'
sleep 1
done
echo 'PostgreSQL started.'
# Start server.
echo 'Starting server...'
/.../really-start-the-server
一种解决方案是使用 supervisorctl:将程序 B 的 autostart 设置为 false,并在 A 启动的程序中写入supervisorctl start B.
例子:
supervisor.cfg:
[supervisord]
nodaemon=false
pidfile=/tmp/supervisor.pid
logfile=/logs/supervisor.log
[unix_http_server]
file=/var/run/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[program:A]
command=do_a
[program:B]
command=do_b
autostart=false
该do_a程序包含:
#!/bin/bash
#do things
supervisorctl start B
TBH 这是@drrzmr 建议的解决方案,但我当时不明白。
这对我来说是一个很好的解决方案!
我使用的一种解决方法是设置进程,然后使用and (一次性)
autostart=false创建引导脚本。引导程序可以是调用每个进程的 shell 脚本。 将阻塞,直到进程成功启动。autostart=trueautorestart=falsesupervisorctl startsupervisorctl start