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

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

CentOS crifan 4848浏览 0评论

折腾:

【已解决】把Python3的Flask部署到远程CentOS7服务器

期间,之前Mac本地已经折腾完毕了,现在已在CentOS中弄好了gunicorn。

现在接着去弄supervisor。

不过之前mac本地折腾的supervisor,不是全局安装的。

现在CentOS服务器中要全局安装,尤其是配置要全局。

因为后期可能会用supervisor去管理,不止当前这一个app。

所以supervisor的log,倒是考虑放在全局,而不是当前app下面。

然后对于supervisor的其他如sock和pid等文件,最好放的,重启服务器不会删掉的非tmp的目录,比如之前的/var/run,但是为了更加规范不乱,可以考虑放到:

/var/run/supervisor/

中。

现在继续重新研究:

CentOS中如何使用supervisor

centos supervisor gunicorn

centos下通过gunicorn+nginx+supervisor部署Flask项目

centos部署django:nginx+gunicorn+supervisor.md – 简书

“每个进程的配置文件都可以单独分拆,放在/etc/supervisor/conf.d/目录下,以.conf作为扩展名,例如,app.conf定义了一个gunicorn的进程”

Centos+Gunicorn+Nginx+Supervisor部署Flask – 简书

How To Set Up Django with Postgres, Nginx, and Gunicorn on CentOS 7 | DigitalOcean

supervisor 和gunicorn部署django项目-Linux运维日志

Flask Gunicorn Supervisor Nginx 项目部署小总结

【已解决】CentOS中用python2的pip去安装supervisor后找不到/etc/supervisor中的默认配置文件supervisord.conf

看了看默认的配置:

