supervisor命令

文档地址: http://supervisord.org/

命令:

supervisorctl help      // 帮助信息

supervisorctl reload    // 重启服务
supervisorctl update    // 更新配置文件



supervisorctl start app
supervisorctl stop app

安装:

easy_install supervisor
apt-get install supervisor
yum install supervisor

supervisord 命令行参数:

-c <file>, --configuration=<file>    指定配置文件
-n, --nodaemon     Run supervisord in the foreground
-u <user>, --user=<user>
-d <path>, --directory=<path>   指定运行目录

supervisorctl 命令行参数:

-c, --configuration     // Configuration file path (default /etc/supervisord.conf)
-s, --serverurl URL     // URL on which supervisord server is listening (default “http://localhost:9001”).
-u, --username          //Username to use for authentication with server
-p, --password          //Password to use for authentication with server

配置文件 -c 指定配置文件,否则:

$CWD/supervisord.conf
$CWD/etc/supervisord.conf
/etc/supervisord.conf

每个进程的配置文件都可以单独分拆,放在 /etc/supervisor/conf.d/ 目录下,以 .conf 作为扩展名,以 app.conf 为例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
; supervisor config file 

[unix_http_server]
file=/var/run//supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef 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=0.0.0.0:9001        ; (ip_address:port specifier, *:port for all iface)
;username=admin              ; (default is no username (open server))
;password=admin        ; (default is no password) e.x: {SHA}82ab876d1387bfafe46cc1c8a2ef074eae50cb1d


[supervisord]
logfile=/var/log/supervisord/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=/var/run/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:///var/run/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


[program:<x>]  ;;Section Settings
command=/path/to/<command> <param>
directory=/path/to/<appFolder>
process_name=<procName>    ;; 进程名, 默认为: %(program_name)s
numprocs=<procNum>         ;; 进程数, 默认为: 1. 如大于1, 则program_name中需要含%(process_num)s
numprocs_start=    ;; An integer offset that is used to compute the number at which numprocs starts.

autostart=true         ;; If true, this program will start automatically when supervisord is started.
autorestart=true    ;; default: unexpected


[program:cat]
command=/bin/cat
process_name=%(program_name)s
numprocs=1
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=10
user=chrism
redirect_stderr=false
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment=A="1",B="2"
serverurl=AUTO

;; [include] Section Settings

[include]
files = /an/absolute/filename.conf /an/absolute/*.conf foo.conf config??.conf

如果要在命令行中使用变量,就需要自己先编写一个shell脚本:

#!/bin/sh
/usr/bin/gunicorn -w `grep -c ^processor /proc/cpuinfo` wsgiapp:application