allow manager to bind on unix socket

This commit is contained in:
clowwindy 2015-08-05 23:11:56 +08:00
parent 9c3af61433
commit d20a07192c
3 changed files with 18 additions and 10 deletions

View file

@ -40,18 +40,26 @@ class Manager(object):
self._loop = eventloop.EventLoop()
self._dns_resolver = asyncdns.DNSResolver()
self._dns_resolver.add_to_loop(self._loop)
self._control_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)
self._statistics = collections.defaultdict(int)
self._control_client_addr = None
try:
manager_address = config['manager_address']
if ':' in manager_address:
addr = manager_address.split(':')
addr = addr[0], int(addr[1])
family = socket.AF_INET
else:
addr = manager_address
family = socket.AF_UNIX
# TODO use address instead of port
self._control_socket.bind(('127.0.0.1',
int(config['manager_port'])))
self._control_socket = socket.socket(family,
socket.SOCK_DGRAM)
self._control_socket.bind(addr)
self._control_socket.setblocking(False)
except (OSError, IOError) as e:
logging.error(e)
logging.error('can not bind to manager port')
logging.error('can not bind to manager address')
exit(1)
self._loop.add(self._control_socket,
eventloop.POLL_IN, self)

View file

@ -49,7 +49,7 @@ def main():
else:
config['port_password'][str(server_port)] = config['password']
if config.get('manager_port', 0):
if config.get('manager_address', 0):
logging.info('entering manager mode')
manager.run(config)
return

View file

@ -136,7 +136,7 @@ def get_config(is_local):
else:
shortopts = 'hd:s:p:k:m:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
'forbidden-ip=', 'user=', 'manager-port=', 'version']
'forbidden-ip=', 'user=', 'manager-address=', 'version']
try:
config_path = find_config()
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
@ -181,8 +181,8 @@ def get_config(is_local):
config['fast_open'] = True
elif key == '--workers':
config['workers'] = int(value)
elif key == '--manager-port':
config['manager_port'] = int(value)
elif key == '--manager-address':
config['manager_address'] = value
elif key == '--user':
config['user'] = to_str(value)
elif key == '--forbidden-ip':
@ -319,7 +319,7 @@ Proxy options:
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
--workers WORKERS number of workers, available on Unix/Linux
--forbidden-ip IPLIST comma seperated IP list forbidden to connect
--manager-port PORT optional server manager UDP port
--manager-address ADDR optional server manager UDP address, see wiki
General options:
-h, --help show this help message and exit