This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
WarpedJester's profile picture

Set triggers to monitor for server stop/start

Started by WarpedJester, 19 January 2015 - 09:25 PM
WarpedJester #1
Posted 19 January 2015 - 10:25 PM
I am going to start by saying that this is my first real dive into ComputerCraft and programming in general (IT monkey by trade) so forgive me if i use the wrong terms or ask a dumb question.

I am looking into ComputerCraft as a possible solution to a problem we are having with our server.

ENVIROMENT:
Our server is a heavily modded server built around remote cities connected via rail lines to move goods and utilities to and from the Hub city (spawn). our server has no teleportation (ender chests, tesseract, etc) by design so our rail service is vital to our world. The server is set to reboot once per day if no one is on (so no set time). This helps with server stability.

ISSUE:
When the server is rebooted, any trains from RailCraft that are on train holding tracks or switch tracks become stuck or messed up (split, tangled, etc) which can completely shut down our system due to blocking the main rail lines.

POSSIBLE SOLUTION:
At this point I have set up a rail yard and a manual switch that will divert all trains to the rail yard and park them, at which point I can reboot the server then send all the trains back out (about 20 trains in total).

THE QUESTION:
Is there a trigger or hook that ComputerCraft can tie in to to know when the server is going to be rebooting so that it can trigger the trains to the rail yard. Additionally is there a way to have ComputerCraft fire back up after server reboot and be able to release all the trains. This would allow me to get the server back to a fully automated reboot cycle so i am not chewing up my time doing the manual service daily.

Thank you in advance for any input.
Lyqyd #2
Posted 19 January 2015 - 11:38 PM
If you are the server administrator, and are running a custom script outside of the game to manage restarting the server, you have at least one option. If you are not, you really don't have any options.

For a server administrator that wants to do this, you'd have your server management script place a file inside one of the computers' "hard drive" a couple minutes before it restarts. The computer would be running a program to check for the existence of this file every thirty seconds or so. When it sees the file, it diverts the trains. When the computer is booted, if this file is present, it resets the trains and sends them out, then deletes the file.

There is no built-in way to see a server shutdown coming, or to know the difference between being booted up because the server started or because the chunk loaded for another reason, so workarounds like the above are about the only options available.
WarpedJester #3
Posted 20 January 2015 - 12:34 AM
Ok good deal, i am the server admin so this sounds like i have options. The chunk that the computercraft system is in is chuck loaded so that is not a issue. additionally if for any reason the system glitched or got confused and thought he server just came back up, it would not matter. ether the trains are there to release or they are not.

Oddly enough i would have though there would have been a ability for computercraft to monitor game chat and be able to see a "server restart in…" and been able to use that as a means to a trigger.

Thanks for the input on the file detection options. now i just need to find a how=to or code sample on how to do it.
Lyqyd #4
Posted 20 January 2015 - 12:41 AM
Ah, yes, there are peripherals that can monitor in-game chat, if you have those extra mods installed.

A loop that looks for the existence of a file looks something like:


while true do
  if fs.exists("/path/to/file") then
    fileExists()
  else
    itDoesNot()
  end
  sleep(30)
end
civilwargeeky #5
Posted 21 January 2015 - 02:30 AM
If you were curious exactly what peripherals can monitor chat, there is the chatbox from peripherals++. If you do choose this, you can learn about events here.
Hopefully you can get the shutdown plugin to work though, because that will likely be easier for everyone involved :)/>