|
|
@ -25,6 +25,7 @@ import signal |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
import inspect |
|
|
|
|
|
|
|
file_path = os.path.dirname(os.path.realpath(inspect.getfile(inspect.currentframe()))) |
|
|
|
sys.path.insert(0, os.path.join(file_path, '../')) |
|
|
|
|
|
|
@ -43,7 +44,8 @@ def main(): |
|
|
|
|
|
|
|
try: |
|
|
|
import resource |
|
|
|
logging.info('current process RLIMIT_NOFILE resource: soft %d hard %d' % resource.getrlimit(resource.RLIMIT_NOFILE)) |
|
|
|
logging.info( |
|
|
|
'current process RLIMIT_NOFILE resource: soft %d hard %d' % resource.getrlimit(resource.RLIMIT_NOFILE)) |
|
|
|
except ImportError: |
|
|
|
pass |
|
|
|
|
|
|
@ -68,7 +70,7 @@ def main(): |
|
|
|
|
|
|
|
tcp_servers = [] |
|
|
|
udp_servers = [] |
|
|
|
dns_resolver = asyncdns.DNSResolver() |
|
|
|
dns_resolver = asyncdns.DNSResolver(config['black_hostname_list']) |
|
|
|
if int(config['workers']) > 1: |
|
|
|
stat_counter_dict = None |
|
|
|
else: |
|
|
@ -106,7 +108,8 @@ def main(): |
|
|
|
(protocol, password, method, obfs, obfs_param)) |
|
|
|
if 'server_ipv6' in a_config: |
|
|
|
try: |
|
|
|
if len(a_config['server_ipv6']) > 2 and a_config['server_ipv6'][0] == "[" and a_config['server_ipv6'][-1] == "]": |
|
|
|
if len(a_config['server_ipv6']) > 2 and a_config['server_ipv6'][0] == "[" and a_config['server_ipv6'][ |
|
|
|
-1] == "]": |
|
|
|
a_config['server_ipv6'] = a_config['server_ipv6'][1:-1] |
|
|
|
a_config['server_port'] = int(port) |
|
|
|
a_config['password'] = password |
|
|
@ -151,11 +154,13 @@ def main(): |
|
|
|
logging.warn('received SIGQUIT, doing graceful shutting down..') |
|
|
|
list(map(lambda s: s.close(next_tick=True), |
|
|
|
tcp_servers + udp_servers)) |
|
|
|
|
|
|
|
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), |
|
|
|
child_handler) |
|
|
|
|
|
|
|
def int_handler(signum, _): |
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, int_handler) |
|
|
|
|
|
|
|
try: |
|
|
@ -191,6 +196,7 @@ def main(): |
|
|
|
except OSError: # child may already exited |
|
|
|
pass |
|
|
|
sys.exit() |
|
|
|
|
|
|
|
signal.signal(signal.SIGTERM, handler) |
|
|
|
signal.signal(signal.SIGQUIT, handler) |
|
|
|
signal.signal(signal.SIGINT, handler) |
|
|
|