<code>[root@naturling-general-01 robotDemo]# 
[root@naturling-general-01 robotDemo]# pwd
/root/naturling_20180101/web/server/robotDemo
-bash: pwd: write error: Success
[root@naturling-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
[root@naturling-general-01 robotDemo]# 
</code>

好像有点奇怪:

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

为何不是*.conf?

  • 默认sock文件:file=/var/run/supervisor/supervisor.sock

  • 默认log文件:logfile=/var/log/supervisor/supervisord.log

  • 默认pid文件:pidfile=/var/run/supervisord.pid

  • 默认:serverurl=unix:///var/run/supervisor/supervisor.sock

对于此处supervisor的运行机制,加载配置的机制,感觉是:

如果别人在项目目录下创建的配置文件中只是简单的:

<code>[program:myapp]
directory= /home/flask
command= gunicorn -w4 -b0.0.0.0:5000 run:app
</code>

而没有配置sock,log,pid等文件,则:

估计是supervisor先去加载系统默认的:

/etc/supervisor.conf

然后再去加载单个app的配置的。

然后对于某个(Flask的app)项目 的supervisor配置文件的存放的位置,感觉是:

可以放到项目目录下

也可以放到(此处的)/etc/supervisord.d/中-》让supervisor自动识别

鉴于官网:

Configuration File — Supervisor 3.3.4 documentation

提到的搜索路径,没包含此处CentOS用yum安装后的supervisor的conf的路径:

/etc/supervisord.d

以及默认配置:

/etc/supervisord.conf

中最后竟然include是ini而不是conf,所以去参考:

python – supervisor.conf default location – Stack Overflow

修改现有的:

/etc/supervisord.conf

的最后部分为:

<code>(robotDemo-dwdcgdaG) [root@naturling-general-01 robotDemo]# cat /etc/supervisord.conf 
[include]
;files = supervisord.d/*.ini
files = /etc/supervisord.d/*.conf
</code>

这样就可以让supervisor自动包含:

/etc/supervisord.d/

下面所有的conf配置了。

不过此处还是为了项目逻辑性更清晰,把自己的supervisor的conf放到自己项目根目录下吧

继续参考:

supervisor 和gunicorn部署django项目-Linux运维日志

优化配置:

supervisord_robotDemo.conf

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

stdout_logfile=/root/naturling_20180101/web/server/robotDemo/logs/%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=/root/naturling_20180101/web/server/robotDemo/logs/%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10
</code>

结果运行却出错:

<code>[root@naturling-general-01 robotDemo]# supervisord -c supervisord_robotDemo.conf 
Error: .ini file does not include supervisord section
For help, use /usr/bin/supervisord -h
</code>

很明显,此处是由于没有包含:

[supervisord]

但是别人为何这么写。

然后发现别人都是放到/etc下面的

所以还是去放到/etc下面去看看吧

<code>[root@naturling-general-01 robotDemo]# mv supervisord_robotDemo.conf /etc/supervisord.d/
[root@naturling-general-01 robotDemo]# ll /etc/supervisord.d
total 4
-rw-r--r-- 1 root root 568 Apr 24 13:38 supervisord_robotDemo.conf
</code>

然后再去运行,不加参数:

<code>[root@naturling-general-01 robotDemo]# supervisord
/usr/lib/python2.7/site-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
</code>

好像还是没有运行?

貌似已经运行了:

<code>[root@naturling-general-01 robotDemo]# ps -ef | grep supervisor
root     32338     1  0 13:43 ?        00:00:00 /usr/bin/python /usr/bin/supervisord
root     32438 31807  0 13:44 pts/0    00:00:00 grep --color=auto supervisor
</code>

然后再去运行supervisorctl看看

<code>[root@naturling-general-01 robotDemo]# supervisorctl status all
robotDemo                        RUNNING   pid 32340, uptime 0:01:17
</code>

和log:

<code>[root@naturling-general-01 robotDemo]# cat /var/log/supervisor/supervisord.log 
2018-04-24 13:43:37,742 CRIT Supervisor running as root (no user in config file)
2018-04-24 13:43:37,742 WARN Included extra file "/etc/supervisord.d/supervisord_robotDemo.conf" during parsing
2018-04-24 13:43:37,765 INFO RPC interface 'supervisor' initialized
2018-04-24 13:43:37,765 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-04-24 13:43:37,767 INFO daemonizing the supervisord process
2018-04-24 13:43:37,768 INFO supervisord started with pid 32338
2018-04-24 13:43:38,771 INFO spawned: 'robotDemo' with pid 32340
2018-04-24 13:43:39,306 INFO success: robotDemo entered RUNNING state, process has stayed up for &gt; than 0 seconds (startsecs)
</code>

然后对应的此处的其他logs,也是对的:

<code>[root@naturling-general-01 robotDemo]# ll logs/
total 36
-rw-r--r-- 1 root root   320 Apr 24 13:46 gunicorn_access.log
-rw-r--r-- 1 root root   885 Apr 24 13:43 gunicorn_error.log
-rw-r--r-- 1 root root  4832 Apr 24 13:46 robotDemo-stderr.log
-rw-r--r-- 1 root root     0 Apr 24 13:43 robotDemo-stdout.log
-rw-r--r-- 1 root root 16667 Apr 24 13:46 RobotQA.log
[root@naturling-general-01 robotDemo]# cat logs/gunicorn_access.log 
[24/Apr/2018:13:46:14 +0800] &lt;32371&gt; 112.4.64.141 "GET /qa?q=play+a+apple+song HTTP/1.1" 200 0.013976 341 -" "Apache-HttpClient/4.5.2 (Java/1.8.0_152-release)"
[24/Apr/2018:13:46:26 +0800] &lt;32367&gt; 112.4.64.141 "GET /qa?q=play+a+juice+song HTTP/1.1" 200 0.008820 182 -" "Apache-HttpClient/4.5.2 (Java/1.8.0_152-release)"
[root@naturling-general-01 robotDemo]# cat logs/gunicorn_error.log 
[2018-04-24 13:43:39 +0800] [32340] [INFO] Starting gunicorn 19.7.1
[2018-04-24 13:43:39 +0800] [32340] [INFO] Listening at: http://0.0.0.0:32851 (32340)
[2018-04-24 13:43:39 +0800] [32340] [INFO] Using worker: threads
[2018-04-24 13:43:39 +0800] [32343] [INFO] Booting worker with pid: 32343
[2018-04-24 13:43:39 +0800] [32345] [INFO] Booting worker with pid: 32345
[2018-04-24 13:43:39 +0800] [32349] [INFO] Booting worker with pid: 32349
[2018-04-24 13:43:39 +0800] [32360] [INFO] Booting worker with pid: 32360
[2018-04-24 13:43:39 +0800] [32362] [INFO] Booting worker with pid: 32362
[2018-04-24 13:43:39 +0800] [32367] [INFO] Booting worker with pid: 32367
[2018-04-24 13:43:39 +0800] [32371] [INFO] Booting worker with pid: 32371
[2018-04-24 13:43:39 +0800] [32375] [INFO] Booting worker with pid: 32375
[2018-04-24 13:43:39 +0800] [32378] [INFO] Booting worker with pid: 32378
[root@naturling-general-01 robotDemo]# cat logs/RobotQA.log 
...
[2018-04-24 13:46:14,543 INFO app.py:107 get] parser=&lt;flask_restful.reqparse.RequestParser object at 0x7f2803819550&gt;
[2018-04-24 13:46:14,544 INFO app.py:110 get] parsedArgs={'q': 'play a apple song'}
[2018-04-24 13:46:14,544 INFO app.py:116 get] q=play a apple song
[2018-04-24 13:46:14,545 INFO app.py:125 get] foundSongName=&lt;_sre.SRE_Match object; span=(0, 17), match='play a apple song'&gt;
[2018-04-24 13:46:14,545 INFO app.py:131 get] songName=apple
[2018-04-24 13:46:14,545 INFO app.py:153 get] filenameRegex=re.compile('apple', re.IGNORECASE)
[2018-04-24 13:46:14,546 INFO app.py:159 get] findFileCursor=&lt;gridfs.grid_file.GridOutCursor object at 0x7f2803819588&gt;
[2018-04-24 13:46:14,549 INFO app.py:161 get] findFileCount=7
[2018-04-24 13:46:14,554 INFO app.py:169 get] [ 1] _id=5ad43f7ba4bc71fa65bb1cf8, contentType=audio/mpeg, filename=44 Apple Pie.mp3
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 2] _id=5ad43f7ba4bc71fa65bb1cf2, contentType=application/pdf, filename=44 Apple Pie.pdf
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 3] _id=5ad44071a4bc71fa65bb2a1d, contentType=audio/mpeg, filename=44 Picking Apples.mp3
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 4] _id=5ad43d08a4bc71fa65bb0191, contentType=audio/mpeg, filename=I AM AN APPLE.mp3
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 5] _id=5ad4389ca4bc71fa65bac65e, contentType=audio/mpeg, filename=Ten Apples Up On Top.mp3
[2018-04-24 13:46:14,556 INFO app.py:169 get] [ 6] _id=5ad43e56a4bc71fa65bb1081, contentType=audio/mpeg, filename=The Apple.mp3
[2018-04-24 13:46:14,556 INFO app.py:169 get] [ 7] _id=5ad43e54a4bc71fa65bb106d, contentType=application/pdf, filename=The Apple.pdf
[2018-04-24 13:46:26,965 INFO app.py:107 get] parser=&lt;flask_restful.reqparse.RequestParser object at 0x7f28038194e0&gt;
[2018-04-24 13:46:26,965 INFO app.py:110 get] parsedArgs={'q': 'play a juice song'}
[2018-04-24 13:46:26,966 INFO app.py:116 get] q=play a juice song
[2018-04-24 13:46:26,966 INFO app.py:125 get] foundSongName=&lt;_sre.SRE_Match object; span=(0, 17), match='play a juice song'&gt;
[2018-04-24 13:46:26,966 INFO app.py:131 get] songName=juice
[2018-04-24 13:46:26,967 INFO app.py:153 get] filenameRegex=re.compile('juice', re.IGNORECASE)
[2018-04-24 13:46:26,967 INFO app.py:159 get] findFileCursor=&lt;gridfs.grid_file.GridOutCursor object at 0x7f2803819518&gt;
[2018-04-24 13:46:26,971 INFO app.py:161 get] findFileCount=0
[root@naturling-general-01 robotDemo]# 
[root@naturling-general-01 robotDemo]# 
[root@naturling-general-01 robotDemo]# ll logs/
total 36
-rw-r--r-- 1 root root   320 Apr 24 13:46 gunicorn_access.log
-rw-r--r-- 1 root root   885 Apr 24 13:43 gunicorn_error.log
-rw-r--r-- 1 root root  4832 Apr 24 13:46 robotDemo-stderr.log
-rw-r--r-- 1 root root     0 Apr 24 13:43 robotDemo-stdout.log
-rw-r--r-- 1 root root 16667 Apr 24 13:46 RobotQA.log
[root@naturling-general-01 robotDemo]# cat logs/robotDemo-stdout.log 
[root@naturling-general-01 robotDemo]# cat logs/robotDemo-stderr.log 
[2018-04-24 13:43:39,305 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f28089fddd8&gt;
[2018-04-24 13:43:39,309 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,334 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f28089fbe80&gt;
[2018-04-24 13:43:39,336 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,416 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f28089fceb8&gt;
[2018-04-24 13:43:39,424 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,581 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f28089faf60&gt;
[2018-04-24 13:43:39,610 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f28089fafd0&gt;
[2018-04-24 13:43:39,614 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,615 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f2808a00080&gt;
[2018-04-24 13:43:39,619 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,633 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,713 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f2808a000f0&gt;
[2018-04-24 13:43:39,714 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,796 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f2808a02128&gt;
[2018-04-24 13:43:39,798 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:43:39,803 INFO app.py:59 &lt;module&gt;] api=&lt;flask_restful.Api object at 0x7f2808a03198&gt;
[2018-04-24 13:43:39,805 INFO app.py:81 &lt;module&gt;] purePymongo=MongoClient(host=['localhost:32018'], document_class=dict, tz_aware=False, connect=True, authsource='gridfs')
[2018-04-24 13:46:14,543 INFO app.py:107 get] parser=&lt;flask_restful.reqparse.RequestParser object at 0x7f2803819550&gt;
[2018-04-24 13:46:14,544 INFO app.py:110 get] parsedArgs={'q': 'play a apple song'}
[2018-04-24 13:46:14,544 INFO app.py:116 get] q=play a apple song
[2018-04-24 13:46:14,545 INFO app.py:125 get] foundSongName=&lt;_sre.SRE_Match object; span=(0, 17), match='play a apple song'&gt;
[2018-04-24 13:46:14,545 INFO app.py:131 get] songName=apple
[2018-04-24 13:46:14,545 INFO app.py:153 get] filenameRegex=re.compile('apple', re.IGNORECASE)
[2018-04-24 13:46:14,546 INFO app.py:159 get] findFileCursor=&lt;gridfs.grid_file.GridOutCursor object at 0x7f2803819588&gt;
[2018-04-24 13:46:14,549 INFO app.py:161 get] findFileCount=7
[2018-04-24 13:46:14,554 INFO app.py:169 get] [ 1] _id=5ad43f7ba4bc71fa65bb1cf8, contentType=audio/mpeg, filename=44 Apple Pie.mp3
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 2] _id=5ad43f7ba4bc71fa65bb1cf2, contentType=application/pdf, filename=44 Apple Pie.pdf
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 3] _id=5ad44071a4bc71fa65bb2a1d, contentType=audio/mpeg, filename=44 Picking Apples.mp3
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 4] _id=5ad43d08a4bc71fa65bb0191, contentType=audio/mpeg, filename=I AM AN APPLE.mp3
[2018-04-24 13:46:14,555 INFO app.py:169 get] [ 5] _id=5ad4389ca4bc71fa65bac65e, contentType=audio/mpeg, filename=Ten Apples Up On Top.mp3
[2018-04-24 13:46:14,556 INFO app.py:169 get] [ 6] _id=5ad43e56a4bc71fa65bb1081, contentType=audio/mpeg, filename=The Apple.mp3
[2018-04-24 13:46:14,556 INFO app.py:169 get] [ 7] _id=5ad43e54a4bc71fa65bb106d, contentType=application/pdf, filename=The Apple.pdf
[2018-04-24 13:46:26,965 INFO app.py:107 get] parser=&lt;flask_restful.reqparse.RequestParser object at 0x7f28038194e0&gt;
[2018-04-24 13:46:26,965 INFO app.py:110 get] parsedArgs={'q': 'play a juice song'}
[2018-04-24 13:46:26,966 INFO app.py:116 get] q=play a juice song
[2018-04-24 13:46:26,966 INFO app.py:125 get] foundSongName=&lt;_sre.SRE_Match object; span=(0, 17), match='play a juice song'&gt;
[2018-04-24 13:46:26,966 INFO app.py:131 get] songName=juice
[2018-04-24 13:46:26,967 INFO app.py:153 get] filenameRegex=re.compile('juice', re.IGNORECASE)
[2018-04-24 13:46:26,967 INFO app.py:159 get] findFileCursor=&lt;gridfs.grid_file.GridOutCursor object at 0x7f2803819518&gt;
[2018-04-24 13:46:26,971 INFO app.py:161 get] findFileCount=0
</code>

然后再去试试其他命令:

<code>[root@naturling-general-01 robotDemo]# supervisorctl stop all
robotDemo: stopped
[root@naturling-general-01 robotDemo]# supervisorctl status all
robotDemo                        STOPPED   Apr 24 01:49 PM
[root@naturling-general-01 robotDemo]# supervisorctl restart all
robotDemo: started
[root@naturling-general-01 robotDemo]# supervisorctl status all 
robotDemo                        RUNNING   pid 32741, uptime 0:00:03
[root@naturling-general-01 robotDemo]# supervisorctl status all
robotDemo                        RUNNING   pid 32741, uptime 0:00:04
</code>

貌似也都是正常的。

接着,再去考虑加到启动中

centos supervisor bootable

centos supervisor add to autostart

install and configure supervisord on centos 7.

<code>systemctl -a | grep supervisor
</code>

好像并没有找到supervisor

Server: Running supervisord automatically on startup for CentOS

How to control your deamon with Supervisord (On CentOS)

<code>[root@naturling-general-01 robotDemo]# systemctl start supervisor
Failed to start supervisor.service: Unit not found.
[root@naturling-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@naturling-general-01 robotDemo]# systemctl status supervisord.service
● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-04-24 13:55:45 CST; 11s ago
  Process: 653 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=2)
[root@naturling-general-01 robotDemo]# journalctl -xe
An error was encountered while opening journal file /var/log/journal/f0f31005fb5a436d88e3c6cbf54e25aa/system.journal, ignoring file.
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 0' suspended, next retry is Sat Apr 21 22:50:31 2018 [v8.24.0 try http://www.rsyslog.com/e/2007 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 3' suspended, next retry is Sat Apr 21 22:50:31 2018 [v8.24.0 try http://www.rsyslog.com/e/2007 ]
Apr 21 22:50:01 naturling-general-01 crond[518]: sendmail: fatal: parameter inet_interfaces: no local interface found for ::1
Apr 21 22:50:01 naturling-general-01 postfix/sendmail[17641]: fatal: parameter inet_interfaces: no local interface found for ::1
Apr 21 22:50:01 naturling-general-01 CROND[17637]: (root) MAIL (mailed 67 bytes of output but got status 0x004b
                                                   )
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 2' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 2' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 2' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 2' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 2' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 21 22:50:01 naturling-general-01 rsyslogd[503]: action 'action 2' resumed (module 'builtin:omfile') [v8.24.0 try http://www.rsyslog.com/e/2359 ]
Apr 23 14:45:00 naturling-general-01 sshd[21567]: Received disconnect from 112.4.64.138 port 56197:11: disconnected by user
Apr 23 14:45:00 naturling-general-01 sshd[21567]: Disconnected from 112.4.64.138 port 56197
Apr 23 14:45:07 naturling-general-01 sshd[21585]: Received disconnect from 112.4.64.138 port 56205:11: disconnected by user
Apr 23 14:45:07 naturling-general-01 sshd[21585]: Disconnected from 112.4.64.138 port 56205
Apr 23 18:29:52 naturling-general-01 sshd[22227]: Received disconnect from 112.4.64.138 port 62006:11: disconnected by user
Apr 23 18:29:52 naturling-general-01 sshd[22227]: Disconnected from 112.4.64.138 port 62006
Apr 23 18:29:52 naturling-general-01 sshd[22228]: Received disconnect from 112.4.64.138 port 62007:11: disconnected by user
Apr 23 18:29:52 naturling-general-01 sshd[22228]: Disconnected from 112.4.64.138 port 62007
Apr 24 10:21:56 naturling-general-01 sshd[23813]: Received disconnect from 101.81.69.165 port 57359:11: disconnected by user
Apr 24 10:21:56 naturling-general-01 sshd[23813]: Disconnected from 101.81.69.165 port 57359
Apr 24 10:22:43 naturling-general-01 sshd[23832]: Received disconnect from 101.81.69.165 port 57377:11: disconnected by user
Apr 24 10:22:43 naturling-general-01 sshd[23832]: Disconnected from 101.81.69.165 port 57377
Apr 24 10:23:04 naturling-general-01 sshd[23849]: Received disconnect from 101.81.69.165 port 57382:11: disconnected by user
Apr 24 10:23:04 naturling-general-01 sshd[23849]: Disconnected from 101.81.69.165 port 57382
[root@naturling-general-01 robotDemo]# 
</code>

很明显,此处貌似是有:

supervisord.service

的,但是systemctl失败了。

但是失败的错误,通过

<code>systemctl status supervisord.service
journalctl -xe
</code>

好像看不太懂。

去看看service文件:

<code>[root@naturling-general-01 robotDemo]# ll /usr/lib/systemd/system/supervisord.service
-rw-r--r-- 1 root root 221 Jul 29  2017 /usr/lib/systemd/system/supervisord.service
[root@naturling-general-01 robotDemo]# cat /usr/lib/systemd/system/supervisord.service
[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf

[Install]
WantedBy=multi-user.target
[root@naturling-general-01 robotDemo]# 
</code>

在CentOS上安装并配置Supervisor – 为程序员服务

Job for supervisord.service failed because the control process exited with error code

systemctl start supervisord failed

在centos7上使用systemd启动supervisor – 简书

去对比看看此处的配置,好像是少了很多,比如:

ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown

ExecReload=/usr/bin/supervisorctl $OPTIONS reload

但是看到ExecStart的/usr/bin/supervisord

那么就去手动试试:

<code>[root@naturling-general-01 robotDemo]# /usr/bin/supervisord -c /etc/supervisord.conf
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /usr/bin/supervisord -h
</code>

很明显,是有端口被占用了。。。

所以去看看是哪个程序占用了

<code>[root@naturling-general-01 robotDemo]# ps -ef | grep supervisor
root      1149 31807  0 14:04 pts/0    00:00:00 grep --color=auto supervisor
root     32338     1  0 13:43 ?        00:00:00 /usr/bin/python /usr/bin/supervisord
</code>

很明显是之前的还没有kill掉,去kill掉:

<code>[root@naturling-general-01 robotDemo]# ps -ef | grep supervisor
root      1237  1199  0 14:05 pts/0    00:00:00 grep --color=auto supervisor
root     32338     1  0 13:43 ?        00:00:00 /usr/bin/python /usr/bin/supervisord
[root@naturling-general-01 robotDemo]# kill -9 1237
-bash: kill: (1237) - No such process
[root@naturling-general-01 robotDemo]# kill -9 32338
[root@naturling-general-01 robotDemo]# ps -ef | grep supervisor
root      1264  1199  0 14:05 pts/0    00:00:00 grep --color=auto supervisor
</code>

然后再去systemctl试试

<code>[root@naturling-general-01 robotDemo]# systemctl status supervisord
● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-04-24 13:59:30 CST; 7min ago
  Process: 858 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=2)
[root@naturling-general-01 robotDemo]# systemctl restart supervisord
[root@naturling-general-01 robotDemo]# systemctl status supervisord
● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-04-24 14:06:39 CST; 5s ago
  Process: 1307 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
 Main PID: 1310 (supervisord)
   CGroup: /system.slice/supervisord.service
           ├─1310 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
           ├─1312 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1315 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1318 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1324 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1329 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1334 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1335 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1343 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1345 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           └─1352 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
[root@naturling-general-01 robotDemo]# 
[root@naturling-general-01 robotDemo]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@naturling-general-01 robotDemo]# systemctl stop supervisord  
[root@naturling-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: inactive (dead) since Tue 2018-04-24 14:08:04 CST; 3s ago
 Main PID: 1310 (code=exited, status=0/SUCCESS)
[root@naturling-general-01 robotDemo]# systemctl start supervisord    
[root@naturling-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: active (running) since Tue 2018-04-24 14:08:17 CST; 2s ago
  Process: 1434 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
 Main PID: 1437 (supervisord)
   CGroup: /system.slice/supervisord.service
           ├─1437 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
           ├─1438 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1441 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1443 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1445 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1448 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1456 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1463 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1469 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           ├─1477 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
           └─1484 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app
[root@naturling-general-01 robotDemo]# 
</code>

貌似就可以了。

即,kill之前正在运行的supervisord后,再去:

systemctl start supervisord

systemctl restart supervisord

都可以正常启动的。

然后通过:

systemctl enable supervisord

实现加到开机启动

其他命令:

查看状态:systemctl status supervisord

停止:systemctl stop supervisord

然后直接去reboot服务器,看看机器启动后,是否正常启动supervisord

<code>Last login: Tue Apr 24 14:05:08 2018 from x.x.x.x
</code>

Welcome to Alibaba Cloud Elastic Compute Service !

[root@naturling-general-01 ~]# systemctl status supervisord

● supervisord.service – Process Monitoring and Control Daemon

   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)

   Active: active (running) since Tue 2018-04-24 14:11:09 CST; 23s ago

Main PID: 675 (supervisord)

   CGroup: /system.slice/supervisord.service

           ├─675 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf

           ├─676 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─679 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─681 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─684 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─685 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─689 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─691 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─694 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           ├─702 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

           └─704 /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/python3.4m /root/.local/share/virtualenvs/robotDemo-dwdcgdaG/bin/gunicorn -c gunicorn_config.py app:app

Apr 24 14:11:08 naturling-general-01 systemd[1]: Starting Process Monitoring and Control Daemon…

Apr 24 14:11:09 naturling-general-01 systemd[1]: Started Process Monitoring and Control Daemon.

[root@naturling-general-01 ~]# supervisorctl status all

robotDemo                        RUNNING   pid 676, uptime 0:00:34

[root@naturling-general-01 ~]#

[root@naturling-general-01 ~]# ps -ef | grep supervisor

root       675     1  0 14:11 ?        00:00:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf

root      1333  1282  0 14:12 pts/0    00:00:00 grep –color=auto supervisor

[root@naturling-general-01 ~]# netstat -lanp | grep supervisor

unix  2      [ ACC ]     STREAM     LISTENING     10226    675/python           /var/run/supervisor/supervisor.sock.501

[root@naturling-general-01 ~]# netstat -lap | grep supervisor

unix  2      [ ACC ]     STREAM     LISTENING     10226    675/python           /var/run/supervisor/supervisor.sock.501

[root@naturling-general-01 ~]# netstat -p | grep supervisor  

[root@naturling-general-01 ~]# netstat -a | grep supervisor

unix  2      [ ACC ]     STREAM     LISTENING     10226    /var/run/supervisor/supervisor.sock.501

[root@naturling-general-01 ~]# netstat -lanp | grep 32851

tcp        0      0 0.0.0.0:32851           0.0.0.0:*               LISTEN      676/python3.4m   

说明是正常启动的。

【总结】

此处去:

  • CentOS:yum install supervisord

  • Ubuntu:apt-get install supervisord

安装supervisord,则可以在/etc中看到默认的配置和对应文件夹:

/etc/supervisord.conf

/etc/supervisord.d/

(注:如果用pip去安装,则会导致supervisord被安装到python的site-packages目录下了,比如:

/usr/lib/python2.7/site-packages/supervisor/

-》/etc中就找不到默认的配置文件supervisord.conf了。

然后由于此处

/etc/supervisord.conf

最后是:include包含ini文件,所以改为希望的conf:

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

接着,去创建一个项目的supervisor的配置文件,如下:

supervisord_robotDemo.conf

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

stdout_logfile=/root/naturling_20180101/web/server/robotDemo/logs/supervisor-%(program_name)s-stdout.log
stdout_logfile_maxbytes=2MB
stdout_logfile_backups=10

stderr_logfile=/root/naturling_20180101/web/server/robotDemo/logs/supervisor-%(program_name)s-stderr.log
stderr_logfile_maxbytes=2MB
stderr_logfile_backups=10
</code>

 

然后再去:

<code>systemctl start supervisord
</code>

即可正常启动。

  • 添加到开机启动:systemctl enable supervisord

    • 注意:此处估计是CentOS中通过yum去install,属于通过系统包管理工具去安装,所以默认帮忙生成好了对应的supervisord.service,所以才能直接用systemctl去管理的。否则估计要自己建立对应的supervisord.service文件,并配置合适的参数,加到合适的位置,才可以实现开机启动。

  • 其他管理命令:

    • 重新启动:systemctl restart supervisord

    • 停止:systemctl stop supervisord

    • 查看状态:systemctl status supervisord

当然也可以通过supervisorctl去管理:

  • 查看状态:supervisorctl status all

  • 全部停止:supervisorctl stop all

  • (当配置文件或文件本身更改后,想要重新加载):supervisorctl reload

转载请注明:在路上 » 【已解决】CentOS中用supervisor去管理gunicorn的Flask的app

发表我的评论
取消评论

表情

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

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