Problem with the Spigot restart script

Discussion in 'Spigot Discussion' started by levisn1, May 13, 2013.

Thread Status:
Not open for further replies.
  1. Hello, i have some problem to set up my restart.sh. My target is that when i do /restart in-game, the server auto-reboot itself. So i created a restart.sh file and putted in my spigot.jar forlder, and in the bukkit.yml:
    restart-on-crash: false
    restart-script-location: /home/test/restart.sh

    I found this restart script here in an other post:

    #!/bin/bash
    java -Xms4096M -Xmx4096M -jar spigot.jar

    When i do /restart in game it just stop and don't reboot. I also did chmod +x restart.sh but if i do ls the file restart.sh is not green. I use this server in a screen called "test" if can help. Somebody can tell me how can i do it works good? Thanks.
     
    • Agree Agree x 1
    • Informative Informative x 1
  2. joehot200

    Supporter

    Unable to help you, however, if you make this your start script:
    (edit: removed -XX:+UseConcMarkSweepGC -XX:+UseParNewGC)

    # /bin/sh
    while true
    do
    java -d64 -jar Xms4096M - Xmx4096M -jar spigot.jar nogui
    pkill -f "craftbukkit" #Not really needed, just there in case of anything.
    echo Its off..sleeping for 5
    sleep 5
    done
    Then your server should automatically start up after 5 seconds after using /stop.
    You can then press control+c to quit the server.
     
    • Like Like x 2
  3. chmod 777 restart.sh
     
    • Optimistic Optimistic x 1
  4. If i do it will works??
     
  5. I created a new file called restart.sh with this into:

    # /bin/sh
    while true
    do
    java -Xms4096M -Xmx4096M -jar craftbukkit.jar
    pkill -f "craftbukkit" #Not really needed, just there in case of anything.
    echo Its off..sleeping for 5
    sleep 5
    done

    and i did on it
    chmod 777 restart.sh
    here my logs:
    http://pastebin.com/ipuwMQvF

    As you can see when i try to do /restart it say:

    2013-05-13 19:01:56 [INFO] Attempting to restart with /home/test/restart.sh
    2013-05-13 19:01:56 [INFO] Stopping server

    But after my server still remain stopped..thanks in advance for help.
     
    • Informative Informative x 1
  6. joehot200

    Supporter

    Well with my start script /stop will successfully restart it, instead of /restart. Try /stop (note this is for START script) and if it works, make a plugin that blocks /restart and makes it so they use /stop instead.
     
  7. Even with /stop, it only stop it. I want use the restart sistem of spigot. I don't need to start the server with a script, i only need a script that works and and that reboot the server when someone execute from console or in-game, doesn't matter, the command /restart, or /stop..the important thing is that it reboot the server.
     
    • Agree Agree x 1
  8. joehot200

    Supporter

    Well you just use it as the startup script but with added extra auto-restartiness.
     
  9. The problem is that i don't know how to do it xD...i usually start my server with a simple command line...not an sh file or a service..really my knowledge is 0 for this kind of things.
     
    • Friendly Friendly x 1
  10. joehot200

    Supporter

    You know you use this:
    Code (Text):

    java -Xms4096M -Xmx4096M -jar spigot.jar
     
    As your startup script?

    Just change it to this:
    Code (Text):

    # /bin/sh
    while true
    do
    java -Xms4096M -Xmx4096M -jar craftbukkit.jar
    pkill -f "craftbukkit" #Not really needed, just there in case of anything.
    echo Its off..sleeping for 5
    sleep 5
    done
     
    As you can see, here (java -Xms4096M -Xmx4096M -jar craftbukkit.jar) is your startup line. Then before that, you have while true
    do

    This just means that as long as the script is running, it will do that line after it (java -Xms4096M -Xmx4096M -jar craftbukkit.jar)

    echo Its off..sleeping for 5
    sleep 5
    done

    And finally, this just makes the whole server sleep 5 seconds before restarting.

    So literally, just make that your startup script. Do nothing else.
     
  11. ok, just out of curiosity how do you start? if I'm not mistaken. / restart.sh right?
    However this not solve my problem of the restart :/
     
  12. joehot200

    Supporter

    this is a start.sh or a run.sh.

    So yes it does because /stop will then just restart the server.

    Also, if you put an invalid path to the restart script, the server should automatically shut down - hence activating the script, and restarting!
     
  13. You don't understand me...there a simple scrits somewhere that can do what i need? Just restart the server on /restart or /stop? xD this is my only one target...sorry..
     
  14. The script that joehot200 is offering is a script that you would use instead of your start.sh script, and what it does is restart your server when it is shut down in any way (not just when using /restart). If you use that script to start up then there will be no way to stop the server and not have it restart (unless you force kill it which is not good for it).

    I think the reason /restart isn't working is that whatever is started inside the restart script is stopped when the server finally shuts down.

    If you want to still have console access after the restart, then try installing screen then having a restart script like this:
    Code (Text):
    #!/bin/bash
    screen -dmS mcserver java -Xms4096M -Xmx4096M -jar spigot.jar
    That will create a new screen after the restart that can be accessed with the command:
    Code (Text):
    screen -dr mcserver

    Or if you don't care about console then this restart script should work:
    Code (Text):
    #!/bin/bash
    (sleep 5 && java -Xms4096M -Xmx4096M -jar spigot.jar)&
    The & tells bash to detach this process from the current session, so it should work, although when using this method there is no way to access the console of the restarted server.

    When using either of these restart scripts you do not need to edit your start script at all.

    Though if you do install screen then I suggest that you use this to start your server (Though this is just an extra I like, you do not need this in any way):
    Code (Text):
    #!/bin/bash
    screen -mS mcserver java -Xms4096M -Xmx4096M -jar spigot.jar
    That last script will allow you to access your server through the above mentioned script:
    Code (Text):
    screen -dr mcserver
    When it isn't restarted.

    When using SCREEN to start/restart your server, you can use the key combo ctrl+a then d in order to escape the screen session. (It will leave your server running but the terminal doesn't have to be open)

    Also you WILL need to chmod +x any scripts that you create.
    For a restart script I would do 'chmod +x restart.sh'
    replacing 'restart.sh' with the name of your restart script.
     
    #14 daboross, May 13, 2013
    Last edited: May 13, 2013
    • Useful Useful x 5
    • Like Like x 2
    • Agree Agree x 1
  15. Thanks now all works :) i find this script...and when do /stop it auto restart my server after 5second...

    what i still don't understand...is how this script recognize the command Stop, than reexecute the command

    java -Xmx4G -Xms4G -jar craftbukkit.jar..how it works exactly?

    #!/bin/sh
    while true
    do
    java -Xmx4G -Xms4G -jar craftbukkit.jar
    echo "If you want to completely stop the server process now, press Ctrl+C before
    the time is up!"
    echo "Rebooting in:"
    for i in 5 4 3 2 1
    do
    echo "$i..."
    sleep 1
    done
    echo "Rebooting now!"
    done
     
  16. joehot200

    Supporter

    Umm thats exactly what the script i was giving you did xD

    Anyways, what it is, its a while loop, so its like, while "true" (so basically while the machine is running) it will run java. When its finished doing that, it will sleep for 5 seconds, It will then go to the bottom of the script - but wait no, because there is the "while" loop. So while the machine is running - run the server. The server then starts up again.
     
  17. Ahh now i understand :) really thanks :) i hope this post will help somebody with my problems xP
     
    • Like Like x 2
    • Agree Agree x 1
  18. but how do i fix that the windows is standing open
     
  19. Dmck2b

    Services Staff

    Why necro and what do you mean?

    If you;re seriously complaining that the window has to stay open to the run the server, just go rent a VPS.
     
    • Funny Funny x 1
  20. hello, guys. I want to make my server start again when it's chrashes :S can u help me?
     
Thread Status:
Not open for further replies.