supervisor

supervisor 能管理linux的進程,項目中用它來保證一個進程斷了自動重啓。


用的是ubuntu系統,所以可以直接 apt-get install supervisor 進行安裝

也可以用其他方法安裝


安裝完畢生成配置文件:

執行:echo_supervisord_conf > /etc/supervisor/supervisord.conf


在文件底部有個include模塊,前面的分號;去掉

[include]

files = /etc/supervisor/*.conf

在目錄/etc/supervisor下面新建一個demo.conf,將supervisord.conf裏program裏的內容複製過來,啓用你需要的配置項

[program:demo]
command=php tests/server.php              ; 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=/data/www/chat                ; 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=true        ; 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=root                   ; setuid to this UNIX account to run the program
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/tmp/super        ; 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=/tmp/super       ; 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)

配置完成後就是啓動supervisor :

supervisord -c /etc/supervisor/supervisord.conf


完成啓動後,可以用supervisorctl來進行管理應用,一些基本的命令

supervisord,初始啓動Supervisord,啓動、管理配置中設置的進程。
supervisorctl stop programxxx,停止某一個進程(programxxx),programxxx爲[program:chatdemon]裏配置的值,這個示例就是chatdemon。
supervisorctl start programxxx,啓動某個進程
supervisorctl restart programxxx,重啓某個進程
supervisorctl stop all,停止全部進程,注:start、restart、stop都不會載入最新的配置文件。
supervisorctl reload,載入最新的配置文件,並按新的配置啓動、管理所有進程。
supervisorctl reread,當一個服務由自動啓動修改爲手動啓動時執行一下就ok


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章