1、安装及启动
sudo apt-get install supervisor
/etc/init.d/supervisor start
2、配置、reload配置
sudo vim /etc/supervisor/supervisord.conf
sudo supervisorctl reload
/etc/init.d/supervisor restart
simon@ubuntu:~/testpid$ sudo supervisorctl status
[sudo] password for simon:
testpid STOPPED Jun 07 02:21 PM
simon@ubuntu:~/testpid$
3、supervisorctl
supervisorctl reload :修改完配置文件后重新启动
supervisor supervisorctl status :查看supervisor
监管的进程状态 supervisorctl start 进程名 :启动XXX进程
supervisorctl stop 进程名 :停止XXX进程
supervisorctl stop all:停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
supervisorctl update:根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启
具体配置
1 ; supervisor config file
2
3 [unix_http_server]
4 file=/var/run/supervisor.sock ; (the path to the socket file)
5 chmod=0700 ; sockef file mode (default 0700)
6
7 [supervisord]
8 logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/su pervisord.log)
9 pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord. pid)
10 childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
11
12 ; the below section must remain in the config file for RPC
13 ; (supervisorctl/web interface) to work, additional interfaces may be
14 ; added by defining them in separate rpcinterface: sections
15 [rpcinterface:supervisor]
16 supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinter face
17
18 [supervisorctl]
19 serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix so cket
20
21 ; The [include] section can just contain the "files" setting. This
22 ; setting can list multiple files (separated by whitespace or
23 ; newlines). It can also contain wildcards. The filenames are
24 ; interpreted as relative to this file. Included files *cannot*
25 ; include files themselves.
26
27 [include]
28 files = /etc/supervisor/conf.d/*.conf
29
30 [inet_http_server]
31 port=127.0.0.1:9001
32 username=123
33 password=123
34
35 [program:testpid]
36 command=bash start.sh
37 numprocs=1
38 directory=/usr/local/bin
39 autorestart=true
40 redirect_stderr=true
41 stdout_file=/var/log/supervisord/testpid.log ;需要手动创建目录
42 loglevel=info
43 user=ubuntu ; 用哪个用户启动
44 stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB
45 stdout_logfile_backups = 2 ; stdout 日志文件备份数
web页面
进程杀掉后会自动重启(配置里面需配置)