Skip to content

Instantly share code, notes, and snippets.

@kkdai
Created December 4, 2014 10:24
Show Gist options
  • Save kkdai/f111e1ce03347fd137e4 to your computer and use it in GitHub Desktop.
Save kkdai/f111e1ce03347fd137e4 to your computer and use it in GitHub Desktop.
check jabberd2 if exist and relaunch it.
import time
import string
import sys
import commands
import time
import os
from threading import Thread
exitapp = False
def get_proc_id(process_name):
process_format = "ps aux | grep '%s'" % (process_name)
d = [i for i in commands.getoutput(process_format).split("\n") if 'grep' not in i.split()]
return (str(d[0].split()[0]), str(d[0].split()[1])) if d else None
def check_recover_process(process_name):
ps_proc = get_proc_id(process_name)
if ps_proc == None:
print ("[%s] %s%s%s" %(time.strftime("%m%d-%H:%m"), 'process ', process_name, ' not exist, launch new one....') )
recover_process(process_name)
else:
print ("[%s] %s %s" %(time.strftime("%m%d-%H:%m"), process_name, ' exist..........') )
def recover_process(process_name):
if 'sm' in process_name or 's2s' in process_name or 'c2s' in process_name :
print ("[%s] %s" %(time.strftime("%m%d-%H:%m"),'Recovery jabberd2 services') )
os.system('sudo service jabberd2 restart')
if __name__ == '__main__':
check_recover_process('sm')
check_recover_process('s2s')
check_recover_process('c2s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment