# Osc\_bc\_rstudio\_server streamlined submit.yml.erb

**URL:** <https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097>\
**Category:** Get Help\
**Tags:** question\
**Created:** [June 3, 2022, 7:00pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097 "2022-06-03T19:00:59Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [June 9, 2022, 5:36pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/21 "2022-06-09T17:36:27Z")

</div>

I’d guess it’s the DB it’s trying to create. I see you have one, but I’d guess it’s a mounting discrepancy.

What scheduler are you on? Slurm gives job specific TMPDIR, so using $TMPDIR in the script, will evaluate to `/tmp/some_job_id` but you’ve mounted it in as just `/tmp` in the container (line 100).

So you need to reference `/tmp` in lines 111 and 112 because that’s where the files are _in the container when the server starts_.

```auto
100 -B “$TMPDIR:/tmp” 
...
111 --database-config-file “/tmp/db.conf”
112 --server-data-dir “/tmp/rstudio-server” 

```

---

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [June 9, 2022, 9:45pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/22 "2022-06-09T21:45:22Z")

</div>

Thanks – understanding to reference “inside” the container paths was important. That allows the server to start running when launching ‘script.sh’ from the command line in the ood working directory.

When I adapt those changes into the ‘script.sh.erb’ and launch the app, the rsession.log is still not generated into the working directory. The operational state is that rserver is started on a compute node:  
mrd20 868792 868767 0 17:38 ? 00:00:00 bash /home/mrd20/ondemand/data/sys/dashboard/batch\_connect/dev/RStudio\_Pioneer/output/a4e2a6d1-970f-4dfa-ab4b-39aa549d5eb0/script.sh  
mrd20 868855 868792 0 17:38 ? 00:00:00 Singularity runtime parent  
mrd20 868869 868855 0 17:38 ? 00:00:00 rserver --www-port 21673 --auth-none 0 --auth-pam-helper-path /home/mrd20/ondemand/data/sys/dashboard/batch\_connect/dev/RStudio\_Pioneer/output/a4e2a6d1-970f-4dfa-ab4b-39aa549d5eb0/bin/auth --auth-encrypt-password 0 --database-config-file /tmp/db.conf --server-data-dir /tmp/rstudio-server --server-user=mrd20 --rsession-path /home/mrd20/ondemand/data/sys/dashboard/batch\_connect/dev/RStudio\_Pioneer/output/a4e2a6d1-970f-4dfa-ab4b-39aa549d5eb0/rsession.sh

The ‘Connect to RStudio Server’ radio button launches a new tab, in which a ‘Signin to Rstudio’ is presented. Is one meant to manually use the ‘connection.yml’ info to signin? I can’t negotiate this page, and again, there is no ‘rsession.log’ to refer to.

And yet…Progress!!  
ps: from script.sh.erb  
89 # Launch the RStudio Server  
90  
91 ## Prepare temp directory for sqlite db and conf  
92  
93 echo “Temp directory for db: $TMPDIR”  
94 echo “create var directory under WORKING\_DIR”  
95 mkdir “$WORKING\_DIR/var”  
96  
97 echo “Starting up rserver… at $(date)”  
98  
99 #  
100 singularity run   
101 -B “$TMPDIR:/tmp”   
102 -B “$WORKING\_DIR”   
103 -B “$WORKING\_DIR/var:/var/lib/rstudio-server”   
104 -B /home   
105 “$RSTUDIO\_SERVER\_IMAGE”   
106 --www-port “${port}”   
107 --auth-none 0   
108 --auth-pam-helper-path “${RSTUDIO\_AUTH}”   
109 --auth-encrypt-password 0   
110 --database-config-file “/tmp/db.conf”   
111 --server-data-dir “/tmp/rstudio-server”   
112 --server-user=$(whoami)   
113 --rsession-path “${RSESSION\_WRAPPER\_FILE}”  
114  
115 echo ‘Singularity as exited…’

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [June 10, 2022, 1:02am UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/23 "2022-06-10T01:02:23Z")

</div>

Maybe you need to initialize some empty directories?

> <https://github.com/OSC/bc_osc_rstudio_server/blob/1ce2e4fb1ddb25921069a1e31cb3edc02ce90535/template/script.sh.erb#L122-L127>

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [June 10, 2022, 1:06am UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/24 "2022-06-10T01:06:57Z")

</div>

> [@emily.dragowsky](#):
>
> –database-config-file “/tmp/db.conf”

Also is this file being created somewhere? Every file in the `template` directory will be copied to `$WORKING_DIR`.

That’s how I mount configs like the `db.conf`.

> <https://github.com/OSC/bc_osc_rstudio_server/blob/1ce2e4fb1ddb25921069a1e31cb3edc02ce90535/template/script.sh.erb#L144>

Plus, since every file is templated, I can configure the log directory to the effectively the same directory as `WORKING_DIR`.

> <https://github.com/OSC/bc_osc_rstudio_server/blob/1ce2e4fb1ddb25921069a1e31cb3edc02ce90535/template/etc/logging.conf.erb#L4>

---

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [June 10, 2022, 4:02pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/25 "2022-06-10T16:02:02Z")

</div>

Thanks, Jeff – The local script.sh.erb remains pretty faithful to the osc repo version.  
What I’ve done is attempted to strip out the ruby conditionals, to aid my understanding.

I’m still confused over how the reverse proxy is supported with only the use of a “basic” template, from the submit.yml.erb.

And the rserver signin: how does that work? I’m hoping that knowing the procedure will help understand the bindings required to implement the server. Particularly, why am I still not finding the rserver.log?

Thanks

> #!/usr/bin/env bash  
> \<%-  
> session\_dir = session.staged\_root  
> %\>
> 
> # Load the required environment
> 
> setup\_env () {
> 
> export WORKING\_DIR=“\<%= session\_dir %\>”
> 
> module purge
> 
> # The rserver container module should set these environment variables:
> 
> # SINGULARITY\_BINDPATH=“/etc,/media,/mnt,/opt,/run,/srv,/usr,/var,/users”
> 
> # RSTUDIO\_SERVER\_IMAGE=“/usr/local/project/ondemand/singularity/rstudio/rstudio\_launcher\_centos7.simg”
> 
> # PATH=“$PATH:/path/to/R:/path/to/rstudio/rserver”
> 
> export RSTUDIO\_SERVER\_IMAGE=“/home/mrd20/hpcdemo/rstudio/rstudio-launcher-centos-8.sif”  
> export SINGULARITY\_BINDPATH=“/scratch,/usr/local”  
> export PATH=“$PATH:/usr/local/easybuild/software/RStudio-Server/1.4.1717-foss-2021a-Java-11-R-4.1.0/bin”
> 
> # SINGULARITY\_BINDPATH is being used to bind all RStudio’s requirements from
> 
> # the host into the guest, and so those values may vary between sites.
> 
> # module load ondemand-vnc/2.0
> 
> module load singularity/3.8.6  
> module load RStudio-Server/1.4.1717-foss-2021a-Java-11-R-4.1.0  
> which rsession  
> export LD\_LIBRARY\_PATH=/usr/lib:$LD\_LIBRARY\_PATH  
> export SINGULARITYENV\_LD\_LIBRARY\_PATH=“$LD\_LIBRARY\_PATH”  
> }  
> setup\_env
> 
> # 
> 
> # Start RStudio Server
> 
> # 
> 
> # PAM auth helper used by RStudio
> 
> export RSTUDIO\_AUTH=“$WORKING\_DIR/bin/auth”
> 
> # Generate an `rsession` wrapper script
> 
> export RSESSION\_WRAPPER\_FILE=“$WORKING\_DIR/rsession.sh”  
> (  
> umask 077  
> sed ‘s/^ {2}//’ \> “$WORKING\_DIR/rsession.sh” \<\< EOL  
> #!/usr/bin/env bash
> 
> # Log all output from this script
> 
> export RSESSION\_LOG\_FILE=“$WORKING\_DIR/rsession.log”
> 
> exec &\>\>“${RSESSION\_LOG\_FILE}”  
> set -x
> 
> # rsession.sh doesn’t share the same env as the outside script, so these
> 
> # need to be set explicitly
> 
> export R\_LIBS\_SITE=“${R\_LIBS\_SITE}”  
> export TZ=“US/Eastern”  
> export HOME=“$HOME”  
> export MODULEPATH\_ROOT=“$MODULEPATH\_ROOT”  
> export MODULEPATH=“$MODULEPATH”  
> export LMOD\_PKG=“$LMOD\_PKG”
> 
> env
> 
> # Launch the original command
> 
> echo “Launching rsession…”  
> wrsession=`which rsession`  
> echo “which rsession? $wrsession?”  
> exec rsession --r-libs-user “${R\_LIBS\_USER}” “${@}”  
> EOL  
> )  
> chmod 700 “$WORKING\_DIR/rsession.sh”
> 
> # Set working directory to home directory
> 
> echo “Home check:\nHOME is: $HOME\nSHOME is $SINGULARITY\_HOME”
> 
> # cd “${SINGULARITY\_HOME}”
> 
> # Output debug info
> 
> hostname  
> whoami  
> echo “$USER”
> 
> # rstudio runtime stuff
> 
> echo -e “provider=sqlite\ndirectory=$TMPDIR/db” \>\> $TMPDIR/db.conf  
> mkdir “$TMPDIR/run”  
> mkdir “$TMPDIR/lib”
> 
> # server log directory in this job’s working directory
> 
> mkdir -p “$WORKING\_DIR/logs”
> 
> set -x
> 
> # Launch the RStudio Server
> 
> ## Prepare temp directory for sqlite db and conf
> 
> echo “Temp directory for db: $TMPDIR”  
> #echo “create var directory under WORKING\_DIR”  
> #mkdir “$WORKING\_DIR/var”
> 
> echo “Starting up rserver… at $(date)”
> 
> #SINGULARITYENV\_LD\_LIBRARY\_PATH=“$LD\_LIBRARY\_PATH”   
> singularity run   
> -B “$TMPDIR:/tmp”   
> -B “$WORKING\_DIR”   
> -B “$TMPDIR/lib:/var/lib/rstudio-server”   
> -B /home   
> “$RSTUDIO\_SERVER\_IMAGE”   
> –www-port “${port}”   
> –auth-none 0   
> –auth-pam-helper-path “${RSTUDIO\_AUTH}”   
> –auth-encrypt-password 0   
> –rsession-path “${RSESSION\_WRAPPER\_FILE}”  
> –database-config-file “/tmp/db.conf”   
> –server-data-dir “/tmp/run”   
> –server-user=$(whoami)   
> –secure-cookie-key-file “/tmp/rstudio-server/secure-cookie-key” \
> 
> echo ‘Singularity as exited…’

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [June 10, 2022, 5:44pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/26 "2022-06-10T17:44:12Z")

</div>

> [@emily.dragowsky](#):
>
> echo -e “provider=sqlite\ndirectory=/tmp/db” \>\> $TMPDIR/db.conf

Does this need to be static /tmp because that’s the value inside the container?

> [@emily.dragowsky](#):
>
> And the rserver signin: how does that work? I’m hoping that knowing the procedure will help understand the bindings required to implement the server

This is part of how auth works.

> [@emily.dragowsky](#):
>
> –auth-pam-helper-path “${RSTUDIO\_AUTH}”

The other bit that’s an update from 1.2 to 1.3 where we create a CSRF token in the `script.sh.erb`, passit to the view in `submit.yml.erb` (in `conn_params`) then use it in the `view.html.erb`.

If you’re still not booting correctly, take advantage of that `set -x` there. It telling you what command it’s issuing.

You have a working version correct? What’s are the differences between the working version and the version you can submit and generate now?

---

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [June 10, 2022, 6:06pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/27 "2022-06-10T18:06:19Z")

</div>

Sorry for not being more direct in reponse to your questions about the database files:

[mrd20@compt351 be955dbb-a98e-45ad-9454-ca476df1d8e3]$ ls -R /tmp/job.11010.hpc  
/tmp/job.11010.hpc:  
**db.conf** job.11010.hpc lib rstudio-server run

/tmp/job.11010.hpc/job.11010.hpc:  
db

/tmp/job.11010.hpc/job.11010.hpc/db:  
rstudio.sqlite

/tmp/job.11010.hpc/lib:

/tmp/job.11010.hpc/rstudio-server:  
secure-cookie-key

/tmp/job.11010.hpc/run:  
rstudio-rsession

/tmp/job.11010.hpc/run/rstudio-rsession:

From: ```  
-B $WORKING\_DIR/etc:/etc/rstudio \

```auto

Do I understand correctly from the line above that you place the db.conf in the $WORKING_DIR/etc, and then bind that into the container at /etc/rstudio?
```

---

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [June 10, 2022, 7:16pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/28 "2022-06-10T19:16:50Z")

</div>

So the session launches, rserver is running on the compute node, and the view presents

 ![image](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/7/7678d32b5bc88a9b8f2293a55e626eb2cf7c2354.png)

Connect to RStudio Server then

 ![image](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/be07d89f4ad452b638dd9fbb0536787e64d79bef.png)

In the code that I’m working with ‘before.sh’ is generating the password and the csrf-token.

```auto
# Export the module function if it exists
[[$(type -t module) == "function"]] && export -f module

# Find available port to run server on
port=$(find_port ${host})

# Define a password and export it for RStudio authentication
password="$(create_passwd 16)"

# rstudio 1.4+ needs a csrf token
csrf_token=<%= SecureRandom.uuid %>

export RSTUDIO_PASSWORD="${password}"
template/before.sh.erb (END)

```

In the script.sh, we have:

```auto
export RSTUDIO_AUTH="$WORKING_DIR/bin/auth"
<..snip..>
--auth-pam-helper-path "${RSTUDIO_AUTH}"

```

So this appears that the flag “–auth-pam-helper-path” executes the script to pull the RSTUDIO\_PASSWORD from the environment variable. before.sh also generates the csrf\_token, but only as a local variable. So for authentication, the only binding that seems relevant is for the $WORKING\_DIR, where before.sh and bin/auth are to be found.

Unfortunately, I’m still not able to see rsession.log, which as you earlier pointed out, would be quite helpful with some of the detailed troubleshooting. Could you please review what needs done to gain access to the rsession.log? Thanks

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [June 21, 2022, 9:59pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/29 "2022-06-21T21:59:54Z")

</div>

**How to get the log directory?**

> <https://github.com/OSC/bc_osc_rstudio_server/blob/master/template/etc/logging.conf.erb>

I used this configuration file with a mount point to etc. Looking at the `rserver` help output I don’t believe there’s an equivalent for this configuration like there is for the `--database-config-file`. So I was likely forced to mount it because there’s no other entrypoint to change it.

**What could be wrong with your auth**

As for what’s going on with your authentication there are these changes you need to make

1. First the auth file needs updated

```auto
# template/bin/auth
# this used to be ne. Now it needs to be lt.
if [[$# -lt 1]]; then

```

1. Generate the `csrf_token`. You have that.
2. pass the `csrf_token` back to the view. Do this by using `conn_params` in your `submit.yml.erb`

```auto
---
batch_connect:
  template: "basic"
  conn_params:
    - csrf_token

```

1. Use the `csrf_token` in the view. That’s all the javascript addition and new hidden form field in this git diff I’d used in my original reply.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/0/0331fac32ad4e03df6b368470c5e70cd9834bf62.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [December 18, 2022, 10:00pm UTC](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097/30 "2022-12-18T22:00:34Z")

</div>

Closed on December 18, 2022, 10:00pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.openondemand.org/t/osc-bc-rstudio-server-streamlined-submit-yml-erb/2097.md?page=1)
