python 判断进程是否存在并重启

#!/usr/bin/env python3
import os
import time



def isRunning(process_name):
    try:
        process = len(os.popen('ps aux | grep "' + process_name + '" | grep -v grep | grep -v tail | grep -v keepH5ssAlive').readlines())
        if process >= 1:
            
            return True
        else:
            return False
    except:
        print("Check process ERROR!!!")
        return False

is_h5ss_running = isRunning('h5s-r8.0.0317.19-CentOS-7.4.1708-64bit')
is_start_h5ss_py_running = isRunning('start_h5ss')

if is_start_h5ss_py_running == False and is_h5ss_running == False:
    f = open('/home/fsu/h5s-r8.0.0317.19-CentOS-7.4.1708-64bit/start_h5ss.log', 'a')
    f.write('['+ str(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())) + '] no h5ss service,start it!\n')
    f.close()
    time.sleep(60)
    os.system('/home/fsu/h5s-r8.0.0317.19-CentOS-7.4.1708-64bit/start_h5ss.sh')

猜你喜欢

转载自blog.csdn.net/wangbin0705030219/article/details/91491062
今日推荐