forked from Ehco1996/aioshadowsocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
38 lines (28 loc) · 1.03 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import logging
import asyncio
from shadowsocks.server_pool import ServerPool
from shadowsocks.logger import init_logger_config
from shadowsocks.config_reader.json_reader import json_config_reader
def run_servers(configs):
async def async_user_task(pool):
pool.async_user()
loop = asyncio.get_event_loop()
pool = ServerPool()
asyncio.ensure_future(pool.async_user_config(configs))
asyncio.ensure_future(async_user_task(pool))
try:
loop.run_forever()
except KeyboardInterrupt:
logging.info('正在关闭所有ss server')
for data in pool.user_handlers.values():
user = data['user']
servers = data['handlers']
logging.info('正在关闭user_id: {} 的连接'.format(user.user_id))
for server in servers:
server.close()
loop.stop()
if __name__ == "__main__":
init_logger_config(log_level="info")
path = os.path.join(os.getcwd(), 'defualtconfig.json').encode()
run_servers(json_config_reader(path))