Skip to content
This repository
Browse code

Touching restart.txt in an app dir forces a restart

  • Loading branch information...
commit db80a2c5679f2e627fd95a80a3bef072b1ceed18 1 parent 653acfa
Joe Cheng authored March 14, 2013
7  NEWS
... ...
@@ -1,3 +1,10 @@
  1
+shiny-server 0.3.4
  2
+--------------------------------------------------------------------------------
  3
+
  4
+* You can now force an app to restart by calling "touch restart.txt" in the app
  5
+  directory root. Existing sessions will not be terminated, but the next session
  6
+  to be initiated will cause a new R process to be launched.
  7
+
1 8
 shiny-server 0.3.3
2 9
 --------------------------------------------------------------------------------
3 10
 
2  lib/main.js
@@ -68,7 +68,7 @@ function ping(req, res) {
68 68
 
69 69
 // We'll need routers...
70 70
 var indirectRouter = new router.IndirectRouter(new router.NullRouter());
71  
-var metarouter = router.join(indirectRouter, ping);
  71
+var metarouter = new router.RestartRouter(router.join(indirectRouter, ping));
72 72
 
73 73
 // ...a worker registry...
74 74
 var workerRegistry = new WorkerRegistry();
31  lib/router/router.js
@@ -77,6 +77,37 @@ function IndirectRouter(router) {
77 77
 }).call(IndirectRouter.prototype);
78 78
 
79 79
 
  80
+// Router that annotates the AppSpec with $APPDIR/restart.txt timestamp,
  81
+// if the file exists. This makes it possible for app developers and
  82
+// admins to use "touch restart.txt" to force an app to start a fresh
  83
+// instance on subsequent loads.
  84
+exports.RestartRouter = RestartRouter;
  85
+function RestartRouter(router) {
  86
+  this.$router = router;
  87
+}
  88
+(function() {
  89
+  this.getAppSpec_p = function(req, res) {
  90
+    return this.$router.getAppSpec_p.apply(this.$router, arguments)
  91
+    .then(function(appSpec) {
  92
+      if (appSpec) {
  93
+        return Q.nfcall(fs.stat, path.join(appSpec.appDir, 'restart.txt'))
  94
+        .then(
  95
+          function(stat) {
  96
+            appSpec.settings.restart = stat.mtime.getTime();
  97
+            return appSpec;
  98
+          },
  99
+          function(err) {
  100
+            return appSpec;
  101
+          }
  102
+        )
  103
+      } else {
  104
+        return appSpec;
  105
+      }
  106
+    });
  107
+  };
  108
+}).call(RestartRouter.prototype);
  109
+
  110
+
80 111
 exports.getFirstAppSpec_p = getFirstAppSpec_p;
81 112
 function getFirstAppSpec_p(routers, req, res) {
82 113
   return qutil.forEachPromise_p(
2  package.json
... ...
@@ -1,7 +1,7 @@
1 1
 {
2 2
   "name": "shiny-server",
3 3
   "preferGlobal": "true",
4  
-  "version": "0.3.3",
  4
+  "version": "0.3.3.99",
5 5
   "author": "RStudio <node@rstudio.com>",
6 6
   "description": "Application server for the Shiny web framework for R",
7 7
   "bin": "./lib/main.js",

0 notes on commit db80a2c

Please sign in to comment.
Something went wrong with that request. Please try again.