解决 supervisor中stop django进程不能真正的停止 问题
用supervisor重啟djangotest 發現用ps aux有兩個進程
使用stop發現只會停止父進程
用ps aux查看 發現停止的是6902的父進程還有一個子進程,
所以stop之后再start djangotest會報錯
所以還要再用sudo kill -15 6904殺死 子進程6904 才能start成功
原因: django,父進程會派生出子進程,停止服務發現supervisor只停止了父進程
問題解決:
避免 Supervisord 產生孤兒進程
使用 Supervisord start 的進程如果開啟多進程,產生了一些子進程,當 stop 父進程的時候,父進程有可能比子進程更早地退出,就會導致子進程成為孤兒進程,脫離 Supervisord 管理。
在 [program:x] 段配置 stopasgroup 選項和 killasgroup 選項可以避免這一情況。或者在/etc/supervisor/conf.d/XXXXX.conf 相應的配置文件下 配置
stopasgroup=false ;默認為false,進程被殺死時,是否向這個進程組發送stop信號,包括子進程 killasgroup=false ;默認為false,向進程組發送kill信號,包括子進程1start djangotest 可以用ps aux發現有兩個進程
2stop djangotest后用ps aux中發現進程消失
3再次start djangotest 成功不會報錯
以下不那么重要
supervisor配置文件詳解 :
[unix_http_server] file=/tmp/supervisor.sock ;UNIX socket 文件,supervisorctl 會使用 ;chmod=0700 ;socket文件的mode,默認是0700 ;chown=nobody:nogroup ;socket文件的owner,格式:uid:gid;[inet_http_server] ;HTTP服務器,提供web管理界面 ;port=127.0.0.1:9001 ;Web管理后臺運行的IP和端口,如果開放到公網,需要注意安全性 ;username=user ;登錄管理后臺的用戶名 ;password=123 ;登錄管理后臺的密碼[supervisord] logfile=/tmp/supervisord.log ;日志文件,默認是 $CWD/supervisord.log logfile_maxbytes=50MB ;日志文件大小,超出會rotate,默認 50MB,如果設成0,表示不限制大小 logfile_backups=10 ;日志文件保留備份數量默認10,設為0表示不備份 loglevel=info ;日志級別,默認info,其它: debug,warn,trace pidfile=/tmp/supervisord.pid ;pid 文件 nodaemon=false ;是否在前臺啟動,默認是false,即以 daemon 的方式啟動 minfds=1024 ;可以打開的文件描述符的最小值,默認 1024 minprocs=200 ;可以打開的進程數的最小值,默認 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]是被管理的進程配置參數,xx是進程的名稱 [program:xx] command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run ; 程序啟動命令 autostart=true ; 在supervisord啟動的時候也自動啟動 startsecs=10 ; 啟動10秒后沒有異常退出,就表示進程正常啟動了,默認為1秒 autorestart=true ; 程序退出后自動重啟,可選值:[unexpected,true,false],默認為unexpected,表示進程意外殺死后才重啟 startretries=3 ; 啟動失敗自動重試次數,默認是3 user=tomcat ; 用哪個用戶啟動進程,默認是root priority=999 ; 進程啟動優先級,默認999,值小的優先啟動 redirect_stderr=true ; 把stderr重定向到stdout,默認false stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默認50MB stdout_logfile_backups = 20 ; stdout 日志文件備份數,默認是10 ; stdout 日志文件,需要注意當指定目錄不存在時無法正常啟動,所以需要手動創建目錄(supervisord 會自動創建日志文件) stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out stopasgroup=false ;默認為false,進程被殺死時,是否向這個進程組發送stop信號,包括子進程 killasgroup=false ;默認為false,向進程組發送kill信號,包括子進程;包含其它配置文件 [include] files = relative/directory/*.ini ;可以指定一個或多個以.ini結束的配置文件其中
stopasgroup=false ;默認為false,進程被殺死時,是否向這個進程組發送stop信號,包括子進程 killasgroup=false ;默認為false,向進程組發送kill信號,包括子進程完整的supervisord.conf配置文件
supervisord.conf (只改后面的include就可以了)登錄后復制 ; 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總結
以上是生活随笔為你收集整理的解决 supervisor中stop django进程不能真正的停止 问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu tail、history|
- 下一篇: 通过端口号找到进程