最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】supervisor的配置文件中用变量表示项目根目录

supervisor crifan 3969浏览 0评论

折腾:

【已解决】把产品demo中语音合成接口换成微软必应语音

期间,对于此处用到的supervisor的配置文件:

supervisord_server.conf

<code>。。。
[program:robotDemo_CeleryBeat]
command=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery beat -A app.celeryApp -s /root/xxx/runtime/celerybeat-schedule
directory=/root/xxx/robotDemo
autostart=true
autorestart=true

stdout_logfile=/root/xxxrobotDemo/logs/celery-beat-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=/root/xxx/logs/celery-beat-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10
。。。
</code>

可以看到,其中有多处用到了,同一个路径:

/root/xxx/robotDemo/

就是当前项目所在的根目录

希望找找,是否可以设置单独的变量可以代表这个路径,或者是有PROJECT_ROOT之类的系统内置变量

去看看

supervisor中conf中,能否指定变量,用于保存当前项目根目录

supervisor config file variable

http://supervisord.org/_sources/configuration.txt

“<pre style=”caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; white-space: pre-wrap;”>Environment Variables

~~~~~~~~~~~~~~~~~~~~~

Environment variables that are present in the environment at the time that

:program:`supervisord` is started can be used in the configuration file

using the Python string expression syntax “%(ENV_X)s“:

.. code-block:: ini

    [program:example]

    command=/usr/bin/example –loglevel=%(ENV_LOGLEVEL)s

In the example above, the expression “%(ENV_LOGLEVEL)s“ would be expanded

to the value of the environment variable “LOGLEVEL“.

.. note::

    In Supervisor 3.2 and later, “%(ENV_X)s“ expressions are supported in

    all options.  In prior versions, some options support them, but most

    do not.  See the documentation for each option below.</pre>”

是可以用 环境变量的

但是此处不想用环境变量

supervisord – Supervisor and Environment Variables – Stack Overflow

supervisor/sample.conf at master · Supervisor/supervisor

Subprocesses — Supervisor 3.3.4 documentation

不过刚刚发现,此处的PWD环境变量,是可以保证是当前文件夹,也就是此处项目根目录的:

远程centos服务器中:

<code>[root@xx-general-01 robotDemo]# ll
total 88
drwxr-xr-x 5 root root  4096 May 10 14:57 ai
-rw-r--r-- 1 root root 31089 May 14 16:16 app.py
-rw-r--r-- 1 root root  1628 May 14 16:52 config.py
-rw-r--r-- 1 root root   345 May 24 10:00 dump.rdb
-rw-r--r-- 1 root root  2005 Apr 24 16:36 gunicorn_config.py
drwxr-xr-x 2 root root  4096 May 18 11:27 logs
-rw-r--r-- 1 root root   303 May 11 17:22 Pipfile
-rw-r--r-- 1 root root 12454 May 11 17:24 Pipfile.lock
drwxr-xr-x 2 root root  4096 May 14 16:53 __pycache__
-rw-r--r-- 1 root root  2102 May  2 16:10 README.md
-rw-r--r-- 1 root root  1579 May 14 16:25 supervisord_server.conf
drwxr-xr-x 3 root root  4096 May 14 16:17 tmp
[root@xx-general-01 robotDemo]# pwd
/root/xxx/robotDemo
[root@xx-general-01 robotDemo]# echo $PWD
/root/xx/robotDemo
</code>

本地mac中:

