Skip to content

Instantly share code, notes, and snippets.

@axpence
Last active October 12, 2015 07:57
Show Gist options
  • Select an option

  • Save axpence/4000130bf5faeed0c73e to your computer and use it in GitHub Desktop.

Select an option

Save axpence/4000130bf5faeed0c73e to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import os
import signal
import subprocess
import time
import psutil
# The os.setsid() is passed in the argument preexec_fn so
# it's run after the fork() and before exec() to run the shell.
def kill_this_thing(proc_pid):
process = psutil.Process(proc_pid)
for proc in process.get_children(recursive=True):
proc.kill()
process.kill()
proc_one = None
proc_two = None
proc_three = None
proc_four = None
proc_five = None
try:
proc_one = subprocess.Popen('cd /root/flask_only_app && gunicorn --bind 0.0.0.0:5000 wsgi'.split(),shell=True)
time.sleep(2)
proc_two = subprocess.Popen('beanstalkd -l 127.0.0.1 -p 11301'.split(),shell=True)
time.sleep(2)
proc_three = subprocess.call('rm -f -r /root/.yowsup/'.split(),shell=True)
# proc_three = subprocess.Popen('mv /root/.yowsup/ /root/TEMP/'.split(),shell=True)
time.sleep(2)
proc_four = subprocess.Popen('/usr/bin/python3 /root/yowsup-queue/run.py​'.split(),shell=True)
try:
proc_four.wait(timeout=10)
except subprocess.TimeoutExpired:
kill_this_thing(proc_four.pid)
proc_five = subprocess.Popen('/usr/bin/python3 /root/yowsup-queue/run.py​'.split(),shell=True)
except Exception as e:
print('$$$$$$$$$$Exception e -> Notify myself here.')
except:
print('$$$$$$$$$$General except -> send myself email here...')
kill_this_thing(proc_four.pid)
kill_this_thing(proc_one.pid)
kill_this_thing(proc_two.pid)
kill_this_thing(proc_three.pid)
kill_this_thing(proc_five.pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment