Created
April 21, 2017 16:22
-
-
Save wolfgangmeyers/e06e86cb50ead2ecce853b218686b717 to your computer and use it in GitHub Desktop.
Dead simple process watcher in python. Restarts a process if and only if it dies with a non-zero exit code. Shuts down if process exits with zero.
This file contains 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 sys | |
import os | |
# Dead simple process watcher in python. | |
# Restarts a process if and only if it dies with a non-zero exit code. | |
# Shuts down if process exits with zero. | |
if __name__ == "__main__": | |
if len(sys.argv) == 1: | |
print "Usage: watcher.py <program> <args>" | |
else: | |
result = os.system(" ".join(sys.argv[1:])) | |
while result != 0: | |
print "Bootstrap restarting process!" | |
result = os.system(" ".join(sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment