安装supervisor
python install supervisor
验证是否安装成功
supervisorctl -h

创建配置文件目录
mkdir /etv/supervisor
创建默认配置文件
echo_supervisord_conf > /etc/supervisord.conf
修改配置文件
vi /etc/supervisord.conf
#修改http服务器存储文件
[unix_http_server]
file=/var/run/supervisor.sock ; the path to the socket file
#修改log文件存储文件
[supervisord]
logfile=/var/run/supervisord.log ; main log file; default $CWD/supervisord.log
#修改sock服务器存储文件
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
#增加自定义文件
[include]
files = /etc/supervisor/*.conf

启动supervisord
supervisord -c /etc/supervisord.conf
查看启动状态
supervisorctl status

创建sp_demo.sh脚本
cd ~
mkdir /demo
cd /demo
vi sp_demo.sh
#!/bin/bash
while :
do
echo `date '+%Y-%m-%d %H:%m:%S'`
sleep 1
done
创建配置文件
cd /etc/supervisor/ #切换到配置文件目录
vi cabbage_test.conf #新建编辑配置文件,文件内容如下
[program:cabbage-test] #服务名称
directory=/www/cabbage-test #执行目录
command=sh /demo/sp_demo.sh #执行命令
autostart=true #自动开始
autorestart=true #自动重启
user=root #权限
environment=HOME="/root",USER="root" #环境变量
stderr_logfile=/var/log/cabbage-test.err.log #错误log
stdout_logfile=/var/log/cabbage-test.out.log #输出log
更新配置文件
supervisorctl update

查看当前状态
supervisorctl status

查看输出结果
tail -f /var/log/cabbage-test.out.log

停止进程
supervisorctl stop cabbage-test

