I have [program:A]
, [program:B]
in my supervisord.conf
B
depend A
, means:
A
should start before B
.
How to ensure this by supervisor?
Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems. It shares some of the same goals of programs like launchd, daemontools, and runit. Unlike some of these programs, it is not meant to be run as a substitute for init as “process id 1”.
So with that patch, supervisor looks for supervisord. conf in the local directory, in the etc/ subdirectory, then in the global /etc/supervisor/ and /etc/ directories. causing supervisord to load any extra files put in the conf. d directory.
The supervisor service runs automatically after installation. You can check its status: sudo systemctl status supervisor.
supervisord
does not directly support dependencies. Your options instead are:
Use priorities. Set priority
for A
to a low value and it'll be started before B
, and shut down after B
. The default value for priority
is 999
.
If you put the two programs into one group as well, that'd let you start and stop them in tandem, with the priorities regulating their start and stop order.
Write an event listener that listens for PROCESS_STATE
STARTING
-to-RUNNING
transition and STOPPING
events for A
, then instruct supervisord
to start and stop B
according to those events. Have A
autostart, but disable autostarting for B
, so that the event handler controls it.
If you want to take a shortcut, and skip reading the documentation about event listeners and skip modifying your programs so they understand events, then:
Instead of starting program B
(which depends on A
) directly, you could start a Bash script that sleeps until A
has been started, and then starts B
. For example, if you have a PostgreSQL database and a server that shouldn't start before PostgreSQL:
[program:server] autorestart=true command=/.../start-server.sh [program:postgres] user=postgres autorestart=true command=/usr/lib/postgresql/9.3/bin/postgres ...
And then inside 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With