Supervisor是一款用Python实现的进程管理工具,可用于在后台以Daemon模式运行进程,并能在异常时自动重启。例如可以用Supervisor管理Node、Nginx等。 apt-get install supervisor #安装 # 注意:用apt安装一般可以开机自启动,用pip安装则需要自己配置 配置应用 在/etc/supervisor/conf.d/文件夹下创建conf文件,一个文件对应一个应用。 cd /etc/supervisor/conf.d/ vim app.conf [program:app] # 应用的名字 command=/root/xxx # 执行的命令 directory=/root/ # 进程当前目录 user=root # 执行用户,可以是nobody priority=1 # 优先级 numprocs=1 # 启动的进程数目 autostart=true # 随supervisor同时启动 autorestart=true # 出错重启 常用操作 # 启动、停止、重启Service service supervisor stop service supervisor start service supervisor restart # 启动、停止、重启指定应用 supervisorctl stop app supervisorctl start app supervisorctl restart app # 启动、停止、重启groupworker分组的应用 supervisorctl stop groupworker supervisorctl start groupworker supervisorctl restart groupworker # 启动、停止、重启所有应用 supervisorctl stop all supervisorctl start all supervisorctl restart all # 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程。 supervisorctl reload # 根据最新的配置文件,启动新配置或有改动的进程,配置没改动的进程不重启 supervisorctl update # 注1:start、restart、stop都不会载入最新的配置文件 # 注2:显式用stop停止掉的进程,用reload或者update都不会自动重启 如果启动supervisor服务时出现以下错误,可输入sudo unlink /tmp/supervisor.sock,再尝试启动。 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. 参考文档: https://www.paincker.com/supervisor-usage/