Is it possible to set up server shutdown with an alarm system?

Discussion in 'Spigot Plugin Development' started by TurtlesBeast23, Feb 14, 2018.

  1. I have an intermittent alarm in my house that sounds every 2 seconds when the server unexpectedly shuts down and wasn’t aborted by me or an automatic scheduled restart. I have this alarm system set up so that if I’m not in my office, this alerts me that the server needs to be restarted or repaired. Is it possible to set this type of system up with a plugin?

  2. You could try sending information to the server via something then if the "something" cant send the information to the server... alert you some how..
  3. I don't follow, you have a spigot server which sometimes shuts down expectantly and you want to run a plugin on the server which has expectantly shutdown to tell you this has happened? If there is no server running then your plugin is no longer running either.

    If the server is _cleanly_ shutdown then all plugins will get their onDisable() method called so you could use that (checking the current system time against the expected shutdown time(s) so you don't get messages for expected events). However, this will not detect a server which has crashed, you need an external watchdog for that.
  4. The onDisable is called when the server crashes. The exception is if the crash was a JVM problem such as an OutOfMemoryError (pretty rare).
  5. OutOfMemoryError might also be plugin related which is not that rare. Especially with poorly coded plugins.

    @OP I would suggest a plugin which updates a value in a database(like current time) regularly and an external web service could check the value in database regularly and if detects it as not-up-to-date then it can alert you somehow.
    • Agree Agree x 1
  6. Make an alive ping counter. Write a simple plugin with a tick task that sends an "Im alive!" HTTP ping message every 10 seconds - 5 minutes or so to a server the alarm is connected to. When the server stops receiving pings for over 20s - 10min (some room for error) you sound the alarm. Might be good to do it on another thread so it doesn't stall the server by accident, but be aware that the main thread can also stall.

    There is zero use in trying to send a message to the alarm when the server crashes. For all you know the power to the computer goes out because of a fuse tripping or maybe the internet connection to it dies. The only reliable solution is regularly pinging.

    A similar approach is to let the alarm request the last alive time from the server regularly. Then the server is the server, which might be easier to accomplish. Then you need to make sure your alarm's request has a short enough timeout so it doesnt endlessly wait for a response that never comes.

    This can be as simple as writing System.currentTimeMillis() to a .txt file and reading this value regularly over FTP from the alarm software end.
    • Like Like x 1
  7. I am going to try to build a Android app to do this.
  8. Android app might be a good idea. I used to have a skype bot that does the same thing but it died when microsoft killed the skype4com. :(
  9. Discord Bot?
    • Like Like x 2
  10. if you already have a such alert system set up for your server, just use the same system by sending the message to the deamon of your system
  11. Eh, for decades we've had services checks on unix/linux systems.. why not just do the same, who cares if it is apache, mysql or minecraft..

    You can check if a service is running, if something isn't running when expected, just send an SMS.
    Using IFTTT's api you can hook it up to an alarm system if you want lol ..

    It was all easy to setup, and haven't had a false positive yet.
    • Agree Agree x 1
  12. I’ll probably make it so that a server sends information to the Minecraft server every 3 seconds and if it was manually aborted by me or an automatic restart, there will be a registry key AbortedExpectedly which will be set to 1, but if it’s set to 0, that means the server crashed or shutdown unexpectedly and will signal the alarm to sound.
    #14 TurtlesBeast23, Feb 17, 2018
    Last edited: Feb 17, 2018
  13. just use unix tool to monitor log, that would be the simplest way.
  14. we usually use various automated logfile monitor on our unix/linux system. you can do the same for minecraft logs.
  15. We have a slightly customized version of Spigot that submits the log to a server rather than to a local file so that we can view the log in the Administration Panel.
  16. that's fine you can stll use a commonly used log file monitor.

Share This Page