欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

配置supervisor管理beego应用

程序员文章站 2022-05-11 14:42:58
Linux配置supervisor,用于管理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