Shutdown server when Memory is low

Discussion in 'Archived: Plugin Requests' started by TehSkull, Aug 28, 2011.

  1. Offline

    TehSkull

    My server has been having a lot of out of memory errors lately, and I was wondering if there was a way to have the server shut down when it reaches a certain amount of memory, or only has a certain amount left.

    Possible?
     
  2. Offline

    chernobyl360

    im not sure if this is possible. ill take a look into it though!
     
  3. Offline

    Haloflooder

    It's possible! There is a plugin called MemMonitor. It tells you on the console about your memory. it tells you Max Memory, Total Memory, Free Memory, Used Memory, and how many memory the players use. Maybe there is a way to use that?
     
  4. Offline

    chernobyl360

    link please? i cannot find this " plugin "
     
  5. Offline

    Haloflooder

  6. Offline

    Haloflooder

    Bump
    I really need this plugin. lol
     
  7. Offline

    MuisYa

    @Haloflooder Hmmm, i never worked with this API.
    What should it do excactly? Shut it down forever?
     
  8. Offline

    TehSkull

    Our .bat is set up to auto-restart after 5 seconds, so it doesn't matter if the plugin restarts it or just stops it.
     
  9. Offline

    McSpazzy

    plugin.getServer().dispatchCommand(player, "stop");
     
    TehSkull likes this.
  10. Offline

    MuisYa

    @TehSkull Oke, i will make it tonight.
    And thanks to @McSpazzy for that little part, that helped me alot dude!

    @TehSkull I could also just kick all players? Maybe that is better or not?
    I will first make the "Stop" thingie.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  11. Offline

    TehSkull

    I'd prefer a full stop. :p Thanks though.
     
  12. Offline

    MuisYa

    @TehSkull Oke, working on it right now.

    @TehSkull Oke, it is working right now!
    Download it here,

    Features:
    • Checking RAM every minute.
    • If it is to high, Kicking all players.
    • RAM amount is configurable in a config.

    @TehSkull I made it kick all players, because i couldnt find the API for "Stopping'' a server, if someone knows it.. Please tell me!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  13. I would decompile and recompile your .jar, but I don't want to be rude.
    Turn
    (line 39?)
    Code:
            if (usingMemory > Main.this.maxRam.intValue()) {
              for (Player playersOnline : Main.this.getServer().getOnlinePlayers()) {
                playersOnline.kickPlayer("Server is rebooting, was using to much RAM.");
              }
    into
    Code:
            if (usingMemory > Main.this.maxRam.intValue()) {
              for (Player playersOnline : Main.this.getServer().getOnlinePlayers()) {
                playersOnline.kickPlayer("Server is rebooting, was using to much RAM.");
    plugin.getServer().dispatchCommand(player, "stop");
    
              }
    May have to import a few more classes, I just glanced over the code. That should work. (Thank McSpazzy for the snippet.) I would also suggest making the checking time (1 minute) into a configurable seconds value in your properties file.
     
  14. Offline

    MuisYa

    Ah well, @Chlikikijleelgus
    I tried that little thingie to, but it doesnt work since "Player" is not defined, and when i do it for playersOnline, it wont work either.

    And i cant just make someone, since the console is performing the Stop...
    How did you decompile it btw?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  15. Offline

    TehSkull

    Could you perhaps make "Player" something changeable in your config file? Like I could put an operator's username and it acts as though an operator used the /stop command?
    (Surely there's a better way, but that's the first that comes to mind.)
    As for how he decompiled it, it's probably because you didn't obfuscate the code. If you don't, anyone can decompile it.
     
  16. Offline

    MuisYa

    @TehSkull What? Its just a .jar, I mean what program did he use for that.
    And i cant do a random player,
    SOMEONE GIVE ME THE STOP CODE D:
     
  17. Offline

    TehSkull

    @MuisYa He used Java Decompiler to decompile your Java. :p
     
  18. Offline

    MuisYa

    @TehSkull How do you know? Download link? :3
    And how can i protect that? Not that im going to...
     
  19. Offline

    McSpazzy

    Its java...the best you can do is obfuscation.
     
  20. Offline

    MuisYa

    How? I know it gets transferred in Byte's but how to protect it?
     
  21. Offline

    McSpazzy

    Why would you want to protect it...what are you hiding?
     
  22. Offline

    TehSkull

    Shouldn't Bukkit plugins be open-source anyway? o__o
     
  23. Offline

    McSpazzy

    Well they don't have to be 'open' source, but I don't see any point in trying to hide it. I always provide source for my plugins if requested, but I don't normally publish it.
     
  24. Offline

    MuisYa

    @McSpazzy Im not gonna use it for bukkit, but im coding programms for schools.
    To learn kids calculating, so i do need it for that, hahaha.
     
  25. Offline

    McSpazzy

    @MuisYa Well java is retardedly insecure. Really the only option you have is to obfuscate your code. But then smart people can still figure it out, that's how all these minecraft mods exist.
     
  26. Offline

    MuisYa

    @McSpazzy Thats why im wondering, what is obfuscating youre code?
     
  27. Offline

    McSpazzy

    @MuisYa Refactoring the source and giving all the functions and variables arbitrary/random names.
     
  28. Offline

    MuisYa

    @McSpazzy Thats why Minecraft.jar his classes is having names like: "ap.class"
    And when you decompile it with MCP it got normal names :D

    @TehSkull New download link: Here.
    Corrected some spelling mistakes,

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  29. Offline

    muCkk

  30. Offline

    MuisYa

Share This Page