Restart or Shutdown the server from script/code?

Started by ., Feb 06, 2015, 12:13 PM

Previous topic - Next topic

.

Probably the title says more then enough. How can someone restart or shutdown the server from Squirrel script or C/C++ code?

PS: I'm not talking about the Reload_Scripts functionality. I want to be able to literally restart and shutdown the server.
.

karan20000000000

#1
Most probably onScriptUnload(); function may do it unless you aren't using a restarter with your server.
With regards,
KP
------------------------------------------

.

Quote from: karan20000000000 on Feb 06, 2015, 04:35 PMMost probably onScriptUnload(); function may do it unless you aren't using a restarter with your server.

That's an event listener :-\ I don't see any use for it in this case.
.

Fuzzie

#3
Creating a C++ module that runs a batch/shell file then terminates itself/the server seems to be the only way I can think of. The batch/shell file contains a command that runs the server. It might require some sort of delay or loop to check if the server process has been terminated but don't quote me cause I've never actually worked with batch nor shell before.

.

Quote from: Fuzzie on Feb 06, 2015, 05:18 PMCreating a C++ module that runs a batch/shell file then terminates itself/the server seems to be the only way I can think of. In the batch/shell file, run the server. It might require some sort of delay or loop to check if the server process has been terminated but don't quote me cause I've never actually worked with batch nor shell before.

Not very cross platform. But to be honest. How does one close/shutdown a VC:MP server? I've always been wondering that. I've always closed them by force so far because I didn't saw any other alternatives for it.

For example there's the system() function which allows you to execute a cmd on the system as if you would from a terminal. But I haven't seen any cmds to close the server or any ways for that mater.
.

Stormeus

You can technically make the server exit by causing it to crash, for example by creating a timer with an instance (like Player or Object) in Squirrel. This isn't recommended as bugfixes can break this. If this is something important, then do that, and I'll just add an API call that allows the server to exit gracefully.

Automatically restarting the server is less trivial to get working cross-platform. If you have an auto-restart script set up, the server would automatically restart after closing anyway.

.

Quote from: stormeus on Feb 06, 2015, 07:18 PMIf this is something important, then do that, and I'll just add an API call that allows the server to exit gracefully.

I'll be waiting for that feature then stormeus. I was working on something like a "control panel" that would emit commands to an SQLite database through web-interface to be interpreted and execued by either a module or script. And a restart or shutdown command would be nice to have. Anyway, thanks for the information and I'll be waiting for those functions in the plugin API.
.

Thijn

I've noticed the linux server doesn't have a way to exit gracefully. Sending a SIGTERM just closes it, without calling the unload or onServerShutdown signals. Using ctrl+c or sending a SIGINT doesn't do it either.
Entering quit, exit, close or anything like that in the console window doesn't do anything.

On windows ctrl+c or closing the console window seems to work, though. At least it gives a "Server shutting down" message.

.

Quote from: Thijn on Feb 06, 2015, 09:26 PMOn windows ctrl+c or closing the console window seems to work, though. At least it gives a "Server shutting down" message.

Sometimes! Depending on the loaded modules and/or scripts you might not get that callback notification. At least that's what I've noticed.
.