Linux下的守护进程工具-Supervisor

简介:没有

安装

sudo apt-get install supervisor

(其实我是用Mint的软件管理器安装的……)

配置

参考帖子:

详解supervisor使用教程 http://www.jb51.net/article/128676.htm

supervisor 从安装到使用 http://www.jianshu.com/p/3658c963d28b

使用 Supervisor 进行进程管理 http://www.jianshu.com/p/2a48b2c987e0

执行命令

sudo supervisord
sudo supervisorctl start/stop/restart RROGRAM_NAME
sudo supervisorctl reload
sudo supervisorctl status

配置文件模板

我的配置文件在/etc/supervisor/supervisord.conf
我的配置模板:

[program:ssr]
command = python local.py -c /home/jerry/opt/shadowsocksr-manyuser/shadowsocks/shadowsocksr.json
stdout_logfile=/tmp/ssr.log
stdout_logfile_backups=2 ;默认为10 
stdout_capture_maxbytes=1MB 

[program:drcom]
command = python2 /home/jerry/opt/DRCOM_PY/latest-wired.py
stdout_logfile=/tmp/drcom.log
stdout_logfile_backups=2 ;默认为10 
stdout_capture_maxbytes=1MB 
autostart= false

通用模板

;[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.