<code>➜  xxxDemoServer git:(master) ✗ pwd
/Users/crifan/dev/xxxo/server/xxxDemoServer
➜  xxxDemoServer git:(master) ✗ echo $PWD
/Users/crifan/dev/xxx/server/xxxDemoServer
➜  xxxDemoServer git:(master) ✗ ll
total 32952
-rw-r--r--  1 crifan  staff   303B  5 11 17:22 Pipfile
-rw-r--r--  1 crifan  staff    12K  5 11 17:24 Pipfile.lock
-rw-r--r--  1 crifan  staff   4.0K  5 23 17:52 README.md
drwxr-xr-x  7 crifan  staff   224B  5 10 15:15 ai
-rw-r--r--  1 crifan  staff    39K  5 23 17:48 app.py
-rw-r--r--  1 crifan  staff    16M  5 23 18:04 celerybeat-schedule
-rw-r--r--  1 crifan  staff   2.0K  5 23 17:52 config.py
drwxr-xr-x  3 crifan  staff    96B  5 14 15:40 debug
-rw-r--r--  1 crifan  staff   138B  5 24 06:17 dump.rdb
-rw-r--r--  1 crifan  staff   2.0K  4 24 16:36 gunicorn_config.py
drwxr-xr-x  3 crifan  staff    96B  5 23 17:21 logs
drwxr-xr-x  2 crifan  staff    64B  5 24 09:40 runtime
-rw-r--r--  1 crifan  staff    10K  4 24 17:00 supervisord_local.conf
-rw-r--r--  1 crifan  staff   2.1K  5 24 09:43 supervisord_server.conf
drwxr-xr-x  3 crifan  staff    96B  5 18 16:36 tmp
</code>

所以,此处此处supervisor是切换到了此处设置的:

<code>directory=/root/xxx/robotDemo
</code>

后,那么之后此处的

<code>"%(PWD)s"
</code>

应该就是可以实现这个路径的效果的

How do I use environment variables in Supervisord’s [supervisord] config section? – Stack Overflow

突然想到:

此处用PWD,未必可行:

因为此处的supervisord_server.conf是放在服务器的supervisor的路径:

/etc/supervisord.d/supervisord_server.conf

中,而不是当前项目目录中的

-》所以此处的PWD环境变量,不一定就是:

<code>/root/xxx/robotDemo
</code>

也可能是:

<code>/etc/supervisord.d
</code>

当然更像是:

supervisor切换到:

<code>directory=/root/xxx/robotDemo
</code>

的路径:

/root/xxx/robotDemo

下,此处再去执行command,此时PWD就是:

/root/xxx/robotDemo

了。

具体情况,需要到时候验证一下才行。

flower – Supervisord using environment variables in command – Stack Overflow

<code>environment=USER=%(ENV_FLOWER_USER_NAME)s,PASS=%(ENV_FLOWER_PASSWORD)s
command=/usr/local/opt/python/bin/flower --basic_auth=%(ENV_USER)s:%(ENV_PASS)s
</code>

好像是自己可以手动设置环境变量的?

那么自己此处就是可以设置类似的:

<code>environment=ROBOTDEMO_PRJOECT_ROOT=/root/xxx/robotDemo
</code>

后续就继续用:

<code>"%(ROBOTDEMO_PRJOECT_ROOT)s"
</code>

去表示此项目根目录了。

抽空试试效果

Supervisord – using A variable INSIDE the supervisord.conf – Stack Overflow

好像的确可以自定义environment变量的

<code>Via Inheritance from supervisord:

As long as you are using version 3.0a10 or above, you can set environment variables in [supervisord] environment and they will be in the environment of all processes under supervisord's management.
[supervisord]
...
environment=FAVORITE_VENTURE="RUSTY",FAVORITE_COLOR="RED"
</code>

不过要注意的是需要在:

[supervisord]

中定义environment

然后后续其他app中就可以用了。

此处去:

<code>cat /etc/supervisord.conf
...
[supervisord]
logfile=/var/log/supervisor/supervisord.log  ; (main log file;default $CWD/supervisord.log)
...
;environment=KEY=value       ; (key value pairs to add to environment)
...
</code>

中就有:

environment=KEY=value       ; (key value pairs to add to environment)

Why can’t I seem to set an environment variable using another environment variable’s value? · Issue #447 · Supervisor/supervisor

python – How to use environment variables in supervisord commands – Stack Overflow

Configuration File — Supervisor 3.3.4 documentation

“Environment Variables

