Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix server data dir (/var/run/rstudio) not writable. Support multiple rstudio-server versions #119

Merged
merged 4 commits into from
Dec 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions jupyter_rsession_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,14 @@ def setup_rserver():
def _get_env(port):
return dict(USER=getpass.getuser())

def db_config():
def db_config(db_dir):
'''
Create a temporary directory to hold rserver's database, and create
the configuration file rserver uses to find the database.

https://docs.rstudio.com/ide/server-pro/latest/database.html
https://github.com/rstudio/rstudio/tree/v1.4.1103/src/cpp/server/db
'''
# use mkdtemp() so the directory and its contents don't vanish when
# we're out of scope
db_dir = tempfile.mkdtemp()
# create the rserver database config
db_conf = dedent("""
provider=sqlite
Expand All @@ -69,8 +66,18 @@ def db_config():
f.close()
return db_config_name

def _support_arg(arg):
ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help'])
return ret.decode().find(arg) != -1

def _get_cmd(port):
ntf = tempfile.NamedTemporaryFile()

# use mkdtemp() so the directory and its contents don't vanish when
# we're out of scope
server_data_dir = tempfile.mkdtemp()
database_config_file = db_config(server_data_dir)

cmd = [
get_rstudio_executable('rserver'),
'--auth-none=1',
Expand All @@ -79,9 +86,15 @@ def _get_cmd(port):
'--www-verify-user-agent=0',
'--secure-cookie-key-file=' + ntf.name,
'--server-user=' + getpass.getuser(),
'--www-root-path={base_url}rstudio/',
f'--database-config-file={db_config()}'
]
# Support at least v1.2.1335 and up

if _support_arg('www-root-path'):
cmd.append('--www-root-path={base_url}rstudio/')
if _support_arg('server-data-dir'):
cmd.append(f'--server-data-dir={server_data_dir}')
if _support_arg('database-config-file'):
cmd.append(f'--database-config-file={database_config_file}')

return cmd

Expand Down