Little tutorial how to run CB on linux server with automatic backup / restart

Discussion in 'Bukkit Help' started by vlado2portos, Apr 2, 2011.

?

Was this any help ?

  1. Yes

    100.0%
  2. No

    0 vote(s)
    0.0%
  3. Don't use linux

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    vlado2portos

    Hello All,

    I'm not sure how many same tutorials are here already but maybe I will add something new ( or not :confused: )

    Purpose:

    To run CB on linux server ( I use ubuntu ) in screen mode so you can log off and it will go on.
    To have full backup of your map every day. ( this save me a lot .. )
    To have automatic restart daily for stability purpose.

    Setting of CB will not be covered as this can be easily find here around..

    Note*
    my directory where bukkit binary is, is: /var/minecraft/bukkit/

    I use two start scripts.

    1: bukkit_start.sh <--- This one start the nogui

    Code:
    #!/bin/sh
    java  -Xincgc -Xmx4G -jar craftbukkit-0.0.1-SNAPSHOT.jar nogui
    
    2: start.sh <--- this one take care of running it in screen

    Code:
    #!/bin/bash
    screen -S minecraft -t world -d -m /var/minecraft/bukkit/bukkit_start.sh
    
    Parameters for screen are important we use them to pass commands to game console with script..

    My backup script:
    backup.sh

    Code:
    #!/bin/bash
    # Minecraft AutoBackup
    NOW=$(date +"%d-%m-%Y")
    i=$(date +"%Hh%Mm%Ss")
    cd /var/minecraft/bukkit/
    if [ -e server.log.lck ] #check if server is running
    then #Inform players that backup started
       screen -S minecraft -p world -X stuff "say ###Auto Backup - Started###"`echo -ne '\015'`
       screen -S minecraft -p world -X stuff "save-off"`echo -ne '\015'`
       screen -S minecraft -p world -X stuff "save-all"`echo -ne '\015'`
       sleep 5
       tar -czf /var/minecraft/bukkit/backup/Svet_MineCraftu-$NOW-$i.tar.gz /var/minecraft/bukkit/Svet_MineCraftu  #/var/minecraft/bukkit/backup/ is where is my backup located and Svet_MineCraftu is name of map
       screen -S minecraft -p world -X stuff "save-on"`echo -ne '\015'`
       screen -S minecraft -p world -X stuff "say ###Auto Backup - Done###"`echo -ne '\015'`
       find /var/minecraft/bukkit/backup/ -mmin +2880 -exec rm {} \; #remove backups older than 2days
    fi
    
    Restart script
    restart.sh <-- will restart server with 1min info in advance for players

    Code:
    #!/bin/bash
    # Minecraft AutoRestart
    
    cd /var/minecraft/bukkit/
    screen -S minecraft -p world -X stuff "say ###Auto Restart - Starting###"`echo -ne '\015'`
    screen -S minecraft -p world -X stuff "say # Restart in 1 Minute!"`echo -ne '\015'`
    sleep 50
    screen -S minecraft -p world -X stuff "say # Restart in 10 Seconds!"`echo -ne '\015'`
    sleep 5
    screen -S minecraft -p world -X stuff "say # Restart in 5 Seconds! You should log off!"`echo -ne '\015'`
    screen -S minecraft -p world -X stuff "save-all"`echo -ne '\015'`
    sleep 5
    screen -S minecraft -p world -X stuff "stop"`echo -ne '\015'`
    sleep 5
    screen -S minecraft -t world -d -m /var/minecraft/bukkit/bukkit_start.sh
    sleep 5
    screen -S minecraft -X stuff "say ###Auto Restart - Done###"`echo -ne '\015'`
    
    Check script if server is running or not ( do not detect hanged server :( )
    check.sh

    Code:
    #!/bin/sh
    cd /var/minecraft/bukkit/
    if [ -e server.log.lck ]
    then
       echo "Server is running !"
    else
       echo "Server is down !"
       screen -S minecraft -t world -d -m /var/minecraft/bukkit/bukkit_start.sh
       NOW=$(date +"%b-%d-%y %H:%M")
       echo '[' $NOW ']: Server was down.... Started !' >> /var/minecraft/bukkit/logs/ServerCheck.log
    fi
    
    And how it is tight up all together in cron ?

    Cron:

    Code:
    ## minecraft maintanance scripts
    #This backs up the server at 3:35am every morning.
    35  3   *   *   *   cd /var/minecraft/bukkit && ./backup.sh >/dev/null 2>&1
    #This restarts the server at 3:40am every morning.
    40   3   *   *   *   cd /var/minecraft/bukkit && ./restart.sh >/dev/null 2>&1
    #Check if server is running every 30min and if not, will start it
    */30   *   *   *   * cd /var/minecraft/bukkit && ./check.sh >/dev/null 2>&1
    
    Maybe it can be helpful to somebody...
     
    Hobby_boy and Hacr like this.
  2. Offline

    Plague

    Takys mohl ty restart hlasky napsat anglicky ;)

    ENG: You could rewrite those restart messages into english.
     
  3. Offline

    vlado2portos

    Ah thanks missed that one :rolleyes:
     
  4. Offline

    Bronski

    This was helpful, thanks :D
     
  5. Offline

    Citizen Derp

    Thanks for the post! Showing how to use the screen command to post stuff from a script was really helpful. I tried to find information on what "stuff" did, but you can imagine how many useful things you could find googling for "stuff"
     
  6. Offline

    vlado2portos

  7. Offline

    Hacr

    thank you! :D :D

    This was really helpful for my backup script :)
     
Thread Status:
Not open for further replies.

Share This Page