Daily reboot and MC-Server autostart

Mar 2, 2019
Daily reboot and MC-Server autostart
  • Hey everybody,

    I've noticed there are very much people who missunderstood how to schedule an automatic Serverreboot and automatic boot up of a Minecraft-Server with a deatched screen.

    So first make sure you have access to your serverconsole. Now check if you've installed crontab and screen you'll need both for this method. This Guide was tested under Ubuntu LTS 16.04.

    To check if screen is installed simply type
    and press enter.

    To check if crontab is installed simply type
    crontab -help
    and press enter. If there comes an overview its fine.

    If you don't have crontab and/or screen installed simply do this by typing
    sudo apt-get install screen
    sudo apt-get install cron

    Well lets start so first you have to setup a bash script what will boot up your MC-Server.

    Switch to your directory and create a new file with vi start.sh you can replace start with another name.
    If the new file was created and opened press "i" then you can write text into your file.
    You can copy the code from below or just write a own one. This code will reboot the server when it crashes or you type /stop InGame

    Code (Text):

    while true
    java -Xms1024M -Xmx2048M -jar spigot.jar
    sleep 5
    When you're done press escape type ":wq" and press enter to save the file.

    Now you need to make the file executable. Type into your terminal chmod 777 start.sh

    If you're done with this we'll go to the next step.

    Now we need to set up crontab let's start with the reboot every day.
    Type into your terminal sudo vi /etc/crontab
    Just add another line below the last like this

    30 4 * * * root reboot

    This would reboot your server every night at 4:30. Some distributions doesn't support the reboot command.
    In this case just replace reboot with shutdown -r.

    When you're done press escape type ":wq" and press enter to save the file.

    Well if you don't start your MC-server with the root account login with your preferred account.
    Then type crontab -e else if you wan't to run this screen with the root account type sudo crontab -e.

    Now we need to add an '@reboot' rule.

    Type the following into this file

    @reboot sleep 45 && cd /path/to/your/file/ && bash start.sh
    You can repeat this step again and again till you have all your servers added.

    After this when you're done press escape type ":wq" and press enter to save the file.

    Just reboot your complete server by typing reboot or shutdown -r.
    Now it should work fine and your MC-Servers will boot every time your server is booting e.g. after powerloss or is just rebooting.

    I hope anyone needed this Guide.
    Thanks for reading.

  • Loading...
  • Loading...