简体   繁体   中英

Restarting Shiny Server with crontab

I'm having a bit of trouble getting shiny-server to restart via crontab . So far, I have tried 2 ways:

1) Created bash script with restart shiny-server as the last line, and added to crontab . Additionally, there's SQL code that pre-processes data within this script.

0 15 * * * bash /home/local/ANT/raybao/load.sh

2) Added a line to crontab -e for root user like the following:

0 15 * * * restart shiny-sever

I added to root crontab as opposed to my own user's simply because you need to sudo restart shiny-server otherwise.

Oddly, all the SQL code within #1 above successfully runs and is logged, however the shiny-server process is not restarted. If I simply do: sudo -i and then restart shiny-server , it works so I'm baffled.

Any ideas on how to solve this?

So, I ended up posting this same question on Ask Ubuntu: https://askubuntu.com/questions/687423/use-crontab-to-restart-an-upstart-service-on-schedule

In summary, the correct way to schedule a restart of the shiny-server in Ubuntu 12.04 (which uses Upstart) is to add the following entry to your root user's crontab :

0 6 * * * /usr/sbin/restart shiny-server

Credit goes to @earthmeLon for helping me figure this out. Hope this helps somebody in the future!

Another solution is described in the server documentation: http://docs.rstudio.com/shiny-server/#schedulers-application-restarts

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. When this occurs, the old processes will remain unaltered, and open connections will remain active and valid until the last connection closes itself.

So, you could use this line to restart :

1) create a file restart.txt in the app directory:

nano restart.txt

2) call touch on this file:

* */1 * * * touch restart.txt

`

I'm stil a beginner to when it comes to Linux and all that comes with it but this worked for me.

If your like me and switched from Ubuntu 14.04 to 15.04 Ubuntu changed to use systemd as the default. This transition can also be seen here under 1.4 Stopping and Starting .

My problem was that I had an old version of shiny-server that used upstart to start and stop shiny-server so to fix this I reinstalled shiny-server and pasted this into my crontab (root) to test if the restart worked:

* */1 * * * systemctl restart shiny-server

It sounds like your problem is different but maybe this can help somewhat?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM