comparison rlgwebd-stop @ 207:ffe22d88bea1

rlgwebd-stop: avoid the deprecated domain module. Instead of catching connection errors with domains, install an error listener on the socket before connecting.
author John "Elwin" Edwards
date Fri, 27 Jan 2017 19:18:31 -0500
parents a7cc38a0168d
children f06f2d1a5035
comparison
equal deleted inserted replaced
206:04c2a895b679 207:ffe22d88bea1
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 2
3 var net = require('net'); 3 var net = require('net');
4 var domain = require('domain');
5 var sockpath = "/var/run/rlgwebd.sock"; 4 var sockpath = "/var/run/rlgwebd.sock";
6 5
7 var dom = domain.create(); 6 var sock = new net.Socket();
8 7
9 dom.on('error', function (err) { 8 sock.on('error', function (err) {
10 console.log("Cannot connect to " + sockpath + ", rlgwebd already stopped."); 9 console.log("Cannot connect to " + sockpath + ", rlgwebd already stopped.");
11 process.exit(0); 10 process.exit(0);
12 }); 11 });
13 12
14 dom.run(function () { 13 sock.connect(sockpath, function () {
15 var sock = net.connect(sockpath, function () { 14 sock.on('close', function (had_error) {
16 sock.on('close', function () { 15 if (process.argv[2] == "debug")
17 if (process.argv[2] == "debug") 16 console.log("Control socket closed");
18 console.log("Control socket closed");
19 });
20 sock.write("quit\n");
21 }); 17 });
18 sock.write("quit\n");
22 }); 19 });