Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart shiny server in Docker container?

I have a Dockerized R Shiny app that extends the rocker/shiny image. I would like to restart the shiny-server inside of the Docker container at some point. From the documentation of shiny-server, I tried all the commands for different Linux builds and none of them worked.

Does anyone know how to restart the shiny-server in the Docker container?

like image 219
Zichen Wang Avatar asked Jan 09 '17 17:01

Zichen Wang


2 Answers

The command

docker ps

lists all running containers, get the required container id. Then run

docker exec -it <container_id> bash

to get into the required docker container. Then

sudo -i 
sudo systemctl restart shiny-server

to restart the shiny server. Hope that helps, systemctl will probably only work on Ubuntu.

like image 135
sjdm Avatar answered Oct 21 '22 18:10

sjdm


An app running in shiny server can be restarted by updating the timestamp on a file restart.txt.

From the docs:

An application can be restarted by altering the "modified time" on a file named restart.txt in the application's directory. This can most easily be done using the touch utility, as in touch restart.txt, which will update the modified timestamp on this file to the current time. Upon the next new connection to the application, Shiny Server will spawn a new R process to run the "new" (restarted) Shiny Application for this and future users.

(Source: https://docs.rstudio.com/shiny-server/#restarting-an-application)

If you need to periodically restart the application (eg. if you set app_idle_timeout = 0 but wish to regularly restart to pull some updated data), you could use a cronjob in the rocker/shiny container to touch restart.txt according to some desired schedule.

like image 23
jwalton Avatar answered Oct 21 '22 17:10

jwalton