forked from svrjs/svrjs
Make SVR.JS gracefully exit on "stop" command.
This commit is contained in:
parent
08cc0ac042
commit
3d4acae311
3 changed files with 61 additions and 14 deletions
|
@ -3,7 +3,7 @@
|
||||||
"port": 80,
|
"port": 80,
|
||||||
"pubport": 80,
|
"pubport": 80,
|
||||||
"page404": "404.html",
|
"page404": "404.html",
|
||||||
"timestamp": 1691613309162,
|
"timestamp": 1691622823922,
|
||||||
"blacklist": [],
|
"blacklist": [],
|
||||||
"nonStandardCodes": [],
|
"nonStandardCodes": [],
|
||||||
"enableCompression": true,
|
"enableCompression": true,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Welcome to SVR.JS Nightly-GitMaster</h1>
|
<h1>Welcome to SVR.JS Nightly-GitMain</h1>
|
||||||
<div style="background-color: #ff0; border-color: #f70; border-width: 5px; border-style: solid; padding: 5px; display: inline-block;">
|
<div style="background-color: #ff0; border-color: #f70; border-width: 5px; border-style: solid; padding: 5px; display: inline-block;">
|
||||||
<b style="font-size: 20pt">WARNING!</b><br/>
|
<b style="font-size: 20pt">WARNING!</b><br/>
|
||||||
This version is only for test purposes and may be unstable.
|
This version is only for test purposes and may be unstable.
|
||||||
|
|
47
svr.js
47
svr.js
|
@ -4772,10 +4772,14 @@ function start(init) {
|
||||||
var commands = {
|
var commands = {
|
||||||
close: function () {
|
close: function () {
|
||||||
try {
|
try {
|
||||||
|
if(server.listening || server2.listening) {
|
||||||
server.close();
|
server.close();
|
||||||
if (secure && !disableNonEncryptedServer) {
|
if (secure && !disableNonEncryptedServer) {
|
||||||
server2.close();
|
server2.close();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Server is already closed.");
|
||||||
|
}
|
||||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server closed.");
|
if (cluster.isPrimary === undefined) serverconsole.climessage("Server closed.");
|
||||||
else {
|
else {
|
||||||
process.send("Server closed.");
|
process.send("Server closed.");
|
||||||
|
@ -4788,12 +4792,16 @@ function start(init) {
|
||||||
},
|
},
|
||||||
open: function () {
|
open: function () {
|
||||||
try {
|
try {
|
||||||
|
if(!server.listening) {
|
||||||
if (secure) {
|
if (secure) {
|
||||||
server.listen(sport);
|
server.listen(sport);
|
||||||
if (!disableNonEncryptedServer) server2.listen(port);
|
if (!disableNonEncryptedServer) server2.listen(port);
|
||||||
} else {
|
} else {
|
||||||
server.listen(port); // Reopen Server
|
server.listen(port); // Reopen Server
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Server is already opened.");
|
||||||
|
}
|
||||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server opened.");
|
if (cluster.isPrimary === undefined) serverconsole.climessage("Server opened.");
|
||||||
else {
|
else {
|
||||||
process.send("Server opened.");
|
process.send("Server opened.");
|
||||||
|
@ -4821,11 +4829,47 @@ function start(init) {
|
||||||
},
|
},
|
||||||
stop: function (retcode) {
|
stop: function (retcode) {
|
||||||
reallyExiting = true;
|
reallyExiting = true;
|
||||||
|
if((!cluster.isPrimary && cluster.isPrimary !== undefined) && server.listening) {
|
||||||
|
try {
|
||||||
|
server.close(function() {
|
||||||
|
if(server2.listening) {
|
||||||
|
try {
|
||||||
|
server2.close(function() {
|
||||||
if (typeof retcode == "number") {
|
if (typeof retcode == "number") {
|
||||||
process.exit(retcode);
|
process.exit(retcode);
|
||||||
} else {
|
} else {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} catch(err) {
|
||||||
|
if (typeof retcode == "number") {
|
||||||
|
process.exit(retcode);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (typeof retcode == "number") {
|
||||||
|
process.exit(retcode);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch(err) {
|
||||||
|
if (typeof retcode == "number") {
|
||||||
|
process.exit(retcode);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (typeof retcode == "number") {
|
||||||
|
process.exit(retcode);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
clear: function () {
|
clear: function () {
|
||||||
console.clear();
|
console.clear();
|
||||||
|
@ -4915,8 +4959,11 @@ function start(init) {
|
||||||
}
|
}
|
||||||
process.send("\x12END");
|
process.send("\x12END");
|
||||||
} else if (line == "\x14KILLPING") {
|
} else if (line == "\x14KILLPING") {
|
||||||
|
if(!reallyExiting) {
|
||||||
process.send("\x12KILLOK");
|
process.send("\x12KILLOK");
|
||||||
process.send("\x12END");
|
process.send("\x12END");
|
||||||
|
}
|
||||||
|
// Refuse to send, when it's really exiting. Main process will treat the worker as hung up anyway...
|
||||||
} else if (line == "\x14KILLREQ") {
|
} else if (line == "\x14KILLREQ") {
|
||||||
if(reqcounter - reqcounterKillReq < 2) {
|
if(reqcounter - reqcounterKillReq < 2) {
|
||||||
process.send("\x12KILLTERMMSG");
|
process.send("\x12KILLTERMMSG");
|
||||||
|
|
Reference in a new issue