I've already got a Minecraft server running via Node.js, now the issue is getting it to close. When I add a callback method to the exit
event and call kill()
on the server process...
// Create server process
mcserver.process = spawn("java", [
"-Xmx1024M",
"-Xms1024M",
"-jar",
"server.jar",
"nogui"],
{
cwd: mcserver.dir,
}
);
mcserver.process.on("exit", () => {
console.log("minecraft server exit lol");
});
// Happens somewhere else in the code
mcserver.process.kill();
The method is executed, but for some reason the server doesn't really close, in fact it keeps running as if nothing happened.
UPDATE: Messing around with Task Manager open, I found this out:
The moment the Minecraft server is created, I see those two new processes pop up
one of them uses way more RAM than the other so it's safe to assume that's the actual Minecraft server running there, however I'm not sure what the other process would be.
After I kill()
the process in the code, one of the processes vanish
but as you can see, it's not the Minecraft server. So basically I'm creating the server process just fine, but the moment I try to kill it, instead it kills the wrong process and the server keeps running.
UPDATE again: Okay I just found out the correct way to stop a Minecraft server is by sending "/stop" to the server as a shell command. Now how am I supposed to do that?