mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 06:22:59 +00:00
update proxy with already-running users at startup
This commit is contained in:
@@ -447,7 +447,7 @@ class JupyterHubApp(Application):
|
|||||||
)
|
)
|
||||||
self.db.add(self.proxy)
|
self.db.add(self.proxy)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
self.proxy.log = self.log
|
||||||
self.proxy.public_server.ip = self.ip
|
self.proxy.public_server.ip = self.ip
|
||||||
self.proxy.public_server.port = self.port
|
self.proxy.public_server.port = self.port
|
||||||
self.proxy.api_server.ip = self.proxy_api_ip
|
self.proxy.api_server.ip = self.proxy_api_ip
|
||||||
@@ -644,6 +644,7 @@ class JupyterHubApp(Application):
|
|||||||
return
|
return
|
||||||
|
|
||||||
loop = IOLoop.current()
|
loop = IOLoop.current()
|
||||||
|
loop.add_callback(self.proxy.add_all_users)
|
||||||
|
|
||||||
if self.proxy_process:
|
if self.proxy_process:
|
||||||
# only check / restart the proxy if we started it in the first place.
|
# only check / restart the proxy if we started it in the first place.
|
||||||
|
@@ -9,6 +9,7 @@ import socket
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from tornado import gen
|
from tornado import gen
|
||||||
|
from tornado.log import app_log
|
||||||
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError
|
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError
|
||||||
|
|
||||||
from sqlalchemy.types import TypeDecorator, VARCHAR
|
from sqlalchemy.types import TypeDecorator, VARCHAR
|
||||||
@@ -123,6 +124,7 @@ class Proxy(Base):
|
|||||||
public_server = relationship(Server, primaryjoin=_public_server_id == Server.id)
|
public_server = relationship(Server, primaryjoin=_public_server_id == Server.id)
|
||||||
_api_server_id = Column(Integer, ForeignKey('servers.id'))
|
_api_server_id = Column(Integer, ForeignKey('servers.id'))
|
||||||
api_server = relationship(Server, primaryjoin=_api_server_id == Server.id)
|
api_server = relationship(Server, primaryjoin=_api_server_id == Server.id)
|
||||||
|
log = app_log
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.public_server:
|
if self.public_server:
|
||||||
@@ -135,6 +137,9 @@ class Proxy(Base):
|
|||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def add_user(self, user, client=None):
|
def add_user(self, user, client=None):
|
||||||
"""Add a user's server to the proxy table."""
|
"""Add a user's server to the proxy table."""
|
||||||
|
self.log.info("Adding user %s to proxy %s => %s",
|
||||||
|
user.name, user.server.base_url, user.server.host,
|
||||||
|
)
|
||||||
client = client or AsyncHTTPClient()
|
client = client or AsyncHTTPClient()
|
||||||
|
|
||||||
req = HTTPRequest(url_path_join(
|
req = HTTPRequest(url_path_join(
|
||||||
@@ -154,6 +159,7 @@ class Proxy(Base):
|
|||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def delete_user(self, user, client=None):
|
def delete_user(self, user, client=None):
|
||||||
"""Remove a user's server to the proxy table."""
|
"""Remove a user's server to the proxy table."""
|
||||||
|
self.log.info("Removing user %s from proxy", user.name)
|
||||||
client = client or AsyncHTTPClient()
|
client = client or AsyncHTTPClient()
|
||||||
req = HTTPRequest(url_path_join(
|
req = HTTPRequest(url_path_join(
|
||||||
self.api_server.url,
|
self.api_server.url,
|
||||||
|
Reference in New Issue
Block a user