使用 systemctl 运行 Supervisord 时遇到问题(systemd)

使用 systemctl 运行 Supervisord 时遇到问题(systemd)

我无法让 Supervisor 通过 systemctl 成功运行。

我正在运行 Centos 7.5

我使用以下方式安装主管sudo pip install supervisor

$ supervisor -v:3.3.4

$ which supervisord/usr/bin/supervisord

我将配置文件放入/etc/supervisor/supervisord.conf0644以及root:root文件和文件supervisor夹)配置文件包含以下内容(为简洁起见,我删除了注释掉的行):

[supervisord]
logfile=/home/myuser/logs/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               ; (logging level;default info; others: debug,warn)
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)
environment=WEBAPP_CONFIG="testing"

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)

[unix_http_server]
file = /var/tmp/supervisor.sock
chmod = 0777

[program:redisgo]
command=/usr/bin/redis-server /etc/redis.conf
autostart=true
autorestart=unexpected
stdout_logfile=/home/myuser/logs/redis.log
stderr_logfile=/home/myuser/logs/rediserr.log

[program:celery]
command = /home/myuser/mydevelopment/git/myproj/env/bin/celery worker -A webapp.celery --loglevel=info
directory = /home/myuser/mydevelopment/git/my_proj
numprocs=1
stdout_logfile=/home/myuser/logs/celeryworker.log
stderr_logfile=/home/myuser/logs/celeryworkererr.log
autostart=true
autorestart=unexpected
startsecs=10
user=myuser
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998

[program:datacollect]
command = /home/myuser/mydevelopment/git/myproj/env/bin/python /home/myuser/mydevelopment/git/myproj/data_monitoring/collection_manager.py
stdout_logfile=/home/myuser/logs/datacollect.log
stderr_logfile=/home/myuser/logs/datacollecterr.log
autostart=true
autorestart=unexpected

# BEGIN ANSIBLE MANAGED BLOCK

[program:cloud_sql_proxy]
environment=GOOGLE_APPLICATION_CREDENTIALS="/home/myuser/credentials/gcp_service_account.json"
command=/usr/local/bin/cloud_sql_proxy -instances=my-proj:us-central1:mysql-proj=tcp:3306
stdout_logfile=/home/myuser/logs/cloud_proxy.log
stderr_logfile=/home/myuser/logs/cloud_proxyerr.log
autostart=true
autorestart=true
# END ANSIBLE MANAGED BLOCK

supervisord.service我放置了一个名为的systemd 文件/usr/lib/systemd/system/supervisord.service(再次,0644root:root),其中包含以下内容:

[Unit]
Description=Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target

[Service]
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=50s

[Install]
WantedBy=multi-user.target

当我通过启动supervisord时,$ sudo systemctl start supervisord我看到以下问题supervisord.log

2018-07-19 19:26:07,655 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2018-07-19 19:26:07,655 WARN For [program:cloud_sql_proxy], redirect_stderr=true but stderr_logfile has also been set to a filename, the filename has been ignored
2018-07-19 19:26:07,663 INFO RPC interface 'supervisor' initialized
2018-07-19 19:26:07,663 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2018-07-19 19:26:07,664 INFO RPC interface 'supervisor' initialized
2018-07-19 19:26:07,664 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-07-19 19:26:07,666 INFO daemonizing the supervisord process
2018-07-19 19:26:07,667 INFO supervisord started with pid 22196
2018-07-19 19:26:07,752 INFO spawned: 'celery' with pid 22200
2018-07-19 19:26:07,753 INFO spawned: 'cloud_sql_proxy' with pid 22201
2018-07-19 19:26:07,754 INFO spawned: 'redisgo' with pid 22202
2018-07-19 19:26:07,756 INFO spawned: 'datacollect' with pid 22203
2018-07-19 19:26:07,758 INFO waiting for celery, cloud_sql_proxy, redisgo, datacollect to die
2018-07-19 19:26:08,831 INFO success: cloud_sql_proxy entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-07-19 19:26:08,831 INFO success: redisgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-07-19 19:26:11,092 INFO waiting for celery, cloud_sql_proxy, redisgo, datacollect to die
2018-07-19 19:26:14,294 INFO waiting for celery, cloud_sql_proxy, redisgo, datacollect to die
2018-07-19 19:26:18,118 INFO success: celery entered RUNNING state, process has stayed up for > than 10 seconds (startsecs)
2018-07-19 19:26:18,118 WARN killing 'datacollect' (22203) with SIGKILL
2018-07-19 19:26:18,118 INFO waiting for celery, cloud_sql_proxy, redisgo, datacollect to die
2018-07-19 19:26:18,124 INFO stopped: datacollect (terminated by SIGKILL)
2018-07-19 19:26:18,198 INFO stopped: redisgo (exit status 0)
2018-07-19 19:26:18,199 INFO stopped: cloud_sql_proxy (terminated by SIGTERM)
2018-07-19 19:26:21,149 INFO waiting for celery to die
2018-07-19 19:26:24,157 INFO waiting for celery to die
...

最后一行打印了好几次,最后celery死掉了。这很奇怪,因为我看不出是什么导致主管杀死所有进程并等待所有进程死掉

如果我superviosrd以启动$ sudo supervisord,则主管将成功启动。但是,它没有注册,systemctl因为$ systemctl status supervisord给出:

● supervisord.service - Supervisor process control system for UNIX
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2018-07-19 19:26:07 UTC; 4min 8s ago
     Docs: http://supervisord.org
 Main PID: 22193 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/supervisord.service

即使它正在运行,因为supervisorctl它可以工作并$ ps -aux | grep super显示:

myuser   22185  0.0  0.0 107988   612 pts/0    S+   19:25   0:00 tail -f supervisord.log
root     22230  0.0  1.1 220796 11256 ?        Ss   19:28   0:00 /usr/bin/python2 /bin/supervisord
myuser   22282  0.0  0.0 112704   972 pts/3    R+   19:31   0:00 grep --color=auto super

但这不起作用,因为我需要 systemctl 来管理它,以便它在启动时启动。你看到任何问题了吗?

答案1


您应该更改supervisord.service
在部分中添加以下内容Service

[Service]
Type=forking

查看 systemd 文档:
https://www.freedesktop.org/software/systemd/man/systemd.service.html
您可以在互联网上的 arch-wiki 上找到最清晰的解释:
https://wiki.archlinux.org/index.php/Systemd#Service_types
您将看到差异并了解为什么它在启动后立即停止。默认模式是simple,它不适用于这种服务。
干杯!

相关内容