Skip to content

Instantly share code, notes, and snippets.

@wolfgangmeyers
Created April 21, 2017 16:22
Show Gist options
  • Save wolfgangmeyers/e06e86cb50ead2ecce853b218686b717 to your computer and use it in GitHub Desktop.
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.
#!/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