RStudio Server Cleanup

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:

  1. Is there another way to shut down rstudio server without using the ‘delete’ button?
  2. 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.

Travis, thanks for the suggestions.

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.

Jeff, isn’t .Renviron in Home or in a rstudio project directory? How can I mount a .Renviron file specific to a job? Could you provide more details?

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).

Thanks Jeff. It works.

You said you don’t use singularity any more. What do you use then? I have tried PRoot, but did get it working.

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.

In fact we have clusters running RHEL/7 with apptainer. We have also run into the issue of opening a terminal in rstudio server:

Can you share your new rstudio server app which used bwrap and apptainer?

Just look at the most current update. This is our production app.

You can see this pull request for the updates I made to the same.

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