Environment variables that are present in the environment at the time that supervisord is started can be used in the configuration file using the Python string expression syntax %(ENV_X)s:

[program:example]

command=/usr/bin/example –loglevel=%(ENV_LOGLEVEL)s

In the example above, the expression %(ENV_LOGLEVEL)s would be expanded to the value of the environment variable LOGLEVEL.

Note

In Supervisor 3.2 and later, %(ENV_X)s expressions are supported in all options. In prior versions, some options support them, but most do not. See the documentation for each option below.”

Configuration File — Supervisor 3.3.4 documentation

“String expressions are evaluated against a dictionary containing the keys group_name, host_node_name, process_num, program_name, here (the directory of the supervisord config file), and all supervisord’s environment variables prefixed with ENV_.”

好像是:

supervisor(中定义)的环境变量,都要以ENV_开头才行

那么我此处应该就就是:

<code>[supervisord]
environment=ENV_ROBOTDEMO_PRJOECT_ROOT=/root/xxx/robotDemo
</code>

了。

另外,如果需要,可以用到supervisor中自带变量:

  • group_name

  • host_node_name

  • process_num

  • program_name:

    • 此处的我的APP的名字是:[program:robotDemo] 中的robotDemo

  • here:supervisord的配置文件所在路径

    • 比如我此处的conf是:/etc/supervisord.d/supervisord_server.conf

    • 对应的路径是:/etc/supervisord.d/

好像根据:

https://stackoverflow.com/questions/34038511/supervisord-using-a-variable-inside-the-supervisord-conf

又不是这个意思,而是:

  • 对于自己在supervisor中自定义的变量,无需加ENV_前缀

    • 且多个变量的话,用逗号隔开

    • 要放在[supervisord]中定义,余下各个app(即:[program:xxx )中都可以引用

    • 具体写法是:

    • environment=MY_VAR_1=XXX,MY_VAR_2=YYY

  • 而在supervisor中引用环境变量的话,才需要写成:%(ENV_XXX)s,其中XXX是你要使用的环境变量

现在可以去试试了supervisord中用environment自定义自己的环境变量了,顺带加上此项目的虚拟环境的根目录:

<code>[supervisord]
environment=ROBOTDEMO_PRJOECT_ROOT=/root/xxx/robotDemo,ROBOTDEMO_VIRTUALENV_ROOT=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG
</code>

编辑好了:

<code>[root@xx-general-01 etc]# pwd
/etc
[root@xx-general-01 etc]# cat supervisord.conf 
; Sample supervisor config file.
...
[supervisord]
logfile=/var/log/supervisor/supervisord.log  ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10          ; (num of main logfile rotation backups;default 10)
loglevel=info               ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false              ; (start in foreground if true;default false)
minfds=1024                 ; (min. avail startup file descriptors;default 1024)
minprocs=200                ; (min. avail process descriptors;default 200)
;umask=022                  ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value       ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)
environment=ROBOTDEMO_PRJOECT_ROOT=/root/xxx/robotDemo,ROBOTDEMO_VIRTUALENV_ROOT=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG
...
</code>

然后自己的配置文件,就可以去更新,写成:

<code>;ROBOTDEMO_PRJOECT_ROOT=/root/xxx/robotDemo
;ROBOTDEMO_VIRTUALENV_ROOT=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG

[program:redis]
directory=%(ROBOTDEMO_PRJOECT_ROOT)s
command=/usr/bin/redis-server

autostart=true
autorestart=true

stdout_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/redis-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/redis-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10

[program:robotDemo_CeleryWorker]
command=%(ROBOTDEMO_VIRTUALENV_ROOT)s/bin/celery worker -A app.celeryApp
directory=%(ROBOTDEMO_PRJOECT_ROOT)s
autostart=true
autorestart=true

stdout_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/celery-worker-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/celery-worker-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10


