diff --git a/batchspawner/batchspawner.py b/batchspawner/batchspawner.py index 1a8a77b5..9e320f8f 100644 --- a/batchspawner/batchspawner.py +++ b/batchspawner/batchspawner.py @@ -74,9 +74,6 @@ class BatchSpawnerBase(Spawner): state_gethost """ - # override default since will need to set the listening port using the api - cmd = Command(['batchspawner-singleuser'], allow_none=True).tag(config=True) - # override default since batch systems typically need longer start_timeout = Integer(300).tag(config=True) @@ -190,7 +187,7 @@ def parse_job_id(self, output): return output def cmd_formatted_for_batch(self): - return ' '.join(self.cmd + self.get_args()) + return ' '.join(['batchspawner-singleuser'] + self.cmd + self.get_args()) @gen.coroutine def run_command(self, cmd, input=None, env=None): diff --git a/batchspawner/singleuser.py b/batchspawner/singleuser.py index 6d493262..afb171a2 100644 --- a/batchspawner/singleuser.py +++ b/batchspawner/singleuser.py @@ -1,21 +1,25 @@ -from jupyterhub.singleuser import SingleUserNotebookApp -from jupyterhub.utils import random_port, url_path_join -from traitlets import default +import os +import sys -class BatchSingleUserNotebookApp(SingleUserNotebookApp): - @default('port') - def _port(self): - return random_port() +from runpy import run_path +from shutil import which - def start(self): - # Send Notebook app's port number to remote Spawner - self.hub_auth._api_request(method='POST', - url=url_path_join(self.hub_api_url, 'batchspawner'), - json={'port' : self.port}) - super().start() +from jupyterhub.utils import random_port, url_path_join +from jupyterhub.services.auth import HubAuth def main(argv=None): - return BatchSingleUserNotebookApp.launch_instance(argv) + port = random_port() + hub_auth = HubAuth() + hub_auth.client_ca = os.environ.get('JUPYTERHUB_SSL_CLIENT_CA', '') + hub_auth.certfile = os.environ.get('JUPYTERHUB_SSL_CERTFILE', '') + hub_auth.keyfile = os.environ.get('JUPYTERHUB_SSL_KEYFILE', '') + hub_auth._api_request(method='POST', + url=url_path_join(hub_auth.api_url, 'batchspawner'), + json={'port' : port}) + + cmd_path = which(sys.argv[1]) + sys.argv = sys.argv[1:] + ['--port={}'.format(port)] + run_path(cmd_path, run_name="__main__") if __name__ == "__main__": main() \ No newline at end of file