Created
November 9, 2013 18:40
-
-
Save imankulov/7388415 to your computer and use it in GitHub Desktop.
Watchers. When something goes wrong, and only restart helps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import shlex | |
import subprocess | |
import time | |
def get_arguments(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-p', '--period', type=int, default=30) | |
parser.add_argument('checker') | |
parser.add_argument('action') | |
return parser.parse_args() | |
def check(arguments): | |
ret = subprocess.call(shlex.split(arguments.checker), stdout=None, stderr=None) | |
if ret != 0: | |
ret = subprocess.call(shlex.split(arguments.action)) | |
def main(): | |
arguments = get_arguments() | |
while True: | |
check(arguments) | |
time.sleep(arguments.period) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[program:watcher] | |
command = watcher.py 'curl --fail --silent http://service' 'sudo supervisorctl restart service_name' | |
autorestart = true | |
stdout_logfile = /var/log/supervisor/watcher.log | |
stderr_logfile = NONE | |
redirect_stderr = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment