diff rlgwebd-stop @ 200:a7cc38a0168d

Actually restart RLGWebD if it crashes. Also, rlgwebd-stop will no longer crash if RLGWebD has already stopped.
author John "Elwin" Edwards
date Sat, 23 Apr 2016 18:53:08 -0400
parents 3bdee6371c3f
children ffe22d88bea1
line wrap: on
line diff
--- a/rlgwebd-stop	Mon Feb 01 21:20:12 2016 -0500
+++ b/rlgwebd-stop	Sat Apr 23 18:53:08 2016 -0400
@@ -1,12 +1,22 @@
 #!/usr/bin/env node
 
 var net = require('net');
+var domain = require('domain');
 var sockpath = "/var/run/rlgwebd.sock";
 
-var sock = net.connect(sockpath, function () {
-  sock.on('close', function () {
-    if (process.argv[2] == "debug")
-      console.log("Control socket closed");
+var dom = domain.create();
+
+dom.on('error', function (err) {
+  console.log("Cannot connect to " + sockpath + ", rlgwebd already stopped.");
+  process.exit(0);
+});
+
+dom.run(function () {
+  var sock = net.connect(sockpath, function () {
+    sock.on('close', function () {
+      if (process.argv[2] == "debug")
+        console.log("Control socket closed");
+    });
+    sock.write("quit\n");
   });
-  sock.write("quit\n");
 });