> [root@centos-011 ~ 07:50:00]#cat /etc/supervisord.conf.bak
```
; Sample supervisor config file.
[unix_http_server]
file=/var/run/supervisor/supervisor.sock ; socket 路徑
;chmod=0700 ; socket 文件的權限
;chown=nobody:nogroup ; socket 所屬用戶及組
;username=user ; 用戶名
;password=123 ; 密碼
;[inet_http_server] ; 是否啟用服務,默認是關閉的(啟用的話可以看到supervisor 管理的服務狀態)
;port=127.0.0.1:9001 ; 監聽的IP及端口
;username=user ; 用戶名
;password=123 ; 密碼
[supervisord] ; supervisord 全局配置
logfile=/var/log/supervisor/supervisord.log ; supervisor 日志路徑
logfile_maxbytes=50MB ; 單個日志文件最大數
logfile_backups=10 ; 保留多少個日志文件(默認10個)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; pid 文件路徑
nodaemon=false ; 啟動是否丟到前臺,設置為false ,表示以daemon 的方式啟動
minfds=1024 ; 最小文件打開數,對應系統limit.conf 中的nofile ,默認最小為1024,最大為4096
minprocs=200 ; 最小的進程打開數,對應系統的limit.conf 中的nproc,默認為200
;umask=022 ; (process file creation umask;default 022)
;user=chrism ; 啟動supervisord 服務的用戶,默認為root
;identifier=supervisor ; (supervisord identifier, default is 'supervisor')
;directory=/tmp ; 這里的目錄指的是服務的工作目錄
;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:///var/run/supervisor/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] ; 定義一個守護進程 ,比如下面的elasticsearch
;command=/bin/cat ; 啟動程序使用的命令,可以是絕對路徑或者相對路徑
;process_name=%(program_name)s ; 一個python字符串表達式,用來表示supervisor進程啟動的這個的名稱,默認值是%(program_name)s
;numprocs=1 ; Supervisor啟動這個程序的多個實例,如果numprocs>1,則process_name的表達式必須包含%(process_num)s,默認是1
;directory=/tmp ; supervisord在生成子進程的時候會切換到該目錄
;umask=022 ; umask for process (default None)
;priority=999 ; 權重,可以控制程序啟動和關閉時的順序,權重越低:越早啟動,越晚關閉。默認值是999
;autostart=true ; 如果設置為true,當supervisord啟動的時候,進程會自動啟動
;autorestart=true ; 設置為隨 supervisord 重啟而重啟,值可以是false、true、unexpected。false:進程不會自動重啟
;startsecs=10 ; 程序啟動后等待多長時間后才認為程序啟動成功,默認是10秒
;startretries=3 ; supervisord嘗試啟動一個程序時嘗試的次數。默認是3
;exitcodes=0,2 ; 一個預期的退出返回碼,默認是0,2。
;stopsignal=QUIT ; 當收到stop請求的時候,發送信號給程序,默認是TERM信號,也可以是 HUP, INT, QUIT, KILL, USR1, or USR2
;stopwaitsecs=10 ; 在操作系統給supervisord發送SIGCHILD信號時等待的時間
;user=chrism ; 如果supervisord以root運行,則會使用這個設置用戶啟動子程序
;redirect_stderr=true ; 如果設置為true,進程則會把標準錯誤輸出到supervisord后臺的標準輸出文件描述符
;stdout_logfile=/a/path ; 把進程的標準輸出寫入文件中,如果stdout_logfile沒有設置或者設置為AUTO,則supervisor會自動選擇一個文件位置
;stdout_logfile_maxbytes=1MB ; 標準輸出log文件達到多少后自動進行輪轉,單位是KB、MB、GB。如果設置為0則表示不限制日志文件大小
;stdout_logfile_backups=10 ; 標準輸出日志輪轉備份的數量,默認是10,如果設置為0,則不備份
;stdout_capture_maxbytes=1MB ; 當進程處于stderr capture mode模式的時候,寫入FIFO隊列的最大bytes值,單位可以是KB、MB、GB
;stdout_events_enabled=false ; 如果設置為true,當進程在寫它的stderr
;stderr_logfile=/a/path ; 把進程的錯誤日志輸出一個文件中,除非redirect_stderr參數被設置為true
;stderr_logfile_maxbytes=1MB ; 錯誤log文件達到多少后自動進行輪轉,單位是KB、MB、GB。如果設置為0則表示不限制日志文件大小
;stderr_logfile_backups=10 ; 錯誤日志輪轉備份的數量,默認是10,如果設置為0,則不備份
;stderr_capture_maxbytes=1MB ; 當進程處于stderr capture mode模式的時候,寫入FIFO隊列的最大bytes值,單位可以是KB、MB、GB
;stderr_events_enabled=false ; 如果設置為true,當進程在寫它的stderr到文件描述符的時候,PROCESS_LOG_STDERR事件會被觸發
;environment=A=1,B=2 ; 一個k/v對的list列表
;serverurl=AUTO ; 是否允許子進程和內部的HTTP服務通訊,如果設置為AUTO,supervisor會自動的構造一個url
; 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.
**這個地方是自定義一個守護進程**
[program:elasticsearch] ; 定義一個守護進程 elasticsearch
environment=ES_HOME=/usr/local/elasticsearch ; 設置ES_HOME 環境變量
user=elk ; 啟動elasticsearch 的用戶
directory=/usr/local/elasticsearch ; 進入到這個目錄中
command=/usr/local/elasticsearch/bin/elasticsearch ; 執行啟動命令
numprocs=1 ; Supervisor啟動這個程序的多個實例,如果numprocs>1,則process_name的表達式必須包含%(process_num)s,默認是1
autostart=true ; 設置為隨 supervisord 啟動而啟動
autorestart=true ; 設置為隨 supervisord 重啟而重啟
startretries=3 ; 設置elasticsearch 重啟的重試次數
priority=1 ; 權重,可以控制程序啟動和關閉時的順序,權重越低:越早啟動,越晚關閉。默認值是999
;[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)
;autorestart=unexpected ; restart at unexpected quit (default: unexpected)
;startsecs=10 ; number of secs prog must stay running (def. 1)
;startretries=3 ; max # of serial start failures (default 3)
;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
;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_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 ; # 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 ; 上面配置好的服務名,比如elasticsearch,kibana,logstash
;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 = supervisord.d/*.ini
```
**一般也可以將守護的進程配置定義守護進程放在/etc/supervisor/目錄下,以x.conf或者x.ini來命名**