1 #!/usr/bin/env python2 #Coding=utf-83 4 ImportSYS5 ImportConfigparser6 ImportUrllib7 ImportUrllib28 fromUtilImportHttp_server9 fromLoggerImportLoggerTen ImportJSON One ImportTraceback A Import Time - - Reload (SYS) theSys.setdefaultencoding ('Utf-8') - - ImportOS - ImportSignal + -Max_process = 2 +Log_index =0 A at #Start Python program - defstart (): - Globalmax_process - GlobalLog_index -Path = Os.popen ('pwd'). ReadLines () [0] - PrintPath'===' inOs.system ('nohup python serverdate.py &') -Time.sleep (10) to + #Stop Child - defstopchild (): theProcessInfo = Os.popen ("ps-ef|grep serverdate.py|grep-v Grep|awk ' {print $} '"). ReadLines () * PrintProcessInfo,'------' $ forPidinchProcessInfo:Panax Notoginseng os.kill (int (PID), signal. SIGKILL) - the #Stop Parent + defstopparent (): AParentlist = Os.popen ("ps-ef|grep serverdate.py|grep-v Grep|awk ' {print $} '"). ReadLines () the PrintParentlist,'***' + forPidinchparentlist: - os.kill (int (PID), signal. SIGKILL) $ $ defStopAll (): - Stopchild () - stopparent () the - Try:WuyiFun = Sys.argv[1] the exceptException: -Fun ="' Wu if(Fun = ='Start'): - Start () About if(Fun = ='Stop'): $ StopAll () - if(Fun = ='Restart'): - StopAll () -Time.sleep (10) AStart ()
How to use: Python serverdate.py start|stop|restart
Linux System restart Python program