Check the service status, which can be used for various types of Linux service processes
The code is as follows:
#!/bin/usr/pythonimport osimport subprocessimport platformimport timedef 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&NBsp; exit () except exception as e: print eif __name__ == ' __main__ ': if get_ostype () == ' Linux ': if get_linuxversion () >= 6: servicename = ' AUDITD ' restartservice (servicename) else: servicename = ' Auditd ' restartservice (servicename) else: print ' unknown Operation system '    &NBsp; exit ()
Restart the service process