Browse Source

detect thread status

add API params
dev
BreakWa11 9 years ago
parent
commit
91576d1e08
  1. 16
      Config.py
  2. 14
      db_transfer.py
  3. 4
      server.py
  4. 4
      server_pool.py
  5. 4
      shadowsocks/tcprelay.py

16
Config.py

@ -1,12 +1,24 @@
#Config
# Config
TRANSFER_MUL = 1.0
API_INTERFACE = 'mysql'
# Mysql
MYSQL_HOST = 'mdss.mengsky.net'
MYSQL_PORT = 3306
MYSQL_USER = 'ss'
MYSQL_PASS = 'ss'
MYSQL_DB = 'shadowsocks'
MYSQL_TRANSFER_MUL = 1.0
MYSQL_UPDATE_TIME = 60
# API
API_URL = 'breakwa11.org'
API_PORT = 80
API_PATH = '/mu/v2/'
API_TOKEN = 'abcdef'
API_NODE_ID = 'id001'
API_UPDATE_TIME = 60
# Manager (ignore this)
MANAGE_PASS = 'ss233333333'
#if you want manage in other server you should set this value to global ip
MANAGE_BIND_IP = '127.0.0.1'

14
db_transfer.py

@ -39,16 +39,16 @@ class DbTransfer(object):
continue
elif last_transfer[id][0] <= curr_transfer[id][0] and \
last_transfer[id][1] <= curr_transfer[id][1]:
dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * Config.MYSQL_TRANSFER_MUL),
int((curr_transfer[id][1] - last_transfer[id][1]) * Config.MYSQL_TRANSFER_MUL)]
dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * Config.TRANSFER_MUL),
int((curr_transfer[id][1] - last_transfer[id][1]) * Config.TRANSFER_MUL)]
else:
dt_transfer[id] = [int(curr_transfer[id][0] * Config.MYSQL_TRANSFER_MUL),
int(curr_transfer[id][1] * Config.MYSQL_TRANSFER_MUL)]
dt_transfer[id] = [int(curr_transfer[id][0] * Config.TRANSFER_MUL),
int(curr_transfer[id][1] * Config.TRANSFER_MUL)]
else:
if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
continue
dt_transfer[id] = [int(curr_transfer[id][0] * Config.MYSQL_TRANSFER_MUL),
int(curr_transfer[id][1] * Config.MYSQL_TRANSFER_MUL)]
dt_transfer[id] = [int(curr_transfer[id][0] * Config.TRANSFER_MUL),
int(curr_transfer[id][1] * Config.TRANSFER_MUL)]
query_head = 'UPDATE user'
query_sub_when = ''
@ -190,7 +190,7 @@ class DbTransfer(object):
trace = traceback.format_exc()
logging.error(trace)
#logging.warn('db thread except:%s' % e)
if DbTransfer.get_instance().event.wait(Config.MYSQL_UPDATE_TIME):
if DbTransfer.get_instance().event.wait(Config.MYSQL_UPDATE_TIME) or not ServerPool.get_instance().thread.is_alive():
break
except KeyboardInterrupt as e:
pass

4
server.py

@ -50,8 +50,8 @@ def main():
thread = MainThread()
thread.start()
try:
while True:
time.sleep(99999)
while thread.is_alive():
time.sleep(10)
except (KeyboardInterrupt, IOError, OSError) as e:
import traceback
traceback.print_exc()

4
server_pool.py

@ -64,8 +64,8 @@ class ServerPool(object):
self.stat_counter = {}
self.loop = eventloop.EventLoop()
thread = MainThread( (self.loop, self.dns_resolver, self.mgr) )
thread.start()
self.thread = MainThread( (self.loop, self.dns_resolver, self.mgr) )
self.thread.start()
@staticmethod
def get_instance():

4
shadowsocks/tcprelay.py

@ -170,7 +170,7 @@ class TCPRelayHandler(object):
self.last_activity = 0
self._update_activity()
self._server.add_connection(1)
self._server.stat_add(common.to_str(self._client_address[0]), 1)
self._server.stat_add(self._client_address[0], 1)
def __hash__(self):
# default __hash__ is id / 16
@ -878,7 +878,7 @@ class TCPRelayHandler(object):
self._dns_resolver.remove_callback(self._handle_dns_resolved)
self._server.remove_handler(self)
self._server.add_connection(-1)
self._server.stat_add(common.to_str(self._client_address[0]), -1)
self._server.stat_add(self._client_address[0], -1)
class TCPRelay(object):
def __init__(self, config, dns_resolver, is_local, stat_callback=None, stat_counter=None):

Loading…
Cancel
Save