Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-Watchdog

A simple watchdog that keeps an eye on your scripts so start/stop/restart them automatically based on your configuration

Futures

  • Keep an eye on your scripts start/stop/restart them automatically if necessary
  • Dont block your main script
  • You can start more then one watchdog parallel
  • Easy implementation and configuration
  • Clean exit over the main process so nor more wild running uboat scripts

Requirements

A linux system and following common python libraries are used: configparser, threading, subprocess, time, os

Example

Just copy all the files in a folder and run example.py to play around.
The example.py will start a watchdog based on watchdog.ini (Start test1.py ans test2.py)
test2.py will run in an error after 20sec and trigger a restart.

Important

The main process (your main script where you start the watchdog) has to run all the time. (infinite loop)
If the main process stops also all the scripts startet with the watchdog will get stoped !
This is intentional behavior to keep the processes clean. It is better to cleanly restart the main process and so all watchdog processes (scripts) than to have unmanaged processes running.

Keep in mind when you set a stop flag to 1 you should set the start flag to 0

Usage

Place the python_watchdog.py in the same directory as your main script.
Create a .ini file for your scripts in the same directory (for example see watchdog.ini)

Define the flags for you scripts in the ini file:
Start = Script should be started
Stop = Script should be stoped
Restart = Script should be restarted if it stops or run in an error

Import the watchdog in your script with:

from python_watchdog import *

You can start a watchdog in your script with:

start_watchdog('your_ini_file.ini')

If you want to run more then one watchdog you can do this with multiple ini files

start_watchdog('your_ini_file2.ini')

If you want to change a flag in a ini file by script (in this example the restart flag from script1 to zero):

watchdog_update('yourfile.ini', 'restart1', 0)

You can set the time how often the script will check for ini file updates in the python_watchdog.py file standard is 5sec.
Change the following in python_watchdog.py :

check_interval = 5

About

A simple watchdog that keeps an eye on your scripts so start/stop/restart them automatically based on your configuration

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages