Supervisord - using the INSIDE variable for supervisord.conf

Translated to use supervisod as a process control system.

I have a LONG and a repeating ENVIRONMENT configuration in my supervisord.conf setting a lot of environment variables for a lot of processes. I need to define it in one place and reuse it to keep the DRY configuration and supported. is this possible with a supervisor and how?

EDIT: An example of a non-dry configuration

[program:node-app1] command=node /home/ubuntu/server/node-app1/app.js directory=/home/ubuntu/server/node-app1 autostart=true autorestart=true stderr_logfile=/home/ubuntu/supervisor/node_app1/err.log stdout_logfile=/home/ubuntu/supervisor/node_app1/out.log user=ubuntu priority=998 startretries=20 ENVIRONMENT=BROKER_URL="amqp://user: password@path.to.rabbit :5672", NODE_ENV=envName, MONGO_URL="mongodb://path.to.mongo:27017", BASE_PUBLIC_API="http:path.to.api", REDIS_URL="redis://path.to.redis:6379", BACKEND_URL="https://path.to.backend", CHARTS_URL="https://path.to.charts" [program:node-app2] command=node /home/ubuntu/server/node-app2/app.js directory=/home/ubuntu/server/node-app2 autostart=true autorestart=true stderr_logfile=/home/ubuntu/supervisor/node_app2/err.log stdout_logfile=/home/ubuntu/supervisor/node_app2/out.log user=ubuntu priority=20 startretries=20 ENVIRONMENT=BROKER_URL="amqp://user: password@path.to.rabbit :5672", NODE_ENV=envName, MONGO_URL="mongodb://path.to.mongo:27017", BASE_PUBLIC_API="http:path.to.api", REDIS_URL="redis://path.to.redis:6379", BACKEND_URL="https://path.to.backend", CHARTS_URL="https://path.to.charts" 

What you can use: ENVIRONMENT , the base directory for the logs (only the end will be changed for each application), such common variables as startec. etc.

+5
source share
1 answer

Functions

Via Inheritance from supervisord:

As long as you use version 3.0a10 or higher, you can set the environment variables in the [supervisord] environment , and they will be in the environment of all processes under the supervision of a supervisor.

 [supervisord] ... environment=FAVORITE_VENTURE="RUSTY",FAVORITE_COLOR="RED" 

Working with supervisord variables inherited from the shell

Supervisord also has a %(ENV_VARNAME)s extension format for interpreting environment variables that allow variable names to be moved across processes. But the configuration section of the configuration does not add to the environment variables accessible by the %(ENV_)s mechanism, so it would be necessary to call superisord with variables that are already set by your shell.

As an example, if you use initialization scripts to start a supervisor and are on a debian-based system (e.g. Ubuntu), you can start with the following in / etc / default / supervisor:

 export SUPERVISOR_INCLUDES="main.conf test.conf" export MAIN_RETRY_COUNT=2 export TEST_RETY_COUNT=1 MONGO_BASE="MONGO_URL=mongodb://path.to.mongo" MAIN_MONGO_URL="${MONGO_BASE}:27017" TEST_MONGO_URL="${MONGO_BASE}:27018" export MAIN_ENV="${MAIN_MONGO_URL},OTHER_THING=\"Another thing with escaped quoting\"" export TEST_ENV=.. 

Then use them in configurations:

 ; supvervisord.conf [includes] files= %(here)s/subdir/other.conf %(ENV_SUPERVISOR_INCLUDES)s ; main.conf [group:main] ... [program:mainbackend] startretries=%(ENV_MAIN_RETRY_COUNT)s environment=%(ENV_MAIN_ENV)s 

If users can use sudo and directly call supervisord, this method does not work very well, since sudo both restricts the user environment and does not run traditional shell init scripts. But you can source /etc/default/supervisor in the root .bashrc and use sudo bash -c "supervisord .." or specify it before calling supervisord.

+2
source

Source: https://habr.com/ru/post/1237234/


All Articles