其他分享
首页 > 其他分享> > debian 安装 supervisor

debian 安装 supervisor

作者:互联网

安装

apt-get update
apt-get install supervisor

主配置文件supervisord.conf

默认apt安装的主配置文件,位置是/etc/supervisor/supervisord.conf
默认个人自定义的子进程配置放到 /etc/supervisor/conf.d/下方
配置文件的默认查找顺序
supervisord -c /etc/supervisor/supervisord.conf 如果不指定 -c 参数,会通过如下顺序来搜索配置文件 */
$PWD/supervisord.conf
$PWD/etc/supervisord.conf
/etc/supervisord.conf
/etc/supervisor/supervisord.conf

cat << EOF > /etc/supervisor/supervisord.conf
[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)
[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

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf

;username 和 password 是后面 web ui 或者 http://172.21.6.89:9001/ 进行管理时要用的
;还有命令行操作时加了密码要先登录进去在交互界面里面输入命令 /usr/bin/supervisorctl -u admin -p admin    没密码时 可以 /usr/bin/supervisorctl -reload
[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9001        ; (ip_address:port specifier, *:port for all iface)
;//启动之后就可以浏览器打开了
;http://127.0.0.1:9001
username=admin              ; (default is no username (open server))
password=admin               ; (default is no password (open server))


测试案例

添加一个小程序

cat << EOF > /usr/local/test.sh
#!/bin/bash
while true
do
    echo $(date +%H:%M:%S) >> /tmp/echo_time.log
    sleep 1
done
EOF

添加自定义配置test.conf 到 /etc/supervisor/conf.d/下方

cat << EOF > /etc/supervisor/conf.d/test.conf
[program:test]
directory = /usr/local ; 程序的启动目录
command =  sh test.sh ; 启动命令,可以看出与手动在命令行启动的命令是一样的
autostart = true ; 在 supervisord 启动的时候也自动启动
startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了
autorestart = true ; 程序异常退出后自动重启
startretries = 3 ; 启动失败自动重试次数,默认是 3
user = root ; 用哪个用户启动
redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false
stdout_logfile_maxbytes = 200MB ; stdout 日志文件大小,默认 50MB
stdout_logfile_backups = 10 ; stdout日志文件备份数
; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录>(supervisord 会自动创建日志文件)
stdout_logfile = /tmp/echo_stdout.log

命令

//关闭supervisord
supervisorctl shutdown 

//验证安装是否成功
supervisorctl --help

//更新配置
supervisorctl update

//重新启动配置中的所有程序
supervisorctl reload 

使用普通用户启动

让非 root 用户可以使用 supervisor
通过修改 root账号安装的目录文件属性,让非root账号可以操作
关闭 supervisord
supervisorctl shutdown
修改权限
chown -R your-user:your-user /etc/supervisor
chown -R your-user:your-user /etc/supervisor/conf.d
chown -R your-user:your-user /var/log/supervisor

标签:supervisor,supervisord,supervisorctl,etc,conf,安装,debian,log
来源: https://www.cnblogs.com/faberbeta/p/16397764.html