ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

debian 安装 supervisor

2022-06-21 18:01:12  阅读:180  来源: 互联网

标签:supervisor supervisord supervisorctl etc conf 安装 debian log


安装

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有