Linux系统重启python程序,, 1 #! /usr


 1 #! /usr/bin/env python 2 #coding=utf-8 3  4 import sys 5 import ConfigParser 6 import urllib 7 import urllib2 8 from util import http_server 9 from logger import logger10 import json11 import traceback12 import time13 14 reload(sys)15 sys.setdefaultencoding(‘utf-8‘)16 17 import os18 import signal19 20 Max_process = 221 log_index = 022 23 # start python program24 def start():25     global Max_process26     global log_index27     path = os.popen(‘pwd‘).readlines()[0]28     print path,‘===‘29     os.system(‘nohup python serverdate.py &‘)30     time.sleep(10)31 32 #stop child33 def stopChild():34     processInfo = os.popen("ps -ef|grep serverdate.py|grep -v grep|awk ‘{print $2}‘").readlines()35     print processInfo,‘------‘36     for pid in processInfo:37         os.kill(int(pid),signal.SIGKILL)38 39 #stop parent40 def stopParent():41     parentList = os.popen("ps -ef|grep serverdate.py|grep -v grep|awk ‘{print $2}‘").readlines()42     print parentList,‘***‘43     for pid in parentList:44         os.kill(int(pid),signal.SIGKILL)45 46 def stopAll():47     stopChild()48     stopParent()49 50 try:51     fun = sys.argv[1]52 except Exception:53     fun = ‘‘54 if(fun == ‘start‘):55     start()56 if(fun == ‘stop‘):57     stopAll()58 if(fun == ‘restart‘):59     stopAll()60     time.sleep(10)61     start()

使用方法:python serverdate.py start|stop|restart

Linux系统重启python程序

相关内容

    暂无相关文章

评论关闭