Created
November 24, 2013 04:18
-
-
Save kasuganosora/7623280 to your computer and use it in GitHub Desktop.
Shadowsocks Watchdog 监视Shadowsocks是否正常运行 如果不正常的话就 杀掉原来的进程重新启动Shadowsocks
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 | |
Port = 123 #Shadowsocks 的端口 | |
ShadowsocksPath = "/home/ss" #Shadowsocks 的路径 | |
def CheckService(): | |
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sk.settimeout(1) | |
global Port | |
global ShadowsocksPath | |
try: | |
sk.connect(('127.0.0.1',Port)) | |
except Exception: | |
print "serive error" | |
global shadowsocks | |
shadowsocks.kill() | |
shadowsocks = subprocess.Popen([ShadowsocksPath]) | |
sk.close() | |
global t | |
t = threading.Timer(3.0,CheckService) | |
t.start() | |
shadowsocks = subprocess.Popen([ShadowsocksPath]) | |
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