项目作者: innovara

项目描述 :
monpid.py checks if a pid file exists; if the pid exists; and if the pid associated process is not a zoombie/defunct. It starts the script/process if any of these fail.
高级语言: Python
项目地址: git://github.com/innovara/monpid.git
创建时间: 2020-07-31T18:21:16Z
项目社区:https://github.com/innovara/monpid

开源协议:GNU General Public License v3.0

下载


monpid.py

Introduction

monpid.py checks if:

  • a pid file exists;
  • if the pid exists; and
  • if the pid associated process is not a zombie/defunct.

It starts the script/process if any of these fail.

How to use it

Use:

  1. ./monpid.py /path/to/script (or command) /path/to/pid_file

The script/process should write a pid file that nonpid.py can read.

See sleep.py for an example.

You can run monpid.py at regular intervals using cron.

Example:

  1. crontab -e
  1. * * * * * * /path/to/monpid.py /path/to/script (or command) /path/to/pid_file

Or you can edit monpid.py and change this:

  1. if __name__ == '__main__':
  2. main()

To this:

  1. if __name__ == '__main__':
  2. while True:
  3. main()
  4. sleep(60) #Number of seconds you want it to wait until it runs again.

And add from time import sleep at the beginning of the script with the rest of import lines.

Then want to possibly run it from the shell like this:

  1. ./monpid.py /path/to/script (or command) /path/to/pid_file &

The & at the end will send the process to the background where it will keep doing its thing.
Bear in mind that if you plan to use monpid.py for SysAdmin tasks, you most likely want to run monpid.py automatically instead.