1. 程式人生 > 實用技巧 >使用supervisor管理tomcat,nginx等程序詳解

使用supervisor管理tomcat,nginx等程序詳解

1,介紹

官網:http://supervisord.org

Supervisor是用Python開發的一套通用的程序管理程式,能將一個普通的命令列程序變為後臺daemon,並監控程序狀態,異常退出時能自動重啟。

它是通過fork/exec的方式把這些被管理的程序當作supervisor的子程序來啟動,這樣只要在supervisor的配置檔案中,把要管理的程序的可執行檔案的路徑寫進去即可。也實現當子程序掛掉的時候,父程序可以準確獲取子程序掛掉的資訊的,可以選擇是否自己啟動和報警。supervisor還提供了一個功能,可以為supervisord或者每個子程序,設定一個非root的user,這個user就可以管理它對應的程序。

2,安裝

這裡我推薦使用easy_install的方式安裝,因為這種方式安裝的自定義性比較強,安裝也比較方便,雖然網上有不少地方也介紹yum方式的安裝,但是據我個人的體驗來看,不如這種安裝方式來的好。

而且這種方式安裝以及使用,是適用於CentOS-6以及CenOS-7兩個大系統版本的。

yum install -y python-setuptools.noarch 
easy_install supervisor 

如果兩條命令都執行沒有問題,就安裝成功了。

也可以通過如下指令測試安裝是否成功:

[root@moban ~]$echo_supervisord_conf
; 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".
;  - Quotes around values are not supported, except in the case of
;    the environment= options as shown below.
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
;  - Command will be truncated if it looks like a config file comment, e.g.
;    "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
 
