解决 supervisor中stop django进程不能真正的停止 问题
用supervisor重啟djangotest 發(fā)現(xiàn)用ps aux有兩個(gè)進(jìn)程
使用stop發(fā)現(xiàn)只會(huì)停止父進(jìn)程
用ps aux查看 發(fā)現(xiàn)停止的是6902的父進(jìn)程還有一個(gè)子進(jìn)程,
所以stop之后再start djangotest會(huì)報(bào)錯(cuò)
所以還要再用sudo kill -15 6904殺死 子進(jìn)程6904 才能start成功
原因: django,父進(jìn)程會(huì)派生出子進(jìn)程,停止服務(wù)發(fā)現(xiàn)supervisor只停止了父進(jìn)程
問題解決:
避免 Supervisord 產(chǎn)生孤兒進(jìn)程
使用 Supervisord start 的進(jìn)程如果開啟多進(jìn)程,產(chǎn)生了一些子進(jìn)程,當(dāng) stop 父進(jìn)程的時(shí)候,父進(jìn)程有可能比子進(jìn)程更早地退出,就會(huì)導(dǎo)致子進(jìn)程成為孤兒進(jìn)程,脫離 Supervisord 管理。
在 [program:x] 段配置 stopasgroup 選項(xiàng)和 killasgroup 選項(xiàng)可以避免這一情況。或者在/etc/supervisor/conf.d/XXXXX.conf 相應(yīng)的配置文件下 配置
stopasgroup=false ;默認(rèn)為false,進(jìn)程被殺死時(shí),是否向這個(gè)進(jìn)程組發(fā)送stop信號,包括子進(jìn)程 killasgroup=false ;默認(rèn)為false,向進(jìn)程組發(fā)送kill信號,包括子進(jìn)程1start djangotest 可以用ps aux發(fā)現(xiàn)有兩個(gè)進(jìn)程
2stop djangotest后用ps aux中發(fā)現(xiàn)進(jìn)程消失
3再次start djangotest 成功不會(huì)報(bào)錯(cuò)
以下不那么重要
supervisor配置文件詳解 :
[unix_http_server] file=/tmp/supervisor.sock ;UNIX socket 文件,supervisorctl 會(huì)使用 ;chmod=0700 ;socket文件的mode,默認(rèn)是0700 ;chown=nobody:nogroup ;socket文件的owner,格式:uid:gid;[inet_http_server] ;HTTP服務(wù)器,提供web管理界面 ;port=127.0.0.1:9001 ;Web管理后臺運(yùn)行的IP和端口,如果開放到公網(wǎng),需要注意安全性 ;username=user ;登錄管理后臺的用戶名 ;password=123 ;登錄管理后臺的密碼[supervisord] logfile=/tmp/supervisord.log ;日志文件,默認(rèn)是 $CWD/supervisord.log logfile_maxbytes=50MB ;日志文件大小,超出會(huì)rotate,默認(rèn) 50MB,如果設(shè)成0,表示不限制大小 logfile_backups=10 ;日志文件保留備份數(shù)量默認(rèn)10,設(shè)為0表示不備份 loglevel=info ;日志級別,默認(rèn)info,其它: debug,warn,trace pidfile=/tmp/supervisord.pid ;pid 文件 nodaemon=false ;是否在前臺啟動(dòng),默認(rèn)是false,即以 daemon 的方式啟動(dòng) minfds=1024 ;可以打開的文件描述符的最小值,默認(rèn) 1024 minprocs=200 ;可以打開的進(jìn)程數(shù)的最小值,默認(rèn) 200[supervisorctl] serverurl=unix:///tmp/supervisor.sock ;通過UNIX socket連接supervisord,路徑與unix_http_server部分的file一致 ;serverurl=http://127.0.0.1:9001 ; 通過HTTP的方式連接supervisord; [program:xx]是被管理的進(jìn)程配置參數(shù),xx是進(jìn)程的名稱 [program:xx] command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run ; 程序啟動(dòng)命令 autostart=true ; 在supervisord啟動(dòng)的時(shí)候也自動(dòng)啟動(dòng) startsecs=10 ; 啟動(dòng)10秒后沒有異常退出,就表示進(jìn)程正常啟動(dòng)了,默認(rèn)為1秒 autorestart=true ; 程序退出后自動(dòng)重啟,可選值:[unexpected,true,false],默認(rèn)為unexpected,表示進(jìn)程意外殺死后才重啟 startretries=3 ; 啟動(dòng)失敗自動(dòng)重試次數(shù),默認(rèn)是3 user=tomcat ; 用哪個(gè)用戶啟動(dòng)進(jìn)程,默認(rèn)是root priority=999 ; 進(jìn)程啟動(dòng)優(yōu)先級,默認(rèn)999,值小的優(yōu)先啟動(dòng) redirect_stderr=true ; 把stderr重定向到stdout,默認(rèn)false stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默認(rèn)50MB stdout_logfile_backups = 20 ; stdout 日志文件備份數(shù),默認(rèn)是10 ; stdout 日志文件,需要注意當(dāng)指定目錄不存在時(shí)無法正常啟動(dòng),所以需要手動(dòng)創(chuàng)建目錄(supervisord 會(huì)自動(dòng)創(chuàng)建日志文件) stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out stopasgroup=false ;默認(rèn)為false,進(jìn)程被殺死時(shí),是否向這個(gè)進(jìn)程組發(fā)送stop信號,包括子進(jìn)程 killasgroup=false ;默認(rèn)為false,向進(jìn)程組發(fā)送kill信號,包括子進(jìn)程;包含其它配置文件 [include] files = relative/directory/*.ini ;可以指定一個(gè)或多個(gè)以.ini結(jié)束的配置文件其中
stopasgroup=false ;默認(rèn)為false,進(jìn)程被殺死時(shí),是否向這個(gè)進(jìn)程組發(fā)送stop信號,包括子進(jìn)程 killasgroup=false ;默認(rèn)為false,向進(jìn)程組發(fā)送kill信號,包括子進(jìn)程完整的supervisord.conf配置文件
supervisord.conf (只改后面的include就可以了)登錄后復(fù)制 ; Sample supervisor config file. ; ; For more information on the config file, please see: ; http://supervisord.org/configuration.html ; ; Notes: ; - Shell expansion ("~" or "$HOME") is not supported. Environment ; variables can be expanded using this syntax: "%(ENV_HOME)s". ; - Comments must have a leading space: "a=b ;comment" not "a=b;comment".[unix_http_server] file=/tmp/supervisor.sock ; (the path to the socket file) ;chmod=0700 ; socket 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=/tmp/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=/tmp/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:///tmp/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) ;startsecs=1 ; # of secs prog must stay up to be running (def. 1) ;startretries=3 ; max # of serial start failures when starting (default 3) ;autorestart=unexpected ; when to restart if exited after running (def: unexpected) ;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) ;stopsignal=QUIT ; signal used to kill process (default TERM) ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;stopasgroup=false ; send stop signal to the UNIX process group (default false) ;killasgroup=false ; SIGKILL the UNIX process group (def false) ;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) ;startsecs=1 ; # of secs prog must stay up to be running (def. 1) ;startretries=3 ; max # of serial start failures when starting (default 3) ;autorestart=unexpected ; autorestart if exited after running (def: unexpected) ;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) ;stopsignal=QUIT ; signal used to kill process (default TERM) ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;stopasgroup=false ; send stop signal to the UNIX process group (default false) ;killasgroup=false ; SIGKILL the UNIX process group (def false) ;user=chrism ; setuid to this UNIX account to run the program ;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners ;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=10 ; # 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 = /etc/supervisord.d/*.conf總結(jié)
以上是生活随笔為你收集整理的解决 supervisor中stop django进程不能真正的停止 问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu tail、history|
- 下一篇: 通过端口号找到进程