小工具之进程守护器

时间:2017-01-19 03:48:30   收藏:0   阅读:382

操作系统: CentOS 6.5_x64
开发语言: Python

适用场景:
程序异常退出后需要及时启动的情况。

源码地址: https://github.com/mike-zhang/processGuarder

原理

通过ps检查进程是否存在,如果不存在则启动

使用

./processGuarder.py default.xml

参数配置

全局参数配置

程序参数配置

配置示例

普通程序配置(example):

<program scriptName = "">
    <processName>proName</processName>
    <command>/path/to/pro</command>
    <param>params</param>
    <restartDelay>1</restartDelay>seconds
</program>

脚本程序配置(example):

<program scriptName="python" >
    <processName>script.py</processName>
    <command>/path/to/script.py</command>
    <param>params</param>
    <restartDelay>1</restartDelay>seconds
</program>

其它

1、进程守护器前台运行还是后台运行?
答 : 进程守护器启动时会通过fork方式生成守护进程,在后台运行。

2、如果进程守护器程序本身退出了怎么办?
答 : 可以在crontab中配置定时启动进程守护器,如果守护器已经启动,会自动退出,不会启动多份;如果进程守护器没有启动,则正常启动,并根据提供的配置进行程序检测。

本文github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2017/20170118_小工具之进程守护器.md

欢迎补充  

原文:http://www.cnblogs.com/MikeZhang/p/6298465.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!