Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.