一、golang、beego等環境安裝與配置
二、supervisor安裝
github專案地址:https://github.com/Supervisor/supervisor
克隆專案:git clone https://github.com/Supervisor/supervisor.git
進入專案:cd supervisor
安裝執行:python setup.py install
三、supervisor配置檔案
官方文件-配置部分
vi /etc/supervisord.conf
[supervisord]
http_port=/var/tmp/supervisor.sock ; (default is to run a UNIX domain socket server)
;http_port=127.0.0.1:9001 ; (alternately, ip_address:port specifies AF_INET)
;sockchmod=0700 ; AF_UNIX socketmode (AF_INET ignore, default 0700)
;sockchown=nobody.nogroup ; AF_UNIX socket uid.gid owner (AF_INET ignores)
;umask=022 ; (process file creation umask;default 022)
logfile=/var/log/supervisor/supervisord.log ; (supervisor輸出日誌,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 ; (logging level;default info; others: debug,warn)
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)
;nocleanup=true ; (don`t clean up tempfiles at start;default false)
;http_username=user ; (default is no username (open system))
;http_password=123 ; (default is no password (open system))
;childlogdir=/tmp ; (`AUTO` child log dir, default $TEMP)
;user=chrism ; (default is current user, required if root)
;directory=/tmp ; (default is not to cd during start)
;environment=KEY=value ; (key value pairs to add to environment)
[supervisorctl]
serverurl=unix:///var/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 http_username if set
;password=123 ; should be same as http_password if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
[unix_http_server]
file=/var/tmp/supervisor.sock ; (the path to the socket file)
;chmod=0777 ; socket file mode (default 0700)
;chown=root:root ; socket file uid:gid owner
;username=root ; (default is no username (open server))
;password=root ; (default is no password (open server))
[inet_http_server]
port = 127.0.0.1:9001
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:hello] ;可以在這邊配置要管理的程式
directory=/home/www/php/ ;
command=/usr/bin/php test.php ;
process_name=%(program_name)s ;
numprocs=1 ;
autostart=true ;
startsecs=1 ;
autorestart=true ;
startretries=3 ;
user=root ;
redirect_stderr=true ;
stdout_logfile_maxbytes=20MB ;
stdout_logfile_backups=10 ;
[include] ;也可以通過include包含進來程式配置檔案
files = ./supervisor/conf.d/*.ini ;
vi /etc/supervisor/conf.d/wx-prj.ini
[program:wx-prj]
;directory=/home/www/go/src/wx-prj ;go專案目錄
;command=/home/www/go/src/wx-prj/wx-prj ;go專案編譯好的可執行檔案
directory=/home/www/go/bin ;
command=/home/www/go/bin/wx-prj ;
process_name=%(program_name)s ;
numprocs=1 ;
autostart=true ;
startsecs=1 ;
autorestart=true ;
startretries=3 ;
user=root ;
redirect_stderr=true ;
stdout_logfile=/home/www/go/wx-prj.stdout.log ;列印標準輸出日誌
stdout_logfile_maxbytes=20MB ;
stdout_logfile_backups=10 ;
stderr_logfile=/home/www/go/wx-prj.stderr.log ;列印標準錯誤輸出日誌
stderr_logfile_maxbytes=20MB ;
stderr_logfile_backups=10 ;
log_stdout=true ; if true, log program stdout (default true)
log_stderr=true ; if true, log program stderr (def false)
四、啟動supervisor服務
supervisord -c /etc/supervisord.conf
啟動服務時可以跟蹤日誌輸出觀察
[root@10-23-67-69 go]# tail -f /var/log/supervisor/supervisord.log
2018-10-26 13:36:30,881 INFO Included extra file "/etc/./supervisor/conf.d/wx-prj.ini" during parsing
2018-10-26 13:36:30,902 INFO RPC interface `supervisor` initialized
2018-10-26 13:36:30,902 CRIT Server `inet_http_server` running without any HTTP authentication checking
2018-10-26 13:36:31,203 INFO RPC interface `supervisor` initialized
2018-10-26 13:36:31,203 CRIT Server `unix_http_server` running without any HTTP authentication checking
2018-10-26 13:36:31,206 INFO daemonizing the supervisord process
2018-10-26 13:36:31,207 INFO supervisord started with pid 17040
2018-10-26 13:36:32,209 INFO spawned: `hello` with pid 17041
2018-10-26 13:36:32,213 INFO spawned: `wx-prj` with pid 17042
2018-10-26 13:36:32,219 INFO spawned: `world` with pid 17043
2018-10-26 13:36:33,279 INFO success: hello entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-10-26 13:36:33,279 INFO success: wx-prj entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-10-26 13:36:33,279 INFO success: world entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
也通過命令檢視程式狀態
[root@10-23-67-69 conf.d]# supervisorctl status
hello RUNNING pid 17041, uptime 0:00:19
world RUNNING pid 17043, uptime 0:00:19
wx-prj RUNNING pid 17042, uptime 0:00:19
五、過載supervisor修改過的配置
supervisorctl reload
六、停止/啟動/重啟supervisor管理的程式
[root@10-23-67-69 conf.d]# supervisorctl stop wx-prj
wx-prj: stopped
[root@10-23-67-69 conf.d]# supervisorctl start wx-prj
wx-prj: started
[root@10-23-67-69 conf.d]# supervisorctl restart wx-prj
wx-prj: stopped
wx-prj: started
[root@10-23-67-69 conf.d]# supervisorctl stop all
hello: stopped
wx-prj: stopped
world: stopped
[root@10-23-67-69 conf.d]# supervisorctl start all
hello: started
wx-prj: started
world: started