-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/python3 | ||
|
||
""" | ||
dashboard/app.rb sometimes gets jammed up and hangs forever; | ||
this utility kills it when it's unresponsive. The restart is left up | ||
to the for loop in your shell or your init system. | ||
Usage: | ||
./killer.py DASHBOARD_URL | ||
If DASHBOARD_URL is not specified, http://127.0.0.1:4567/ will be used. | ||
""" | ||
|
||
import os | ||
import sys | ||
import time | ||
import subprocess | ||
import urllib.request as request | ||
|
||
def kill_dashboard(): | ||
print("\nKilling dashboard") | ||
try: | ||
pids = list(map(int, subprocess.check_output(["pgrep", "-f", "^ruby.*dashboard/app.rb"]).strip().split())) | ||
except KeyboardInterrupt: | ||
raise | ||
except: | ||
pids = [] | ||
if len(pids) == 1: | ||
os.system('kill -9 %s' % (pids[0],)) | ||
else: | ||
print("\nDid not kill, there were 0 or > 1 dashboard PIDs: %r" % (pids,)) | ||
|
||
def main(): | ||
try: | ||
url = sys.argv[1] | ||
except IndexError: | ||
url = "http://127.0.0.1:4567/" | ||
while True: | ||
try: | ||
r = request.urlopen(url, timeout=10) | ||
except KeyboardInterrupt: | ||
raise | ||
except: | ||
body = "" | ||
else: | ||
body = r.read().decode("latin-1") | ||
print(".", end=" ") | ||
sys.stdout.flush() | ||
if not body or "</body>" not in body: | ||
kill_dashboard() | ||
time.sleep(30) | ||
|
||
if __name__ == '__main__': | ||
main() |