[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           ; # of main logfile backups; 0 means none, 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 rpcinterface:supervisor 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:x] sections.
 
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
 
; The supervisorctl section configures how supervisorctl will connect to
; supervisord.  configure it match the settings in either the unix_http_server
; or inet_http_server section.
 
[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 in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available
 
; The sample program section below 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 (0 means none, 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 (0 means none, 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 sample eventlistener section below shows all possible eventlistener
; subsection values.  Create one or more 'real' eventlistener: sections to be
; able to handle event notifications sent by supervisord.
 
;[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 (0 means none, 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 (0 means none, 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 sample group section below 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 = relative/directory/*.ini

3,建立主配置

1,建立supervisor配置檔案目錄

mkdir -m 755 -p /etc/supervisor

2,建立主配置檔案

echo_supervisord_conf >/etc/supervisor/supervisord.conf

3,建立專案配置檔案目錄

mkdir -m 755 /etc/supervisor/conf.d

配置檔案的詳細解析放在最後

4,配置管理tomcat程序

主機上安裝的tomcat程序,無論怎麼操作都無法開機自啟動,那麼現在有了這個程序管理工具,就可以實現對tomcat程序的管理了。

程序管理配置引數,不建議全都寫在supervisord.conf

檔案中,應該每個程序寫一個配置檔案放在include指定的目錄下包含進supervisord.conf檔案中。

所以此時應該先修改一下這個引數:

vim /etc/supervisor/supervisord.conf

直接跳到文字最後,刪掉前邊的註釋(分號)。然後更改如下:

[include]
files = /etc/supervisor/conf.d/*.ini

然後建立tomcat的配置檔案。

需要注意的地方====》所有要管理的程序都不能開啟後臺模式,只能使用前臺模式進行配置;使用後臺模式會出現一直重新開啟新程序的情況。

[root@fbtest conf.d]$cat tomcat.ini
[program:tomcat]
command=/usr/local/tomcat/bin/catalina.sh run
stdout_logfile=/usr/local/tomcat/logs/catalina.out
stderr_logfile=/usr/local/tomcat/logs/catalina.out
environment=JAVA_HOME="/usr/local/jdk1.8.0_144",JAVA_BIN="/usr/local/jdk1.8.0_144/bin"
autorestart=false
startsecs=60
priority=1
stopasgroup=true
killasgroup=true

注意:我當時寫tomcat啟動命令的時候,使用了/usr/local/tomcat_adminB/bin/startup.sh這個命令,結果發現,不知道什麼原因,竟然會一次啟動四個tomcat程序,也是挺詭異的。
還有,因為使用catalina.sh run的方式啟動是一種前臺的啟動方式,因此日誌並不會輸出到對應的tomcat日誌裡,當中有兩句定義日誌的指令,其中生效的是stderr_logfile,也就是說,是這條指令,使得儘管我們在前臺啟動的tomcat應用,依然會將日誌輸出到catalina.out裡邊。

還可以建立一個管理nginx的配置檔案(也是要關閉後臺模式,在執行的命令後面新增-g “daemon off;”)。

[root@fbtest conf.d]$cat nginx.ini
[program:nginx]
command=/usr/local/nginx/sbin/nginx -g 'daemon off;'
priority=1000
autostart=true
startretries=3
autorestart=true
user=root

還可以建立更多的管理服務的檔案,這些配置依據文末的講解,都可以非常容易的配置出來,不過有一些屬性則需要自己去進行除錯,然後來適應實際的工作需求,比如我在配置tomcat的配置時,就把自動重啟的功能給關閉了,因為在測試環境需要經常釋出,釋出就免不了重啟服務,如果這個地方開啟自動重啟,那麼很容易會在釋出的時候出現各種意想不到的情況。

5,啟動supervisor

通過啟動命令載入配置檔案。

supervisord -c /etc/supervisor/supervisord.conf
[root@moban ~]$supervisorctl
tomcat     FATAL     Exited too quickly (process log may have details)
supervisor>

如果此時報錯,那麼google一下報的錯誤,很容易解決。

以上兩個命令說明:

  • supervisord : supervisor的伺服器端部分,用於supervisor啟動。
  • supervisorctl:啟動supervisor的命令列視窗,在該命令列中可執行start、stop、status、reload等操作。

注意:每次修改配置檔案後需進入supervisorctl,執行reload, 改動部分才能生效。

1,建立supervisor服務管理檔案

此時可以通過檢視tomcat的日誌,來判斷,是否啟動成功,也可以通過重啟伺服器,來檢驗,是否生效。

估計重啟伺服器還不行,因為還沒有新增supervisor程序的開機自啟。

這個地方因為CentOS版本升級之後對服務的管理方式不同,因此建立的方式也不一樣,我這裡分別列出來。

1,如果是CentOS-7

進入/lib/systemd/system目錄,並建立supervisord.service檔案。

[root@moban ~]$cat /lib/systemd/system/supervisord.service
 
[Unit]
Description=supervisord
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
 
[Install]
WantedBy=multi-user.target

2,如果是CenOS6

[root@moban ~]$cat  /etc/rc.d/init.d/supervisord
 
#!/bin/bash
#
# supervisord   This scripts turns supervisord on
#
# Author:       Mike McGrath <[email protected]> (based off yumupdatesd)
#
# chkconfig:    - 95 04
#
# description:  supervisor is a process control utility.  It has a web based
#               xmlrpc interface as well as a few other nifty features.
# processname:  supervisord
# config: /etc/supervisord.conf
# pidfile: /var/run/supervisord.pid
#
 
# source function library
. /etc/rc.d/init.d/functions
 
RETVAL=0
 
start() {
    echo -n $"Starting supervisord: "
    daemon "supervisord -c /etc/supervisor/supervisord.conf"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/supervisord
}
 
stop() {
    echo -n $"Stopping supervisord: "
    killproc supervisord
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/supervisord
}
 
restart() {
    stop
    start
}
 
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|force-reload|reload)
    restart
    ;;
  condrestart)
    [ -f /var/lock/subsys/supervisord ] && restart
    ;;
  status)
    status supervisord
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    exit 1
esac
 
exit $RETVAL

2,加入開機自啟

1,如果是CentOS-7

chmod 766 /lib/systemd/system/supervisord.service
systemctl daemon-reload
systemctl enable supervisord.service
systemctl start supervisord
systemctl status supervisord

2,如果是CenOS6

chkconfig supervisord on

6,開啟web管理

一般情況都是使用supervisorctl在命令列進行管理,不過也可以玩一下開啟web管理,然後再關掉就好了

編輯配置檔案:

vim /etc/supervisor/supervisord.conf
 
;[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))
 
修改成:
 
[inet_http_server]         ; inet (TCP) server disabled by default
port=192.168.157.182: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))
 
port:繫結訪問IP和埠,這裡是繫結的是本機IP和9001埠(寫上你自己的伺服器IP或是本地IP)
username:登入管理後臺的使用者名稱
password:登入管理後臺的密碼

訪問一下:

7,配置檔案詳解

[unix_http_server]            
file=/tmp/supervisor.sock   ; socket檔案的路徑,supervisorctl用XML_RPC和supervisord通訊就是通過它進行的。如果不設定的話,supervisorctl也就不能用了,不設定的話,預設為none。 非必須設定        
;chmod=0700                 ; 這個簡單,就是修改上面的那個socket檔案的許可權為0700,不設定的話,預設為0700。 非必須設定
;chown=nobody:nogroup       ; 這個一樣,修改上面的那個socket檔案的屬組為user.group,不設定的話,預設為啟動supervisord程序的使用者及屬組。非必須設定
;username=user              ; 使用supervisorctl連線的時候,認證的使用者,不設定的話,預設為不需要使用者。 非必須設定
;password=123               ; 和上面的使用者名稱對應的密碼,可以直接使用明碼,也可以使用SHA加密,如:{SHA}82ab876d1387bfafe46cc1c8a2ef074eae50cb1d,預設不設定。。。非必須設定
;[inet_http_server]         ; 偵聽在TCP上的socket,Web Server和遠端的supervisorctl都要用到他,不設定的話,預設為不開啟。非必須設定
;port=127.0.0.1:9001        ; 這個是偵聽的IP和埠,偵聽所有IP用 :9001或*:9001。這個必須設定,只要上面的[inet_http_server]開啟了,就必須設定它
;username=user              ; 這個和上面的uinx_http_server一個樣。非必須設定
;password=123               ; 這個也一個樣。非必須設定
[supervisord]                ;這個主要是定義supervisord這個服務端程序的一些引數的,這個必須設定,不設定,supervisor就不用幹活了
logfile=/tmp/supervisord.log ; 這個是supervisord這個主程序的日誌路徑,注意和子程序的日誌不搭嘎。預設路徑$CWD/supervisord.log,$CWD是當前目錄。。非必須設定
logfile_maxbytes=50MB        ; 這個是上面那個日誌檔案的最大的大小,當超過50M的時候,會生成一個新的日誌檔案。當設定為0時,表示不限制檔案大小,預設值是50M,非必須設定。              
logfile_backups=10           ; 日誌檔案保持的數量,上面的日誌檔案大於50M時,就會生成一個新檔案。檔案數量大於10時,最初的老檔案被新檔案覆蓋,檔案數量將保持為10,當設定為0時,表示不限制檔案的數量。預設情況下為10。。。非必須設定
loglevel=info                ; 日誌級別,有critical, error, warn, info, debug, trace, or blather等,預設為info。。。非必須設定項
pidfile=/tmp/supervisord.pid ; supervisord的pid檔案路徑。 預設為$CWD/supervisord.pid。。。非必須設定
nodaemon=false               ; 如果是true,supervisord程序將在前臺執行,預設為false,也就是後臺以守護程序執行。。。非必須設定
minfds=1024                  ; 這個是最少系統空閒的檔案描述符,低於這個值supervisor將不會啟動。系統的檔案描述符在這裡設定cat /proc/sys/fs/file-max,預設情況下為1024。。。非必須設定
minprocs=200                 ; 最小可用的程序描述符,低於這個值supervisor也將不會正常啟動。ulimit  -u這個命令,可以檢視linux下面使用者的最大程序數,預設為200。。。非必須設定
;umask=022                   ; 程序建立檔案的掩碼,預設為022。。非必須設定項
;user=chrism                 ; 這個引數可以設定一個非root使用者,當我們以root使用者啟動supervisord之後。我這裡面設定的這個使用者,也可以對supervisord進行管理,預設情況是不設定。。。非必須設定項
;identifier=supervisor       ; 這個引數是supervisord的識別符號,主要是給XML_RPC用的。當你有多個supervisor的時候,而且想呼叫XML_RPC統一管理,就需要為每個,supervisor設定不同的識別符號了,預設是supervisord。。。非必需設定
;directory=/tmp              ; 這個引數是當supervisord作為守護程序執行的時候,設定這個引數的話,啟動supervisord程序之前,會先切換到這個目錄,預設不設定。。。非必須設定
;nocleanup=true              ; 這個引數當為false的時候,會在supervisord程序啟動的時候,把以前子程序產生的日誌檔案(路徑為AUTO的情況下)清除掉。有時候咱們想要看歷史日誌,當然不想日誌被清除了。所以可以設定為true,預設是false,有除錯需求的同學可以設定為true。。。非必須設定
;childlogdir=/tmp            ; 當子程序日誌路徑為AUTO的時候,子程序日誌檔案的存放路徑。預設路徑是這個東西,執行下面的這個命令看看就OK了,處理的東西就預設路徑python -c "import tempfile;print tempfile.gettempdir()",非必須設定
;environment=KEY="value"     ; 這個是用來設定環境變數的,supervisord在linux中啟動預設繼承了linux的環境變數,在這裡可以設定supervisord程序特有的其他環境變數。supervisord啟動子程序時,子程序會拷貝父程序的記憶體空間內容。 所以設定的這些環境變數也會被子程序繼承。小例子:environment=name="haha",age="hehe"預設為不設定。。。非必須設定
;strip_ansi=false            ; 這個選項如果設定為true,會清除子程序日誌中的所有ANSI 序列。什麼是ANSI序列呢?就是我們的\n,\t這些東西。預設為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]    ;這個選項是給XML_RPC用的,當然你如果想使用supervisord或者web server 這個選項必須要開啟的
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface 
[supervisorctl]              ;這個主要是針對supervisorctl的一些配置  
serverurl=unix:///tmp/supervisor.sock ; 這個是supervisorctl本地連線supervisord的時候,本地UNIX socket路徑,注意這個是和前面的[unix_http_server]對應的預設值就是unix:///tmp/supervisor.sock。。非必須設定
;serverurl=http://127.0.0.1:9001 ; 這個是supervisorctl遠端連線supervisord的時候,用到的TCP socket路徑注意這個和前面的[inet_http_server]對應預設就是http://127.0.0.1:9001。。。非必須項
;username=chris              ; 使用者名稱,預設空。。非必須設定
;password=123                ; 密碼,預設空。。非必須設定
;prompt=mysupervisor         ; 輸入使用者名稱密碼時候的提示符,預設supervisor。。非必須設定
;history_file=~/.sc_history  ; 這個引數和shell中的history類似,我們可以用上下鍵來查詢前面執行過的命令,預設是no file的。。所以我們想要有這種功能,必須指定一個檔案。。。非必須設定
; 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]      ;這個就是咱們要管理的子程序了,":"後面的是名字,最好別亂寫和實際程序有點關聯最好。這樣的program我們可以設定一個或多個,一個program就是要被管理的一個程序
;command=/bin/cat              ; 這個就是我們的要啟動程序的命令路徑了,可以帶引數例子:/home/test.py -a 'hehe'有一點需要注意的是,我們的command只能是那種在終端執行的程序,不能是守護程序。這個想想也知道了,比如說command=service httpd start。httpd這個程序被linux的service管理了,我們的supervisor再去啟動這個命令這已經不是嚴格意義的子程序了。這個是個必須設定的項
;process_name=%(program_name)s ; 這個是程序名,如果我們下面的numprocs引數為1的話,就不用管這個引數了,它預設值%(program_name)s也就是上面的那個program冒號後面的名字,但是如果numprocs為多個的話,那就不能這麼幹了。想想也知道,不可能每個程序都用同一個程序名吧。
;numprocs=1                    ; 啟動程序的數目。當不為1時,就是程序池的概念,注意process_name的設定 預設為1    。。非必須設定
;directory=/tmp                ; 程序執行前,會前切換到這個目錄 預設不設定。。。非必須設定
;umask=022                     ; 程序掩碼,預設none,非必須
;priority=999                  ; 子程序啟動關閉優先順序,優先順序低的,最先啟動,關閉的時候最後關閉 預設值為999 。。非必須設定
;autostart=true                ; 如果是true的話,子程序將在supervisord啟動後被自動啟動 預設就是true   。。非必須設定
;autorestart=unexpected        ; 這個是設定子程序掛掉後自動重啟的情況,有三個選項,false,unexpected和true。如果為false的時候,無論什麼情況下,都不會被重新啟動,如果為unexpected,只有當程序的退出碼不在下面的exitcodes裡面定義的退 出碼的時候,才會被自動重啟。當為true的時候,只要子程序掛掉,將會被無條件的重啟
;startsecs=1                   ; 這個選項是子程序啟動多少秒之後,此時狀態如果是running,則我們認為啟動成功了 預設值為1 。。非必須設定
;startretries=3                ; 當程序啟動失敗後,最大嘗試啟動的次數。。當超過3次後,supervisor將把此程序的狀態置為FAIL預設值為3 。。非必須設定
;exitcodes=0,2                 ; 注意和上面的的autorestart=unexpected對應。。exitcodes裡面的定義的退出碼是expected的。
;stopsignal=QUIT               ; 程序停止訊號,可以為TERM, HUP, INT, QUIT, KILL, USR1, or USR2等訊號預設為TERM 。。當用設定的訊號去幹掉程序,退出碼會被認為是expected,非必須設定
;stopwaitsecs=10               ; 這個是當我們向子程序傳送stopsignal訊號後,到系統返回資訊給supervisord,所等待的最大時間。 超過這個時間,supervisord會向該子程序傳送一個強制kill的訊號。預設為10秒。。非必須設定
;stopasgroup=false             ; 這個東西主要用於,supervisord管理的子程序,這個子程序本身還有子程序。那麼我們如果僅僅幹掉supervisord的子程序的話,子程序的子程序有可能會變成孤兒程序。所以咱們可以設定可個選項,把整個該子程序的整個程序組都幹掉。 設定為true的話,一般killasgroup也會被設定為true。需要注意的是,該選項傳送的是stop訊號預設為false。。非必須設定。。
;killasgroup=false             ; 這個和上面的stopasgroup類似,不過傳送的是kill訊號
;user=chrism                   ; 如果supervisord是root啟動,我們在這裡設定這個非root使用者,可以用來管理該program預設不設定。。。非必須設定項
;redirect_stderr=true          ; 如果為true,則stderr的日誌會被寫入stdout日誌檔案中 預設為false,非必須設定
;stdout_logfile=/a/path        ; 子程序的stdout的日誌路徑,可以指定路徑,AUTO,none等三個選項。設定為none的話,將沒有日誌產生。設定為AUTO的話,將隨機找一個地方生成日誌檔案,而且當supervisord重新啟動的時候,以前的日誌檔案會被清空。當 redirect_stderr=true的時候,sterr也會寫進這個日誌檔案
;stdout_logfile_maxbytes=1MB   ; 日誌檔案最大大小,和[supervisord]中定義的一樣。預設為50
;stdout_logfile_backups=10     ; 和[supervisord]定義的一樣。預設10
;stdout_capture_maxbytes=1MB   ; 這個東西是設定capture管道的大小,當值不為0的時候,子程序可以從stdout傳送資訊,而supervisor可以根據資訊,傳送相應的event。預設為0,為0的時候表達關閉管道。。。非必須項
;stdout_events_enabled=false   ; 當設定為ture的時候,當子程序由stdout向檔案描述符中寫日誌的時候,將觸發supervisord傳送PROCESS_LOG_STDOUT型別的event 預設為false。。。非必須設定
;stderr_logfile=/a/path        ; 這個東西是設定stderr寫的日誌路徑,當redirect_stderr=true。這個就不用設定了,設定了也是白搭。因為它會被寫入stdout_logfile的同一個檔案中 預設為AUTO,也就是隨便找個地存,supervisord重啟被清空。。非必須設定
;stderr_logfile_maxbytes=1MB   ; 這個出現好幾次了,就不重複了
;stderr_logfile_backups=10     ; 這個也是
;stderr_capture_maxbytes=1MB   ; 這個一樣,和stdout_capture一樣。 預設為0,關閉狀態
;stderr_events_enabled=false   ; 這個也是一樣,預設為false
;environment=A="1",B="2"       ; 這個是該子程序的環境變數,和別的子程序是不共享的
;serverurl=AUTO                ; 
; 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] ;這個東西其實和program的地位是一樣的,也是suopervisor啟動的子程序,不過它乾的活是訂閱supervisord傳送的event。他的名字就叫listener了。我們可以在listener裡面做一系列處理,比如報警等等
;command=/bin/eventlistener    ; 這個和上面的program一樣,表示listener的可執行檔案的路徑
;process_name=%(program_name)s ; 這個也一樣,程序名,當下面的numprocs為多個的時候,才需要。否則預設就OK了
;numprocs=1                    ; 相同的listener啟動的個數
;events=EVENT                  ; event事件的型別,也就是說,只有寫在這個地方的事件型別。才會被髮送
;buffer_size=10                ; 這個是event佇列快取大小,單位不太清楚,樓主猜測應該是個吧。當buffer超過10的時候,最舊的event將會被清除,並把新的event放進去。預設值為10。。非必須選項
;directory=/tmp                ; 程序執行前,會切換到這個目錄下執行預設為不切換。。。非必須
;umask=022                     ; 淹沒,預設為none,不說了
;priority=-1                   ; 啟動優先順序,預設-1,也不扯了
;autostart=true                ; 是否隨supervisord啟動一起啟動,預設true
;autorestart=unexpected        ; 是否自動重啟,和program一個樣,分true,false,unexpected等,注意unexpected和exitcodes的關係
;startsecs=1                   ; 也是一樣,程序啟動後跑了幾秒鐘,才被認定為成功啟動,預設1
;startretries=3                ; 失敗最大嘗試次數,預設3
;exitcodes=0,2                 ; 期望或者說預料中的程序退出碼,
;stopsignal=QUIT               ; 幹掉程序的訊號,預設為TERM,比如設定為QUIT,那麼如果QUIT來幹這個程序那麼會被認為是正常維護,退出碼也被認為是expected中的
;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                   ;設定普通使用者,可以用來管理該listener程序。預設為空。。非必須設定
;redirect_stderr=true          ; 為true的話,stderr的log會併入stdout的log裡面 預設為false。。。非必須設定
;stdout_logfile=/a/path        ; 這個不說了,好幾遍了
;stdout_logfile_maxbytes=1MB   ; 這個也是
;stdout_logfile_backups=10     ; 這個也是
;stdout_events_enabled=false   ; 這個其實是錯的,listener是不能傳送event
;stderr_logfile=/a/path        ; 這個也是
;stderr_logfile_maxbytes=1MB   ; 這個也是
;stderr_logfile_backups        ; 這個不說了
;stderr_events_enabled=false   ; 這個也是錯的,listener不能傳送event
;environment=A="1",B="2"       ; 這個是該子程序的環境變數 預設為空。。。非必須設定
;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分組,劃分到組裡面的program。我們就不用一個一個去操作了我們可以對組名進行統一的操作。 注意:program被劃分到組裡面之後,就相當於原來的配置從supervisor的配置檔案裡消失了。。。supervisor只會對組進行管理,而不再會對組裡面的單個program進行管理了
;programs=progname1,progname2  ; 組成員,用逗號分開這個是個必須的設定項
;priority=999                  ; 優先順序,相對於組和組之間說的預設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]                         ;這個東西挺有用的,當我們要管理的程序很多的時候,寫在一個檔案裡面就有點大了。我們可以把配置資訊寫到多個檔案中,然後include過來
;files = relative/directory/*.ini