[program:robotDemo_CeleryBeat]
command=%(ROBOTDEMO_VIRTUALENV_ROOT)s/bin/celery beat -A app.celeryApp -s %(ROBOTDEMO_PRJOECT_ROOT)s/runtime/celerybeat-schedule
directory=%(ROBOTDEMO_PRJOECT_ROOT)s
autostart=true
autorestart=true

stdout_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/celery-beat-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/celery-beat-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10

[program:robotDemo]
command=%(ROBOTDEMO_VIRTUALENV_ROOT)s/bin/gunicorn -c gunicorn_config.py app:app
directory=%(ROBOTDEMO_PRJOECT_ROOT)s
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true
killasgroup=true
stopasgroup=true

stdout_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/supervisord-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/supervisord-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10

</code>

了。

然后去,停掉supervisor

reload

再start

看看是否正常

结果此处start出错了:

【已解决】supervisor的supervisorctl start出错:unix:///var/run/supervisor/supervisor.sock no such file

接着参考自己之前的:

【已解决】CentOS中用supervisor去管理gunicorn的Flask的app

【已解决】supervisor去启动gunicorn的Flask出错:supervisor couldn’t setuid to 0 Can’t drop privilege as nonroot user

感觉是:

首先,虽然之前正常运行的supervisor,但是此处不知道是不是由于配置文件有问题,还是其他什么原因,导致无法supervisor的deamon停止掉了

然后或许对应的socket文件也丢失了?(虽然不是在tmp文件夹,但是不知何故也丢失了)

然后此处supervisor没有运行的情况下,导致无法继续运行supervisorctl的各种命令

所以此处:

或许是,去启动supervisord,然后再运行supervisorctl或许就可以了?

而启动supervisord,按道理,至少有两种方式:

自己手动

<code>supervisord -c supervisord.conf
</code>

用系统管理去启动:

<code>systemctl start supervisord
</code>

此处去试试后者,这样可以充分利用系统,去加载此处服务器中supervisor的配置文件

<code>[root@xxx-general-01 robotDemo]# systemctl start supervisord
Job for supervisord.service failed because the control process exited with error code. See "systemctl status supervisord.service" and "journalctl -xe" for details.
[root@xxx-general-01 robotDemo]# systemctl status supervisord
● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2018-05-24 13:47:10 CST; 16s ago
  Process: 20112 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=2)
 Main PID: 678 (code=exited, status=2)

May 24 13:47:10 xxx-general-01 systemd[1]: Starting Process Monitoring and Control Daemon...
May 24 13:47:10 xxx-general-01 supervisord[20112]: Error: Format string '%(ROBOTDEMO_PRJOECT_ROOT)s' for 'directory' contains names which cannot be expanded
May 24 13:47:10 xx-general-01 supervisord[20112]: For help, use /usr/bin/supervisord -h
May 24 13:47:10 xx-general-01 systemd[1]: supervisord.service: control process exited, code=exited status=2
May 24 13:47:10 xx-general-01 systemd[1]: Failed to start Process Monitoring and Control Daemon.
May 24 13:47:10 xx-general-01 systemd[1]: Unit supervisord.service entered failed state.
May 24 13:47:10 xx-general-01 systemd[1]: supervisord.service failed.
</code>

通过:

Error: Format string ‘%(ROBOTDEMO_PRJOECT_ROOT)s’ for ‘directory’ contains names which cannot be expanded

就明显看出错误是自己之前的配置文件中的调用变量,无法被正常识别

难道是:

/etc/supervisord.conf

中的:

<code>[supervisord]
environment=ROBOTDEMO_PRJOECT_ROOT=/root/xxx/robotDemo,ROBOTDEMO_VIRTUALENV_ROOT=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG
</code>

的配置无法传递到:

/etc/supervisord.d/supervisord_server.conf

中?

搜:

supervisor Error: Format string  for contains names which cannot be expanded

Supervisor won’t start using %(ENV_env_var_here)s in environment · Issue #599 · Supervisor/supervisor

Error: Format string which cannot be expanded · Issue #958 · Supervisor/supervisor

“You’re trying to use the expansion %(ENV_TWITTERACCESSTOKEN)s in the config file. This means that a TWITTERACCESSTOKEN variable must exist in supervisord’s environment.

TWITTERACCESSTOKEN is not set in supervisord’s environment, so it can’t be expanded.”

难道此处必须加上ENV_前缀?

去试试

<code>[program:redis]
;directory=%(ROBOTDEMO_PRJOECT_ROOT)s
directory=%(ENV_ROBOTDEMO_PRJOECT_ROOT)s
command=/usr/bin/redis-server

autostart=true
autorestart=true

;stdout_logfile=%(ROBOTDEMO_PRJOECT_ROOT)s/logs/redis-%(program_name)s-stdout.log
stdout_logfile=%(ENV_ROBOTDEMO_PRJOECT_ROOT)s/logs/redis-%(program_name)s-stdout.log
</code>

结果:

错误依旧:

<code>May 24 13:57:02 xx-general-01 supervisord[20628]: Error: Format string '%(ENV_ROBOTDEMO_PRJOECT_ROOT)s' for 'directory' contains names which cannot be expanded
</code>

Expanding env variables using service supervisor start doesnt work · Issue #926 · Supervisor/supervisor

Error with supervisor configuration file · Issue #107 · cozy/cozy-controller

supervisord – Access environment variables passed in docker run from supervisor child process – Stack Overflow

“The syntax is correct, but environment expansion is only available in version > 3.2 of supervisor, as per this github issue.”

Supervisor won’t start using %(ENV_env_var_here)s in environment · Issue #599 · Supervisor/supervisor

去试了试:

<code>[root@xx-general-01 robotDemo]# supervisord --version
3.1.4
</code>

此处远程CentOS服务器中supervisord竟然是旧版本3.1.4,而不是3.2.0之后到版本!

注:Mac本地:

<code>➜  xxxobotDemoServer git:(master) ✗ supervisord --version
3.3.4
</code>

是稍微新的版本

去看看supervisor官网最新版本是多少

Supervisor: A Process Control System — Supervisor 3.3.4 documentation

Release History

服务器中的3.1.4是2017-07-24的版本

现在最新的是3.3.4了。

所以去:

【已解决】升级CentOS中的supervisor到最新版本

但是后来出现了:

【已解决】supervisor启动出错:Job for supervisord.service failed because the control process exited with error code

最后的最后,虽然升级了版本,支持了 environment,

但对于此处需求来说,还是无法解决:

【已解决】supervisor启动出错:Job for supervisord.service failed because the control process exited with error code

和:

【未解决】supervisor的conf配置中无法使用自定义变量或环境变量

不过,到时可以去掉变量的事情,让supervisor正常运行的:

结果配置:

<code>;ROBOTDEMO_PRJOECT_ROOT=/xxx/server/robotDemo
;ROBOTDEMO_VIRTUALENV_ROOT=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG

[program:redis]
directory=/xxx/robotDemo
command=/usr/bin/redis-server

autostart=true
autorestart=true

stdout_logfile=/xxx/logs/redis-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=/xxx/logs/redis-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10


[program:robotDemo_CeleryWorker]
command=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery worker -A app.celeryApp
directory=/xxx/robotDemo
autostart=true
autorestart=true

stdout_logfile=/xxx/logs/celery-worker-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=/xxx/logs/celery-worker-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10


[program:robotDemo_CeleryBeat]
command=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery beat -A app.celeryApp -s /xxx/runtime/celerybeat-schedule
directory=/xxx/robotDemo
autostart=true
autorestart=true

stdout_logfile=/xxx/logs/celery-beat-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=/xxx/logs/celery-beat-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10


[program:robotDemo]
command=/root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
directory=/xxx/robotDemo
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true
killasgroup=true
stopasgroup=true

stdout_logfile=/xxx/logs/supervisord-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=/xxx/logs/supervisord-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10
</code>

竟然出现其他错误了:

