1、安装
Pip 安装:pip install supervisor
yum 安装:yum install supervisor
apt 安装:apt-get install supervisor
2、简单管理
[root@localhost ~]# echo_supervisord_conf > /etc/supervisord.d/supervisord.conf //生成配置文件
[root@localhost ~]# cat /etc/supervisord.conf //默认配置文件路径
[root@localhost ~]# supervisord //使用默认配置文件启动supervisor服务
[root@localhost ~]# supervisord -c /etc/supervisord.d/supervisord.conf //指定配置文件启动supervisor服务
配置文件示例
[unix_http_server] file=/var/run/supervisor/supervisor.sock [inet_http_server] port=*:9001 username=user password=123 [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///var/run/supervisor/supervisor.sock ;serverurl=http://127.0.0.1:9001 ;username=user ;password=123 [supervisord] logfile=/tmp/supervisord.log logfile_maxbytes=50MB logfile_backups=10 loglevel=info pidfile=/tmp/supervisord.pid nodaemon=false minfds=1024 minprocs=200 [program:theprogramname] command=/bin/cat ; the program (relative uses PATH, can take args) process_name=%(program_name)s ; process_name expr (default %(program_name)s) numprocs=1 ; number of processes copies to start (def 1) directory=/tmp ; directory to cwd to before exec (def no cwd) umask=022 ; umask for process (default None) priority=999 ; the relative start priority (default 999) autostart=true ; start at supervisord start (default: true) autorestart=true ; retstart at unexpected quit (default: true)
3、supervisorctl命令说明
[root@localhost ~]# supervisorctl status //查看所有进程的状态
[root@localhost ~]# supervisorctl stop theprogramname //停止theprogramname
[root@localhost ~]# supervisorctl start theprogramname //启动theprogramname
[root@localhost ~]# supervisorctl restart theprogramname //重启theprogramname
[root@localhost ~]# supervisorctl update //更新新的配置到supervisord(不会重启原来已运行的程序)
[root@localhost ~]# supervisorctl reload //载入所有配置文件,并按新的配置启动、管理所有进程(会重启原来已运行的程序)
注:直接输入supervisorctl进入supervisorctl的shell交互界面,此时上面的命令不带supervisorctl可直接使用
4、supervisor服务管理脚本
[root@localhost ~]# cat /usr/lib/systemd/system/supervisord.service
[Unit] Description=Process Monitoring and Control Daemon After=rc-local.service nss-user-lookup.target [Service] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf ExecStop=/usr/bin/supervisorctl shutdown ExecReload=/usr/bin/supervisorctl reload killMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target
参考链接:
https://www.cnblogs.com/xuezhigu/p/7660203.html
http://supervisord.org/configuration.html