Spigot Restart script help.

Discussion in 'Spigot Discussion' started by ahammers, Jun 25, 2016.

Thread Status:
Not open for further replies.
  1. When I do /restart the console disappear? :// How could i get it to not?
     
    • Like Like x 1
  2. Make sure that your spigot.yml is pointing to the script you use to start the server.

    Here's what I use on my localhost Windows server:


    From spigot.yml
    Code (Text):
      restart-script: ./start.bat

    start.bat
    Code (Text):
    @echo off

    java -Xms512M -Xmx1G -jar spigot-server.jar
    pause
     
  3. electronicboy

    IRC Staff

    You'll wanna make your startup script start a screen session and run the server inside that
     
  4. My run file that opens the console and runs the server looks like this:

    Code (Text):
    @ECHO OFF
    title Hub
    color 07
    cls
    :start
    java -Xmx5G -Xms1G -jar spigot-1.9.2.jar -o false
    goto start
    The "title" and "color" and "cls" are not necessary, they are cosmetic.
    However, if you use
    Code (Text):
    @ECHO OFF
    :start
    java -Xmx5G -Xms1G -jar spigot-1.9.2.jar -o false
    goto start
    Then every time the server stops, it restarts it again. Then, instead of "/restart", use "/stop". It does exactly the same thing.
     
  5. If your using a Minecraft server host that only gives you access through some control panel then your options are limited. If your running it on your own system, though, or a system you have full access to (access to all the files, the system terminal, etc), then you can modify and create scripts for linux to run.

    If that is the case you probably already have a startup script. You could simply tell your restart plugin the location and name of that script. Then, when you do the command it will close the server and trigger that script.

    Another thing you could do, and I recommend, is to modify your startup script to run the server in a screen. By doing this you can close your terminal, do other things on the computer, and your server will still run unattended.

    Here is my startup script:

    Code (Text):
    #!/bin/sh
    screen -dmS server java -server -Xms5G -Xmx5G -jar spigot-1.10.2.jar
     
    The "screen -dmS server" part creates a new screen named server that is detached by default. This means it is running in background and you won't see it. The next part should be familiar to you, it just says that within the screen it should run "java -server -Xms5G -Xmx5G -jar spigot-1.10.2.jar" which starts the server.

    To attach to a screen you type "screen -r" into your terminal. You can put the name if you have more than one. The name, however, is more for scripts you will create that connect to it. To disconnect to a screen hit CTRL+D to detach.

    Now, with your server running in a screen you can create a script that closes your server and then runs the startup script. Here is the code you need:

    Code (Text):
    #!/bin/sh
    screen -s server -X stuff "stop"
    screen -s server -X eval "stuff \015"
    sleep 15
    cd <path to the folder your startup script is stored in>
    ./start.sh
     
    You will need to replace ./start.sh with whatever your startup script is named. You can add additional commands as well following the same format, so that you can have warning messages and kick people before it actually closes. Here is a more advanced one:

    Code (Text):
    #!/bin/sh
    screen -s server -X stuff "broadcast &cServer rebooting in 3 minutes."
    screen -s server -X eval "stuff \015"
    sleep 60
    screen -s server -X stuff "broadcast &cServer rebooting in 2 minutes."
    screen -s server -X eval "stuff \015"
    sleep 60
    screen -s server -X stuff "broadcast &cServer rebooting in 1 minute."
    screen -s server -X eval "stuff \015"
    sleep 60
    screen -s server -X stuff "broadcast &cServer rebooting..."
    screen -s server -X eval "stuff \015"
    screen -s server -X stuff "kickall Rebooting. Please reconnect in one minute."
    screen -s server -X eval "stuff \015"
    sleep 5
    screen -s server -X stuff "stop"
    screen -s server -X eval "stuff \015"
    sleep 15
    cd <path to the folder your startup script is stored in>
    ./start.sh
     
    Now you can activate this script by running it manually, clicking on it if you save it to your desktop or something, or find a plugin to run it with a command.

    Finally, if you want to have automatic reboots you can use a cron job. You should look this up on your own. Basically, you tell linux to run the script (or anything really) at a specific time, day, month, etc. (Every day at midnight maybe?)
     
    • Winner Winner x 3
    • Informative Informative x 2
    • Useful Useful x 1
Thread Status:
Not open for further replies.