<code>[root@xx-general-01 robotDemo]# systemctl start supervisord
Job for supervisord.service failed because the control process exited with error code. See "systemctl status supervisord.service" and "journalctl -xe" for details.
[root@xx-general-01 robotDemo]# systemctl status supervisord.service
● supervisord.service - supervisord - Supervisor process control system for UNIX
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Thu 2018-05-24 17:26:37 CST; 8s ago
     Docs: http://supervisord.org
  Process: 24882 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=2)
 Main PID: 678 (code=exited, status=2)

May 24 17:26:37 xx-general-01 systemd[1]: Failed to start supervisord - Supervisor process control system for UNIX.
May 24 17:26:37 xx-general-01 systemd[1]: Unit supervisord.service entered failed state.
May 24 17:26:37 xx-general-01 systemd[1]: supervisord.service failed.
[root@xx-general-01 robotDemo]# journalctl -xe
-- The result is failed.
May 24 17:25:12 xx-general-01 systemd[1]: Unit supervisord.service entered failed state.
May 24 17:25:12 xx-general-01 systemd[1]: supervisord.service failed.
May 24 17:25:54 xx-general-01 systemd[1]: supervisord.service holdoff time over, scheduling restart.
May 24 17:25:54 xx-general-01 systemd[1]: Starting supervisord - Supervisor process control system for UNIX...
-- Subject: Unit supervisord.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit supervisord.service has begun starting up.
May 24 17:25:55 xx-general-01 supervisord[24878]: Error: Cannot open an HTTP server: socket.error reported errno.ENOENT (2)
May 24 17:25:55 xx-general-01 supervisord[24878]: For help, use /usr/bin/supervisord -h
May 24 17:25:55 xx-general-01 systemd[1]: supervisord.service: control process exited, code=exited status=2
May 24 17:25:55 xx-general-01 systemd[1]: Failed to start supervisord - Supervisor process control system for UNIX.
-- Subject: Unit supervisord.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit supervisord.service has failed.
-- 
-- The result is failed.
May 24 17:25:55 xx-general-01 systemd[1]: Unit supervisord.service entered failed state.
May 24 17:25:55 xx-general-01 systemd[1]: supervisord.service failed.
May 24 17:26:37 xx-general-01 systemd[1]: supervisord.service holdoff time over, scheduling restart.
May 24 17:26:37 xx-general-01 systemd[1]: Starting supervisord - Supervisor process control system for UNIX...
-- Subject: Unit supervisord.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit supervisord.service has begun starting up.
May 24 17:26:37 xx-general-01 supervisord[24882]: Error: Cannot open an HTTP server: socket.error reported errno.ENOENT (2)
May 24 17:26:37 xx-general-01 supervisord[24882]: For help, use /usr/bin/supervisord -h
May 24 17:26:37 xx-general-01 systemd[1]: supervisord.service: control process exited, code=exited status=2
May 24 17:26:37 xx-general-01 systemd[1]: Failed to start supervisord - Supervisor process control system for UNIX.
-- Subject: Unit supervisord.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit supervisord.service has failed.
-- 
-- The result is failed.
May 24 17:26:37 xx-general-01 systemd[1]: Unit supervisord.service entered failed state.
May 24 17:26:37 xx-general-01 systemd[1]: supervisord.service failed.
[root@xx-xx-01 robotDemo]#
</code>

Error: Cannot open an HTTP server: socket.error reported errno.ENOENT (2)

Strange socket related error with supervisord – Peterbe.com

去看自己的配置:

<code>[root@xx-general-01 robotDemo]# cat /etc/supervisord.conf 
; Sample supervisor config file.

[unix_http_server]
file=/var/run/supervisor/supervisor.sock   ; (the path to the socket file)
;chmod=0700                 ; sockef file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

[supervisord]
logfile=/var/log/supervisor/supervisord.log  ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10          ; (num of main logfile rotation backups;default 10)
loglevel=info               ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false              ; (start in foreground if true;default false)
minfds=1024                 ; (min. avail startup file descriptors;default 1024)
minprocs=200                ; (min. avail process descriptors;default 200)
;umask=022                  ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value       ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as http_username if set
;password=123                ; should be same as http_password if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.

