python自己重启自己程序_Supervisor 让崩溃的程序自动重启

Supervisor 介绍

Supervisor 是一个用 Python 写的进程管理工具,可以很方便的用来启动、重启、关闭进程(不仅仅是 Python 进程)。除了对单个进程的控制,还可以同时启动、关闭多个进程,比如很不幸的服务器由于某种原因暂时 kill 掉你的应用,此时可以用 Supervisor 让你的应用自动重启,如果是多个应用被杀死,也省去了手动一个一个地敲命令重新启动。

安装

目前 Supervisor 只能运行在 Unix-Like 的系统上,无法运行在 Windows 上。Supervisor 官方版目前只能运行在 Python 2.4 以上版本,但是还无法运行在 Python 3 上。执行下面代码前,需要安装 pip:

pip install supervisor

安装完成后,可以使用两个命令,分别是 supervisord 和 supervisorctl,如果你的系统里有两个版本的 Python,且默认的 python 命令版本是 Python 3,此时运行会出错,解决方式是修改两个命令使用的 Python 版本。使用 which 命令找到两个命令的文件地址,然后编辑文件并指定 Python 版本:

修改 Python 版本

编辑配置文件

将下面内容保存到 /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)

; the below section must remain in the config file for RPC

; (supervisorctl/web interface) to work, additional interfaces may be

; ad

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值