主页

索引

模块索引

搜索页面

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; supervisor config file 
 2
 3[unix_http_server]
 4file=/var/run//supervisor.sock   ; (the path to the socket file)
 5chmod=0700                       ; sockef file mode (default 0700)
 6;chown=nobody:nogroup       ; socket file uid:gid owner
 7;username=user              ; (default is no username (open server))
 8;password=123               ; (default is no password (open server))
 9
10[inet_http_server]         ; inet (TCP) server disabled by default
11port=0.0.0.0:9001        ; (ip_address:port specifier, *:port for all iface)
12;username=admin              ; (default is no username (open server))
13;password=admin        ; (default is no password) e.x: {SHA}82ab876d1387bfafe46cc1c8a2ef074eae50cb1d
14
15
16[supervisord]
17logfile=/var/log/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log)
18logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
19logfile_backups=10          ; (num of main logfile rotation backups;default 10)
20loglevel=info               ; (log level;default info; others: debug,warn,trace)
21pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
22nodaemon=false              ; (start in foreground if true;default false)
23minfds=1024                 ; (min. avail startup file descriptors;default 1024)
24minprocs=200                ; (min. avail process descriptors;default 200)
25;umask=022                  ; (process file creation umask;default 022)
26;user=chrism                 ; (default is current user, required if root)
27;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
28;directory=/tmp              ; (default is not to cd during start)
29;nocleanup=true              ; (don`t clean up tempfiles at start;default false)
30;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
31;environment=KEY="value"       ; (key value pairs to add to environment)
32;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)
33
34; the below section must remain in the config file for RPC
35; (supervisorctl/web interface) to work, additional interfaces may be
36; added by defining them in separate rpcinterface: sections
37[rpcinterface:supervisor]
38supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
39
40[supervisorctl]
41serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
42;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
43;username=chris              ; should be same as http_username if set
44;password=123                ; should be same as http_password if set
45;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
46;history_file=~/.sc_history  ; use readline history if available
47
48
49[program:<x>]  ;;Section Settings
50command=/path/to/<command> <param>
51directory=/path/to/<appFolder>
52process_name=<procName>    ;; 进程名, 默认为: %(program_name)s
53numprocs=<procNum>         ;; 进程数, 默认为: 1. 如大于1, 则program_name中需要含%(process_num)s
54numprocs_start=    ;; An integer offset that is used to compute the number at which numprocs starts.
55
56autostart=true         ;; If true, this program will start automatically when supervisord is started.
57autorestart=true    ;; default: unexpected
58
59
60[program:cat]
61command=/bin/cat
62process_name=%(program_name)s
63numprocs=1
64directory=/tmp
65umask=022
66priority=999
67autostart=true
68autorestart=true
69startsecs=10
70startretries=3
71exitcodes=0,2
72stopsignal=TERM
73stopwaitsecs=10
74user=chrism
75redirect_stderr=false
76stdout_logfile=/a/path
77stdout_logfile_maxbytes=1MB
78stdout_logfile_backups=10
79stdout_capture_maxbytes=1MB
80stderr_logfile=/a/path
81stderr_logfile_maxbytes=1MB
82stderr_logfile_backups=10
83stderr_capture_maxbytes=1MB
84environment=A="1",B="2"
85serverurl=AUTO
86
87;; [include] Section Settings
88
89[include]
90files = /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

主页

索引

模块索引

搜索页面