当前位置:   article > 正文

Linux系统重启python程序

python重启linux系统
 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 logger
10 import json
11 import traceback
12 import time
13 
14 reload(sys)
15 sys.setdefaultencoding('utf-8')
16 
17 import os
18 import signal
19 
20 Max_process = 2
21 log_index = 0
22 
23 # start python program
24 def start():
25     global Max_process
26     global log_index
27     path = os.popen('pwd').readlines()[0]
28     print path,'==='
29     os.system('nohup python serverdate.py &')
30     time.sleep(10)
31 
32 #stop child
33 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 parent
40 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

转载于:https://www.cnblogs.com/tsw123/p/5655356.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/72303
推荐阅读
相关标签
  

闽ICP备14008679号