;[program:theprogramname]
;command=/bin/cat              ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; start at supervisord start (default: true)
;autorestart=true              ; retstart at unexpected quit (default: true)
;startsecs=10                  ; number of secs prog must stay running (def. 1)
;startretries=3                ; max # of serial start failures (default 3)
;exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A=1,B=2           ; process environment additions (def no adds)
;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample eventlistener section shows all possible
; eventlistener subsection values, create one or more 'real'
; eventlistener: sections to be able to handle event notifications
; sent by supervisor.

;[eventlistener:theeventlistenername]
;command=/bin/eventlistener    ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;events=EVENT                  ; event notif. types to subscribe to (req'd)
;buffer_size=10                ; event buffer queue size (default 10)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=-1                   ; the relative start priority (default -1)
;autostart=true                ; start at supervisord start (default: true)
;autorestart=unexpected        ; restart at unexpected quit (default: unexpected)
;startsecs=10                  ; number of secs prog must stay running (def. 1)
;startretries=3                ; max # of serial start failures (default 3)
;exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups        ; # of stderr logfile backups (default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A=1,B=2           ; process environment additions
;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample group section shows all possible group values,
; create one or more 'real' group: sections to create "heterogeneous"
; process groups.

;[group:thegroupname]
;programs=progname1,progname2  ; each refers to 'x' in [program:x] definitions
;priority=999                  ; the relative start priority (default 999)

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
;files = supervisord.d/*.ini
files = /etc/supervisord.d/*.conf
</code>

其中:

[unix_http_server]

file=/var/run/supervisor/supervisor.sock   ; (the path to the socket file)

中的文件夹:

/var/run/supervisor

<code>[root@xx-general-01 robotDemo]# ll /var/run/supervisor
ls: cannot access /var/run/supervisor: No such file or directory
[root@xx-general-01 robotDemo]# mkdir /var/run/supervisor
[root@xx-general-01 robotDemo]# ll /var/run/supervisor   
total 0
</code>

然后再去运行,终于正常了:

<code>[root@xx-general-01 robotDemo]# systemctl start supervisord         
[root@xx-general-01 robotDemo]# systemctl status supervisord
● supervisord.service - supervisord - Supervisor process control system for UNIX
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-05-24 17:30:50 CST; 36s ago
     Docs: http://supervisord.org
  Process: 24927 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
 Main PID: 24930 (supervisord)
   CGroup: /system.slice/supervisord.service
           ├─24930 /usr/bin/python2 /usr/bin/supervisord -c /etc/supervisord.conf
           ├─24931 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24932 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery beat -A app.celeryApp -s /root/nat...
           ├─24933 /usr/bin/redis-server *:6379
           ├─24934 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery worker -A app.celeryApp
           ├─24945 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24947 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24948 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24951 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24954 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24956 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24960 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24963 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24966 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─24981 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery worker -A app.celeryApp
           ├─24982 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery worker -A app.celeryApp
           ├─24986 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery worker -A app.celeryApp
           └─24990 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/celery worker -A app.celeryApp

May 24 17:30:50 xx-general-01 systemd[1]: Starting supervisord - Supervisor process control system for UNIX...
May 24 17:30:50 xx-general-01 systemd[1]: Started supervisord - Supervisor process control system for UNIX.
[root@xx-general-01 robotDemo]# supervisorctl status all
redis                            RUNNING   pid 24933, uptime 0:01:12
robotDemo                        RUNNING   pid 24931, uptime 0:01:12
robotDemo_CeleryBeat             RUNNING   pid 24932, uptime 0:01:12
robotDemo_CeleryWorker           RUNNING   pid 24934, uptime 0:01:12
</code>

转载请注明:在路上 » 【未解决】supervisor的配置文件中用变量表示项目根目录

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.175 seconds, using 22.14MB memory