Restart or Shutdown the server from script/code?

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
Restart or Shutdown the server from script/code?
« on February 6th, 2015, 12:13 PM »Last edited on February 6th, 2015, 12:36 PM
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

  • Jr. Member
  • KP
  • Posts: 66
With regards,
KP
------------------------------------------

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
.

Fuzzie

  • Jr. Member
  • Posts: 83
Re: Restart or Shutdown the server from script/code?
« Reply #3, on February 6th, 2015, 05:18 PM »Last edited on February 6th, 2015, 05:19 PM
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.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
Re: Restart or Shutdown the server from script/code?
« Reply #4, on February 6th, 2015, 05:24 PM »
Quote from Fuzzie on February 6th, 2015, 05:18 PM
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. 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

  • VC:MP Developer
  • oh god how did i get here im not good w computer
  • Posts: 1,088
Re: Restart or Shutdown the server from script/code?
« Reply #5, on February 6th, 2015, 07:18 PM »
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.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
Re: Restart or Shutdown the server from script/code?
« Reply #6, on February 6th, 2015, 08:07 PM »
Quote from stormeus on February 6th, 2015, 07:18 PM
If 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

  • VC:MP Beta Tester
  • Posts: 1,689
Re: Restart or Shutdown the server from script/code?
« Reply #7, on February 6th, 2015, 09:26 PM »
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.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,801
.