allow manager to bind on unix socket
This commit is contained in:
parent
9c3af61433
commit
d20a07192c
3 changed files with 18 additions and 10 deletions
|
@ -40,18 +40,26 @@ class Manager(object):
|
||||||
self._loop = eventloop.EventLoop()
|
self._loop = eventloop.EventLoop()
|
||||||
self._dns_resolver = asyncdns.DNSResolver()
|
self._dns_resolver = asyncdns.DNSResolver()
|
||||||
self._dns_resolver.add_to_loop(self._loop)
|
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._statistics = collections.defaultdict(int)
|
||||||
self._control_client_addr = None
|
self._control_client_addr = None
|
||||||
try:
|
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
|
# TODO use address instead of port
|
||||||
self._control_socket.bind(('127.0.0.1',
|
self._control_socket = socket.socket(family,
|
||||||
int(config['manager_port'])))
|
socket.SOCK_DGRAM)
|
||||||
|
self._control_socket.bind(addr)
|
||||||
self._control_socket.setblocking(False)
|
self._control_socket.setblocking(False)
|
||||||
except (OSError, IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
logging.error('can not bind to manager port')
|
logging.error('can not bind to manager address')
|
||||||
exit(1)
|
exit(1)
|
||||||
self._loop.add(self._control_socket,
|
self._loop.add(self._control_socket,
|
||||||
eventloop.POLL_IN, self)
|
eventloop.POLL_IN, self)
|
||||||
|
|
|
@ -49,7 +49,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
config['port_password'][str(server_port)] = config['password']
|
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')
|
logging.info('entering manager mode')
|
||||||
manager.run(config)
|
manager.run(config)
|
||||||
return
|
return
|
||||||
|
|
|
@ -136,7 +136,7 @@ def get_config(is_local):
|
||||||
else:
|
else:
|
||||||
shortopts = 'hd:s:p:k:m:c:t:vq'
|
shortopts = 'hd:s:p:k:m:c:t:vq'
|
||||||
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
|
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
|
||||||
'forbidden-ip=', 'user=', 'manager-port=', 'version']
|
'forbidden-ip=', 'user=', 'manager-address=', 'version']
|
||||||
try:
|
try:
|
||||||
config_path = find_config()
|
config_path = find_config()
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
|
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
|
||||||
|
@ -181,8 +181,8 @@ def get_config(is_local):
|
||||||
config['fast_open'] = True
|
config['fast_open'] = True
|
||||||
elif key == '--workers':
|
elif key == '--workers':
|
||||||
config['workers'] = int(value)
|
config['workers'] = int(value)
|
||||||
elif key == '--manager-port':
|
elif key == '--manager-address':
|
||||||
config['manager_port'] = int(value)
|
config['manager_address'] = value
|
||||||
elif key == '--user':
|
elif key == '--user':
|
||||||
config['user'] = to_str(value)
|
config['user'] = to_str(value)
|
||||||
elif key == '--forbidden-ip':
|
elif key == '--forbidden-ip':
|
||||||
|
@ -319,7 +319,7 @@ Proxy options:
|
||||||
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
|
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
|
||||||
--workers WORKERS number of workers, available on Unix/Linux
|
--workers WORKERS number of workers, available on Unix/Linux
|
||||||
--forbidden-ip IPLIST comma seperated IP list forbidden to connect
|
--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:
|
General options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
Loading…
Add table
Reference in a new issue