Simple server restart?

Discussion in 'Spigot Help' started by Fressh, Jun 1, 2018.

  1. Hello, I've been trying to figure out how to schedule a simple "/restart" command from console once every 12 or 24 hours to keep my server fresh but I don't really know how to do that. There's plugins that require you to set up a whole bootloader, but that's not what I'm looking for. Right now my server is in a simple loop:
    Code (Text):
    while [ 5 > 4 ]
    do
            java -Xms4G -Xmx6G -jar paperspigot.jar nogui
            echo
            echo Pausing for 10 seconds.  Press control-c to stop.
            echo
            sleep 10s
    done
     
    That just keeps the server on at all times, but sometimes it will run for days on end and sometimes even crash. The server will start back up but I want to control it to restart more often to avoid that from happening. How can I schedule a simple command from console without using a bootloader or multicraft?
     
  2. You need some sort of wrapper to do that. If you're skilled enough, you can try to make a program that will exit out if the exit code is some special value (that's how my bot updater works).
    Code (Java):
    public static void loop() throws IOException, InterruptedException {
        Process process = new ProcessBuilder(new String[]{"java", "-jar", "server.jar"}).inheritIO().start();
        while(p.isAlive());
        if(process.exitValue() == 0x11) loop();
    }
    And maybe in Spigot
    Code (Java):
    // Shutdown the server first
    Bukkit.getServer().shutdown();

    // Exit with 0x11
    System.exit(0x11);
    Try with a test server first ;)
     
  3. Strahan

    Benefactor

    You can just make a plugin that sends the restart every whatever amount of time, it's pretty simplistic. Though I'd recommend instead stopping the server and letting the batch file/bash script just restart automatically as /reload is not recommended.