Linux System restart Python program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.