Created
December 9, 2013 13:13
-
-
Save kasuganosora/7872090 to your computer and use it in GitHub Desktop.
用来检查某个服务是否正常使用的py脚本,如果不正常的话就会杀掉重启
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import threading | |
import os | |
import subprocess | |
def CheckService(): | |
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sk.settimeout(1) | |
try: | |
sk.connect(('xxx.xxx.xxx.xxx',0000)) | |
except Exception: | |
print "serive error" | |
global shadowocks | |
shadowocks.kill() | |
shadowocks = subprocess.Popen(["/home/xxx/xxx"]) | |
sk.close() | |
global t | |
t = threading.Timer(3.0,CheckService) | |
t.start() | |
shadowocks = subprocess.Popen(["/home/xxx/xxx"]) | |
t = threading.Timer(3.0,CheckService) | |
t.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment