Sequential execution of stopping servers

This commit is contained in:
ziajka
2019-02-07 16:02:25 +01:00
parent 06bda9fc79
commit 7410455bdf

View File

@ -9,23 +9,31 @@ function getServerArguments(server, overrides) {
} }
async function stopAll() { async function stopAll() {
Object.keys(runningServers).forEach(async (serverName) => { for(var serverName in runningServers) {
await stop(serverName); let result, error = await stop(serverName);
}); }
console.log(`Stopped all servers`);
} }
async function stop(serverName) { async function stop(serverName) {
const runningServer = runningServers[serverName]; const runningServer = runningServers[serverName];
const pid = runningServer.process.pid; const pid = runningServer.process.pid;
console.log(`Stopping '${serverName}' with PID='${pid}'`); console.log(`Stopping '${serverName}' with PID='${pid}'`);
kill(pid, (error) => {
if(error) { const stopped = new Promise((resolve, reject) => {
console.error(`Error occured during stopping '${serverName}' with PID='${pid}'`); kill(pid, (error) => {
} if(error) {
else { console.error(`Error occured during stopping '${serverName}' with PID='${pid}'`);
console.log(`Stopped '${serverName}' with PID='${pid}'`); reject(error);
} }
else {
console.log(`Stopped '${serverName}' with PID='${pid}'`);
resolve(`Stopped '${serverName}' with PID='${pid}'`);
}
});
}); });
return stopped;
} }
async function run(server, options) { async function run(server, options) {