Permalink
Browse files

Touching restart.txt in an app dir forces a restart

  • Loading branch information...
1 parent 653acfa commit db80a2c5679f2e627fd95a80a3bef072b1ceed18 @jcheng5 jcheng5 committed Mar 14, 2013
Showing with 40 additions and 2 deletions.
  1. +7 −0 NEWS
  2. +1 −1 lib/main.js
  3. +31 −0 lib/router/router.js
  4. +1 −1 package.json
View
7 NEWS
@@ -1,3 +1,10 @@
+shiny-server 0.3.4
+--------------------------------------------------------------------------------
+
+* You can now force an app to restart by calling "touch restart.txt" in the app
+ directory root. Existing sessions will not be terminated, but the next session
+ to be initiated will cause a new R process to be launched.
+
shiny-server 0.3.3
--------------------------------------------------------------------------------
View
@@ -68,7 +68,7 @@ function ping(req, res) {
// We'll need routers...
var indirectRouter = new router.IndirectRouter(new router.NullRouter());
-var metarouter = router.join(indirectRouter, ping);
+var metarouter = new router.RestartRouter(router.join(indirectRouter, ping));
// ...a worker registry...
var workerRegistry = new WorkerRegistry();
View
@@ -77,6 +77,37 @@ function IndirectRouter(router) {
}).call(IndirectRouter.prototype);
+// Router that annotates the AppSpec with $APPDIR/restart.txt timestamp,
+// if the file exists. This makes it possible for app developers and
+// admins to use "touch restart.txt" to force an app to start a fresh
+// instance on subsequent loads.
+exports.RestartRouter = RestartRouter;
+function RestartRouter(router) {
+ this.$router = router;
+}
+(function() {
+ this.getAppSpec_p = function(req, res) {
+ return this.$router.getAppSpec_p.apply(this.$router, arguments)
+ .then(function(appSpec) {
+ if (appSpec) {
+ return Q.nfcall(fs.stat, path.join(appSpec.appDir, 'restart.txt'))
+ .then(
+ function(stat) {
+ appSpec.settings.restart = stat.mtime.getTime();
+ return appSpec;
+ },
+ function(err) {
+ return appSpec;
+ }
+ )
+ } else {
+ return appSpec;
+ }
+ });
+ };
+}).call(RestartRouter.prototype);
+
+
exports.getFirstAppSpec_p = getFirstAppSpec_p;
function getFirstAppSpec_p(routers, req, res) {
return qutil.forEachPromise_p(
View
@@ -1,7 +1,7 @@
{
"name": "shiny-server",
"preferGlobal": "true",
- "version": "0.3.3",
+ "version": "0.3.3.99",
"author": "RStudio <node@rstudio.com>",
"description": "Application server for the Shiny web framework for R",
"bin": "./lib/main.js",

0 comments on commit db80a2c

Please sign in to comment.