[ADMIN] Mac OS X/Linux Bukkit Starter w/ Auto-Backup (v0.1)

Discussion in 'Bukkit Tools' started by kshotts, Jan 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    kshotts

    I've been playing around with Bukkit for awhile, and have been tweaking the shell script used to start it to suit my needs, and figured I'd share it with y'all.

    Features:
    • Specify the minimum and maximum amount of RAM to allocate as command-line parameters (optional; if not specified default is 2G for each.) Example: sh ./start_server.sh 2G 4G (minimum 2G, max 4G)
    • Automatically backup selected worlds to a directory you specify in the script prior to starting Bukkit. Worlds are stored in backupworlds.txt in BUkkit's directory, with one world per line, surrounded by quotes.
    I'm sure more things will be coming, so I'll update with any changes.

    Auto-Backup of Worlds
    The script uses a file in the main directory of Bukkit (referred to as $BUKKIT_HOME) that lists the worlds to backup. The file looks something like this:

    Code:
     "world"
     "world_nether"
     "world_the_end"
     "SkyBlock2.1"
     "TheCity"
     ...
    
    The Script

    Before you use the script, you need to replace two variables at the top of the script, namely BUKKIT_HOME (with the path to your Bukkit installation, minus the final "/"), and BACKUP_DIR (with the path to your desired backup location, minus the final "/"). The location specified in BACKUP_DIR must exist, or the backup will fail.

    Pre-requisites
    • Java should be in the PATH, and the Java environment should be set up correctly prior to starting the script.
    • A file in $BUKKIT_HOME/backupworlds.txt with AT LEAST one world to backup. (Next version will let this be optional.)
    • Bukkit Server .jar is named "craftbukkit.jar". If it isn't, you'll have to edit the script appropriately.
    • The location for the backups must exist. This script won't create the path for you automatically.

    Code:
    #!/bin/bash
    BUKKIT_HOME="specify_your_path_to_bukkit_here"
    BACKUP_DIR="specify_your_backup_directory_here"
    ###################################################################################
    #
    # MINECRAFT STARTER, by Kerri Shotts (kshotts) CCv3 SSA, with-attribution
    #
    ###################################################################################
    #
    # Usage:
    #    start_server [min_mem] [max_mem]
    #
    #    min_mem: if not specified, defaults to 2G. Use Java conventions
    #    max_mem: if not specified, defaults to 2G. Use Java conventions
    #
    ###################################################################################
    if [ "$1" = "" ]; then
        min_mem="2G"
    else
        min_mem="$1"
    fi
    if [ "$2" = "" ]; then
        max_mem="2G"
    else
        max_mem="$2"
    fi
    
    #
    # Do a backup to Dropbox. We will use the list of worlds to backup in
    # $BUKKIT_HOME/backupworlds.txt
    #
    echo
    echo "Backup up worlds prior to starting Minecraft Server..."
    echo
    echo "    Source File: $BUKKIT_HOME/backupworlds.txt"
    echo "    Target Dir:  $BACKUP_DIR"
    echo
    xargs -t -I fn cp -r "$BUKKIT_HOME"/"fn" "$BACKUP_DIR" < $BUKKIT_HOME/backupworlds.txt
    echo
    echo "... Backup completed."
    echo
    
    #
    # Now start the server with the specified memory
    #
    
    echo
    echo "Starting Minecraft Server at $min_mem (with up to $max_mem allowed)..."
    echo
    
    cd "$( dirname "$0" )"
    java -server -Xincgc -Xmn$min_mem -Xmx$max_mem -jar $BUKKIT_HOME/craftbukkit.jar
    
    echo
    echo "Minecraft Server Stopped."
    echo
    
    
    Disclaimer

    While this works fine on my system, I make no guarantee that it will on yours or that it won't do funny things or horrible things. Be sure to test it yourself on a non-critical installation first.

    Further, this works on my Mac OS X system; I haven't tested on Linux. I don't see any reason why Linux shouldn't work, however.

    License

    You're free to use this script pretty much however you want within the bounds of the Creative Commons v3, Share-and-share-alike, with-attribution license. If you do modify the script, please share the results with the community - I might want to put it in mine, at least! If you do share the script, please link back to this forum or indicate me as the author.
     
Thread Status:
Not open for further replies.

Share This Page