Chris Matthews | 4d39f84 | 2017-08-17 20:26:33 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | Kill all the Zombie Gunicon processes. |
| 4 | |
| 5 | """ |
| 6 | import re |
| 7 | import subprocess |
| 8 | |
| 9 | out = subprocess.check_output(["ps", "auxxxf"]) |
| 10 | |
| 11 | stranded = re.compile(r"^lnt\s+(?P<pid>\d+).*00\sgunicorn:\swork") |
| 12 | pids = [] |
| 13 | for line in out.split('\n'): |
| 14 | m = stranded.match(line) |
| 15 | if m: |
| 16 | pid = m.groupdict()['pid'] |
| 17 | pids.append(pid) |
| 18 | else: |
| 19 | print ">", line |
| 20 | |
| 21 | if not pids: |
| 22 | print "No PIDs to kill." |
| 23 | |
| 24 | for pid in pids: |
| 25 | print subprocess.check_output(["kill", "-9", "{}".format(pid)]) |