标签:python 服务进程
检查服务状态,该脚本可用于各种类型linux的服务进程
代码如下:
#!/bin/usr/python import os import subprocess import platform import time def get_ostype(): return platform.system() def get_linuxversion(): return platform.platform().split(‘-‘)[6] def restartService(service): pidfile = ‘/var/run/%s.pid‘ %service if os.path.exists(pidfile): print ‘service %s is running‘ %service exit() try: subprocess.call([‘service‘,service,‘restart‘]) time.sleep(2) if os.path.exists(pidfile): print ‘service %s restart successfully‘ %service exit() except Exception as e: print e if __name__ == ‘__main__‘: if get_ostype() == ‘Linux‘: if get_linuxversion() >= 6: servicename = ‘auditd‘ restartService(servicename) else: servicename = ‘auditd‘ restartService(servicename) else: print ‘unknown operation system‘ exit()
标签:python 服务进程
原文地址:http://hifour.blog.51cto.com/2733096/1786943