diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 37f7033..3b3d062 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -51,7 +51,7 @@ def get_system_user(): return(user) def setup_rserver(): - def _get_env(port): + def _get_env(port, unix_socket): return dict(USER=get_system_user()) def db_config(db_dir): @@ -83,7 +83,7 @@ def _get_www_frame_origin(default="same"): except Exception: return default - def _get_cmd(port): + def _get_cmd(port, unix_socket): ntf = tempfile.NamedTemporaryFile() # use mkdtemp() so the directory and its contents don't vanish when @@ -95,7 +95,6 @@ def _get_cmd(port): get_rstudio_executable('rserver'), '--auth-none=1', '--www-frame-origin=' + _get_www_frame_origin(), - '--www-port=' + str(port), '--www-verify-user-agent=0', '--secure-cookie-key-file=' + ntf.name, '--server-user=' + get_system_user(), @@ -109,6 +108,14 @@ def _get_cmd(port): if _support_arg('database-config-file'): cmd.append(f'--database-config-file={database_config_file}') + if unix_socket != "": + if _support_arg('www-socket'): + cmd.append('--www-socket={unix_socket}') + else: + raise NotImplementedError(f'rstudio-server does not support requested socket connection') + else: + cmd.append('--www-port={port}') + return cmd def _get_timeout(default=15): @@ -127,6 +134,16 @@ def _get_timeout(default=15): 'icon_path': get_icon_path() } } + + use_socket = os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET') + if use_socket is not None: + # If this env var is anything other than case insensitive 'no' or 'false', + # use unix sockets instead of tcp sockets. This allows us to default to + # using unix sockets by default in the future once this feature is better + # tested, and allow people to turn it off if needed. + if use_socket.casefold() not in ('no', 'false'): + server_process['unix_socket'] = True + return server_process def setup_rsession():