Lets say I have two programs in supervisord. Is there a way to run the first program (background process) conditionally without having to move that to a separate script file?
[supervisord]
nodaemon=true
logfile=/tmp/supervisord.log
#Need this program to run conditionally - say based off an environment variable being set
[program:prog1]
command=/bin/prog1
[program:prog2]
command=/bin/prog2 -DFOREGROUND
To start supervisord, run $BINDIR/supervisord. The resulting process will daemonize itself and detach from the terminal. It keeps an operations log at $CWD/supervisor. log by default.
The supervisor service runs automatically after installation. You can check its status: sudo systemctl status supervisor.
Refer to http://supervisord.org/subprocess.html#subprocess-environment for more info. Environment Variables PORT=8000 command=uwsgi --ini uwsgi. ini --http :<PORT> How do I use it on the command line?
Start / Stop a Service To start a non-running service or stop a running one, use supervisorctl start my-daemon and supervisorctl stop my-daemon . To restart a service, you can also use supervisorctl restart my-daemon .
Resurrecting an old thread, but @nelson's answer is incomplete. Namely, environment variables in supervisor need to be formatted as %(ENV_YOURVARIABLE)s
in order to be recognized (notice the prefix ENV_
, %
sign before brackets and s
at the end). Additionally, you have to export it before sending it to bash script:
[program:prog1]
command=bash -c "export INIT_PROG=%(ENV_INIT_PROG)s && ./conditional-startup.sh"
conditional-startup.sh:
#!/bin/bash
if [ $INIT_PROG = "some value" ]; then
/bin/prog1
fi
See also:
Pass conditional value to SERVER1_START and control the flow.
[program:somecommand]
command=bash -c "if [ ${SERVER1_START} = "VALUE-X" ]; then /apps/bin/start.sh
/apps/server.properties; fi"
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