多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# supervision安装配置测试 ### 安装supervision ``` apt-get install supervisor ``` ### 主配置文件自动生成了 ``` [root@supervisor ~]# cat /etc/supervisor/supervisord.conf ; supervisor config file [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) ; the below section must remain in the config file for RPC ; (supervisorctl/web interface) to work, additional interfaces may be ; added by defining them in separate rpcinterface: sections [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 ``` ### 测试脚本 #### 每秒输出日期到日志里,杀掉进程然后查看时候会中断 ``` [root@supervisor ~]# cat scripts/echo_date.sh #!/bin/bash while true do echo $(date +%H:%M:%S) >> /tmp/echo_time.log sleep 1 done ``` ### 添加程序配置program.conf [root@supervisor conf.d]# cat program.conf ``` [program:echo_date_server] directory = /root/scripts ; 程序的启动目录 command = sh echo_date.sh ; 启动命令,可以看出与手动在命令行启动的命令是一样的 autostart = true ; 在 supervisord 启动的时候也自动启动 startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了 autorestart = true ; 程序异常退出后自动重启 startretries = 3 ; 启动失败自动重试次数,默认是 3 user = root ; 用哪个用户启动 redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB stdout_logfile_backups = 20 ; stdout 日志文件备份数 ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件) stdout_logfile = /tmp/echo_stdout.log ``` ### 启动服务 ``` systemctl start supervisor.service ``` ### 出错信息 ``` [root@supervisor ~]# supervisord -c /etc/supervisor/supervisord.conf Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord. For help, use /usr/bin/supervisord -h ``` 解决, 可能是用其他命令启动了supervisord进程,全部杀掉,然后用/init.d或者systemcl启动 ### 测试方法 启动supervisor 查看测试程序输出日志 查看测试程序的进程pid 杀掉正在运行的测试程序 观察输出日志是否会中断 如果没中断就表示supervisor重启生效了 如果中断了就表示配置没生效