Created
October 13, 2015 19:08
-
-
Save axpence/8de6681111674c364fb7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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) | |
| proc_four = subprocess.Popen('cd /root/yowsup-queue/ && python3 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