Skip to content

Instantly share code, notes, and snippets.

@kasuganosora
Created December 9, 2013 13:13
Show Gist options
  • Save kasuganosora/7872090 to your computer and use it in GitHub Desktop.
Save kasuganosora/7872090 to your computer and use it in GitHub Desktop.
用来检查某个服务是否正常使用的py脚本,如果不正常的话就会杀掉重启
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