Skip to content

Commit

Permalink
Polish.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwlzn committed Aug 21, 2019
1 parent a747850 commit ac28ad6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ def shutdown_server(server_info, timeout=5, log=None):
Returns True if the server was stopped by any means, False if stopping it
failed (on Windows).
"""
# TODO: this needs to handle socket connections
from tornado.httpclient import HTTPClient, HTTPRequest
url = server_info['url']
pid = server_info['pid']
Expand Down Expand Up @@ -454,6 +455,9 @@ class NbserverStopApp(JupyterApp):
port = Integer(DEFAULT_NOTEBOOK_PORT, config=True,
help="Port of the server to be killed. Default %s" % DEFAULT_NOTEBOOK_PORT)

sock = Unicode(u'', config=True,
help="UNIX socket of the server to be killed.")

def parse_command_line(self, argv=None):
super(NbserverStopApp, self).parse_command_line(argv)
if self.extra_args:
Expand All @@ -467,16 +471,16 @@ def start(self):
if not servers:
self.exit("There are no running servers")
for server in servers:
if server['port'] == self.port:
if server.get('sock') == self.sock or server['port'] == self.port:
print("Shutting down server on port", self.port, "...")
if not self.shutdown_server(server):
sys.exit("Could not stop server")
return
else:
print("There is currently no server running on port {}".format(self.port), file=sys.stderr)
print("Ports currently in use:", file=sys.stderr)
print("Ports/sockets currently in use:", file=sys.stderr)
for server in servers:
print(" - {}".format(server['port']), file=sys.stderr)
print(" - {}".format(server.get('sock', server['port'])), file=sys.stderr)
self.exit(1)


Expand Down Expand Up @@ -556,6 +560,8 @@ def start(self):
'ip': 'NotebookApp.ip',
'port': 'NotebookApp.port',
'port-retries': 'NotebookApp.port_retries',
'sock': 'NotebookApp.sock',
'sock-umask': 'NotebookApp.sock_umask',
'transport': 'KernelManager.transport',
'keyfile': 'NotebookApp.keyfile',
'certfile': 'NotebookApp.certfile',
Expand Down Expand Up @@ -703,7 +709,7 @@ def _valdate_ip(self, proposal):
help=_("The UNIX socket the notebook server will listen on.")
)

sock_umask = Unicode(u'', config=True,
sock_umask = Unicode(u'0600', config=True,
help=_("The UNIX socket umask to set on creation (default: 0600).")
)

Expand Down Expand Up @@ -1472,7 +1478,7 @@ def _bind_http_server(self):

def _bind_http_server_unix(self):
try:
sock = bind_unix_socket(self.sock, mode=int(self.sock_umask, 8))
sock = bind_unix_socket(self.sock, mode=int(self.sock_umask.encode(), 8))
self.http_server.add_socket(sock)
except socket.error as e:
if e.errno == errno.EADDRINUSE:
Expand Down Expand Up @@ -1772,6 +1778,7 @@ def server_info(self):
return {'url': self.connection_url,
'hostname': self.ip if self.ip else 'localhost',
'port': self.port,
'sock': self.sock,
'secure': bool(self.certfile),
'base_url': self.base_url,
'token': self.token,
Expand Down

0 comments on commit ac28ad6

Please sign in to comment.