From fdb3a36170031117e17518e5ee2515221472e5e0 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Fri, 12 Sep 2014 20:47:04 +0800 Subject: [PATCH] implement graceful shutdown in sslocal; close #179 --- shadowsocks/local.py | 7 +++++++ shadowsocks/server.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/shadowsocks/local.py b/shadowsocks/local.py index 0a00136..e480b58 100755 --- a/shadowsocks/local.py +++ b/shadowsocks/local.py @@ -24,6 +24,7 @@ import sys import os import logging +import signal import utils import encrypt import eventloop @@ -58,6 +59,12 @@ def main(): dns_resolver.add_to_loop(loop) tcp_server.add_to_loop(loop) udp_server.add_to_loop(loop) + + def handler(signum, _): + logging.warn('received SIGQUIT, doing graceful shutting down..') + tcp_server.close(next_tick=True) + udp_server.close(next_tick=True) + signal.signal(signal.SIGQUIT, handler) loop.run() except (KeyboardInterrupt, IOError, OSError) as e: logging.error(e) diff --git a/shadowsocks/server.py b/shadowsocks/server.py index 5f92b58..3adc4fd 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -24,13 +24,13 @@ import sys import os import logging +import signal import utils import encrypt import eventloop import tcprelay import udprelay import asyncdns -import signal def main():