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,
|
||||
"pubport": 80,
|
||||
"page404": "404.html",
|
||||
"timestamp": 1691613309162,
|
||||
"timestamp": 1691622823922,
|
||||
"blacklist": [],
|
||||
"nonStandardCodes": [],
|
||||
"enableCompression": true,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
</style>
|
||||
</head>
|
||||
<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;">
|
||||
<b style="font-size: 20pt">WARNING!</b><br/>
|
||||
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 = {
|
||||
close: function () {
|
||||
try {
|
||||
if(server.listening || server2.listening) {
|
||||
server.close();
|
||||
if (secure && !disableNonEncryptedServer) {
|
||||
server2.close();
|
||||
}
|
||||
} else {
|
||||
throw new Error("Server is already closed.");
|
||||
}
|
||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server closed.");
|
||||
else {
|
||||
process.send("Server closed.");
|
||||
|
@ -4788,12 +4792,16 @@ function start(init) {
|
|||
},
|
||||
open: function () {
|
||||
try {
|
||||
if(!server.listening) {
|
||||
if (secure) {
|
||||
server.listen(sport);
|
||||
if (!disableNonEncryptedServer) server2.listen(port);
|
||||
} else {
|
||||
server.listen(port); // Reopen Server
|
||||
}
|
||||
} else {
|
||||
throw new Error("Server is already opened.");
|
||||
}
|
||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server opened.");
|
||||
else {
|
||||
process.send("Server opened.");
|
||||
|
@ -4821,11 +4829,47 @@ function start(init) {
|
|||
},
|
||||
stop: function (retcode) {
|
||||
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") {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
} 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 () {
|
||||
console.clear();
|
||||
|
@ -4915,8 +4959,11 @@ function start(init) {
|
|||
}
|
||||
process.send("\x12END");
|
||||
} else if (line == "\x14KILLPING") {
|
||||
if(!reallyExiting) {
|
||||
process.send("\x12KILLOK");
|
||||
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") {
|
||||
if(reqcounter - reqcounterKillReq < 2) {
|
||||
process.send("\x12KILLTERMMSG");
|
||||
|
|
Reference in a new issue