annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
193
80ca029f0906 Add a script to stop RLGWebD.
John "Elwin" Edwards
parents:
diff changeset
1 #!/usr/bin/env node
80ca029f0906 Add a script to stop RLGWebD.
John "Elwin" Edwards
parents:
diff changeset
2
80ca029f0906 Add a script to stop RLGWebD.
John "Elwin" Edwards
parents:
diff changeset
3 var net = require('net');
194
5483d413a45b RLGWebD: move the control socket into /var/run.
John "Elwin" Edwards
parents: 193
diff changeset
4 var sockpath = "/var/run/rlgwebd.sock";
193
80ca029f0906 Add a script to stop RLGWebD.
John "Elwin" Edwards
parents:
diff changeset
5
207
ffe22d88bea1 rlgwebd-stop: avoid the deprecated domain module.
John "Elwin" Edwards
parents: 200
diff changeset
6 var sock = new net.Socket();
200
a7cc38a0168d Actually restart RLGWebD if it crashes.
John "Elwin" Edwards
parents: 195
diff changeset
7
207
ffe22d88bea1 rlgwebd-stop: avoid the deprecated domain module.
John "Elwin" Edwards
parents: 200
diff changeset
8 sock.on('error', function (err) {
200
a7cc38a0168d Actually restart RLGWebD if it crashes.
John "Elwin" Edwards
parents: 195
diff changeset
9 console.log("Cannot connect to " + sockpath + ", rlgwebd already stopped.");
a7cc38a0168d Actually restart RLGWebD if it crashes.
John "Elwin" Edwards
parents: 195
diff changeset
10 process.exit(0);
a7cc38a0168d Actually restart RLGWebD if it crashes.
John "Elwin" Edwards
parents: 195
diff changeset
11 });
a7cc38a0168d Actually restart RLGWebD if it crashes.
John "Elwin" Edwards
parents: 195
diff changeset
12
207
ffe22d88bea1 rlgwebd-stop: avoid the deprecated domain module.
John "Elwin" Edwards
parents: 200
diff changeset
13 sock.connect(sockpath, function () {
ffe22d88bea1 rlgwebd-stop: avoid the deprecated domain module.
John "Elwin" Edwards
parents: 200
diff changeset
14 sock.on('close', function (had_error) {
ffe22d88bea1 rlgwebd-stop: avoid the deprecated domain module.
John "Elwin" Edwards
parents: 200
diff changeset
15 if (process.argv[2] == "debug")
ffe22d88bea1 rlgwebd-stop: avoid the deprecated domain module.
John "Elwin" Edwards
parents: 200
diff changeset
16 console.log("Control socket closed");
193
80ca029f0906 Add a script to stop RLGWebD.
John "Elwin" Edwards
parents:
diff changeset
17 });
207
ffe22d88bea1 rlgwebd-stop: avoid the deprecated domain module.
John "Elwin" Edwards
parents: 200
diff changeset
18 sock.write("quit\n");
193
80ca029f0906 Add a script to stop RLGWebD.
John "Elwin" Edwards
parents:
diff changeset
19 });