转而使用supervisod作为过程控制系统.
我的supervisord.conf中有一个LONG和重复的环境配置,为很多进程设置了很多环境变量.我需要在一个地方定义并重用它,以保持配置DRY和可维护.这是可能与主管和如何?
编辑:非干配置的示例
[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"
Run Code Online (Sandbox Code Playgroud)
可以共享的内容:ENVIRONMENT,日志的基本目录(每个应用程序只会更改结束),常见变量如startsecs.等等
只要你使用的是3.0a10及以上版本,就可以在里面设置环境变量[supervisord] environment,它们会在supervisord管理下的所有进程的环境中。
[supervisord]
...
environment=FAVORITE_VENTURE="RUSTY",FAVORITE_COLOR="RED"
Run Code Online (Sandbox Code Playgroud)
Supervisord 还具有用于解释环境变量的%(ENV_VARNAME)s扩展格式,这将允许为不同的进程移动变量名称。但是配置的环境部分不会添加到该%(ENV_)s机制可用的环境变量中,因此有必要使用 shell 已经设置的变量调用 supervisord。
例如,如果您使用 init 脚本来启动 supervisord 并且在基于 debian 的系统(即 Ubuntu)上,那么您可以从 /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=..
Run Code Online (Sandbox Code Playgroud)
然后在配置中使用它们:
; 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
Run Code Online (Sandbox Code Playgroud)
如果用户可以 sudo 并直接调用 supervisord,则此方法效果不佳,因为 sudo 既剥离了用户环境又不运行传统的 shell init 脚本。但是您可以source /etc/default/supervisor在 root 的 .bashrc 中并sudo bash -c "supervisord .."在调用 supervisord 之前使用或获取它。
| 归档时间: |
|
| 查看次数: |
4973 次 |
| 最近记录: |