Browse Source

implement graceful shutdown in sslocal; close #179

auth
clowwindy 10 years ago
parent
commit
fdb3a36170
  1. 7
      shadowsocks/local.py
  2. 2
      shadowsocks/server.py

7
shadowsocks/local.py

@ -24,6 +24,7 @@
import sys import sys
import os import os
import logging import logging
import signal
import utils import utils
import encrypt import encrypt
import eventloop import eventloop
@ -58,6 +59,12 @@ def main():
dns_resolver.add_to_loop(loop) dns_resolver.add_to_loop(loop)
tcp_server.add_to_loop(loop) tcp_server.add_to_loop(loop)
udp_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() loop.run()
except (KeyboardInterrupt, IOError, OSError) as e: except (KeyboardInterrupt, IOError, OSError) as e:
logging.error(e) logging.error(e)

2
shadowsocks/server.py

@ -24,13 +24,13 @@
import sys import sys
import os import os
import logging import logging
import signal
import utils import utils
import encrypt import encrypt
import eventloop import eventloop
import tcprelay import tcprelay
import udprelay import udprelay
import asyncdns import asyncdns
import signal
def main(): def main():

Loading…
Cancel
Save