We run RStudio Server in a singularity container and need to pass some environment variables to the RStudio Server through .Renviron. We would like to clean up .Renviron after RStudio Server is stopped. The ideal place to put the cleanup script is clean.sh. However, to stop RStudio Server I have to use the ‘delete’ button, which sends SIGKILL to the batch script. rserver will be killed and the clean_up() function in the batch script will be skipped. clean_up() is supposed to call clean.sh if it exists and kills any vncservers started by the user.
My questions are:
Is there another way to shut down rstudio server without using the ‘delete’ button?
If we have to use the ‘delete’ button, is there a way to at least have the customized ‘clean.sh’ executed?
From the interactive apps page that is going to be the only option aside from killing this within the app itself.
I don’t know exactly how you could, but it seems like you could use singularity to do this somehow since it manages the container, and what you are looking for is something to gracefully handle this shut down of the server in the container, that may be a route.
The other approach may be to use the template/script and include a cleanup function which then has a trap command that watches for the SIGKILL which could then execute what is needed in the cleanup function.
I know those aren’t too specific but hopefully they can get things moving. I’d say adding the trap in the template/script would be easiest to try first and see if it functions correctly.
Let me know if you have any more issues or questions on this though.
It would be the best solution to add cleanup in template/script. Unfortunately SIGKILL cannot be trapped.
If we use singularity to shutdown the rserver, where to put the control that allows users to shut down the server? Maybe a ‘shutdown’ button in the interactive apps page? But how to implement that?
If it’s a singularity container, why not just mount a new job specific .Renviron to that location? This will be specific to that job & singularity instance, so it doesn’t overwrite the actual users’ file.
So in you’re batch connect application, you’d have something like this.
template/Renviorn.erb
Then you can mount it in your script.sh.erb with
-B $WORKING_DIR/Renvion $HOME/.Renviron
We don’t use singularity anymore, so I had to look back to this tag. But you can see we template files in an etc/ directory and these show up at runtime at $WORKING_DIR/etc. (the $WORKING_DIR is that big long ~/ondemand/data/sys/... directory that’s specific to that job).
We use bwrap now because we updated to apptainer and we use user namespaces (so we turned off the setuid thing in apptainer).
Apptainer worked mostly fine, but we hit this issue with RHEL/7 where you can’t open psuedoterminals in containers when using user namespaces. Rstudio has that feature - to open a terminal.
Again - it only affects you if you’ve enabled user namespaces and run RHEL/7.