0

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 enter image description here

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 enter image description here

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?

arthurgps2
  • 101
  • 1
  • 7
  • Do you know if something keep block the server stop ? like a world save or something ? Also, what is `mcserver` ? From which dependency does it come ? – Elikill58 Sep 30 '22 at 08:17
  • If you mean something is keeping the server from stopping, then no as far as I know. Also `mcserver` is an object in the code containing all info from the server, such as the server directory, whether it's running or not, its ip and its spawn process. – arthurgps2 Sep 30 '22 at 17:06
  • Are you sure that the server expects and handles the kill signal? – Bergi Oct 04 '22 at 23:04
  • Sorry for the long time without an answer. I just realized something that might help, though I still couldn't figure this out fully. Please read my edit on the question. – arthurgps2 Oct 31 '22 at 06:05

0 Answers0