Jump to content

Recommended Posts

Posted

Useful for anyone who wants to run their Tekkit server on a linux machine. It's a modified script from https://github.com/lhutton/minecraft-server-init-script and http://www.minecraftwiki.net/wiki/Server_startup_script. It requires rsync and screen and of course your latest java package.

On a debian based system you can install it with

update.rc <scriptname> defaults
 where <scriptname> is whatever is whatever you call this file.




#!/bin/bash



# User editable variables:

# Always include the trailing slashes on directories!

MINECRAFT="Tekkit.jar"         # Name of your server jar file. This script supports vanilla and craftbukkit.

MCPATH="/var/minecraft/server/"     # Directory on disk of your MC server. Make sure your MINECRAFT jar file is located here.

ARGS="-Xincgc -Xmx1024M -Xms1024M -jar" # Standard arguments for the minecraft server jar.

USER="minecraft"            # User your minecraft server runs under.

BACKUPDIR="/var/minecraft/backups/"   # Directory for backup tar files.



# Various programs this script calls

# Setup for Debian by default, you may need to update the location of these for other distros.

JAVA="/usr/bin/java"

SCREEN="/usr/bin/screen"

DATE=$(date +%m-%d-%Y-%H:%M)

TAR="/bin/tar"

RSYNC="/usr/bin/rsync"



# RAM Disk settings.

# Don't use this if you don't know what you're doing!

# See the README for me info

RAMDISK=false          # Set to true if you want to use a RAM disk, false to run from a hard disk. See README first.

RAMDISKDIR="/path/to/ramdisk/" # The path where your RAM disk is mounted.



already_running(){



    if pgrep -u $USER -f $MINECRAFT > /dev/null

    then

        return 1

    else

        return 0

    fi

}



run_as() {



    WHOAMI=`whoami`



    if [ "$WHOAMI" == "$USER" ]

    then

        bash -c "$1"

    else

        su - $USER -c "$1"

    fi



}



start() {



    already_running



    if [ "$?" == "1" ]

    then

        echo "Minecraft already running ..."

    else

        if [ $RAMDISK == "true" ]

        then

            echo "Copying files to RAM Disk ..."

            setup_ramdisk

            echo "Starting $MINECRAFT ..."

            run_as "cd $RAMDISKDIR && $SCREEN -dm -S minecraft $JAVA $ARGS $MINECRAFT"

            sleep 7

        else



            echo "Starting $MINECRAFT ..."

            run_as "cd $MCPATH && $SCREEN -dm -S minecraft $JAVA $ARGS $MINECRAFT"

            sleep 7

        fi



        already_running

            if [ "$?" == "1" ]

            then

                echo "$MINECRAFT started."

            else

                echo "Error, $MINECRAFT could not be started. Check ${MCPATH}server.log for errors."

            fi



    fi

}





stop() {



    already_running

    if [ "$?" == "1" ]

    then

        if [ $RAMDISK == "true" ]

        then



        echo "Syncing RAM drive to disk .."

        sync_ram_to_disk

        echo "Sync complete."



    fi

        echo "Stopping $MINECRAFT ... "

        run_as "$SCREEN -p 0 -S minecraft -X stuff \"say SERVER SHUT DOWN IN 5 SECONDS. SAVING WORLD ...\"$(echo -ne '\015')"

        run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff save-all\015'"

        sleep 5

        run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff stop\015'"

        sleep 2

        already_running

            if [ "$?" == "1" ]

            then

                echo "$MINECRAFT could not be stopped."

                echo "Check ${MCPATH}server.log for errors."

            else

                echo "$MINECRAFT stopped."

            fi



    else

        echo "$MINECRAFT is not running"

    fi

}



status() {



    already_running

    if [ "$?" == "1" ]

    then

        echo "$MINECRAFT is running."

    else

        echo "$MINECRAFT is not running."

    fi

}



save_all() {



    already_running

    if [ "$?" == "1" ]

    then

        echo "Saving all in memory to disk ..."

        run_as "$SCREEN -p 0 -S minecraft -X stuff \"say SAVING WORLD. PREPARE FOR LAG.\"$(echo -ne '\015')"

        run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff save-all\015'"

        sleep 10

        run_as "$SCREEN -p 0 -S minecraft -X stuff \"say SAVE COMPLETE.\"$(echo -ne '\015')"

    else

        echo "$MINECRAFT not running."



    fi







}



backup() {

    already_running

    if [ "$?" == "1" ]

    then

        if [ "$RAMDISK" == "true" ]

        then

            echo "Syncing RAM drive to disk .."

            sync_ram_to_disk

            echo "Sync complete."

        fi



        echo "Backing up server ..."

        if [ -d $BACKUPDIR ]

        then

            run_as "$SCREEN -p 0 -S minecraft -X stuff \"say BACKING UP. SERVER GOING READ-ONLY.\"$(echo -ne '\015')"

            run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff save-off\015'"

            run_as "$TAR czf ${BACKUPDIR}minecraft-server-${DATE}.tar.gz $MCPATH"

            run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff save-on\015'"

            run_as "$SCREEN -p 0 -S minecraft -X stuff \"say BACK UP COMPLETE. SERVER GOING READ-WRITE.\"$(echo -ne '\015')"



            echo "Backup complete."

        else

            echo "Error, backup directory not found."

        fi

    else

            run_as "$TAR czf ${BACKUPDIR}minecraft-server-${DATE}.tar.gz $MCPATH"

            echo "Backup complete."

    fi



}



setup_ramdisk() {

        echo "You are setup to run in a RAM disk."

        echo "PLEASE see the README about syncing the RAM drive with a hard drive!"

        run_as "$RSYNC -art --delete-after $MCPATH $RAMDISKDIR"

}



sync_ram_to_disk() {



    if [ -f $RAMDISKDIR/${MINECRAFT} ]

    then



        echo "Syncing RAM disk to drive ..."

        run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff save-off\015'"

        run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff save-all\015'"

        sleep 2

        run_as "$RSYNC -art --delete-after $RAMDISKDIR $MCPATH"

        run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff save-on\015'"

        echo "Sync complete."



    else

        echo "Error, $MINECRAFT not in RAM disk."

    fi

}



mc_command() {

    command="$1";

    if pgrep -u $USER -f $MINECRAFT > /dev/null

    then

        pre_log_len=`wc -l "$MCPATH/server.log" | awk '{print $1}'`

        run_as "$SCREEN -p 0 -S minecraft -X eval 'stuff \"$command\"\015'"

        sleep .1

        tail -n $[`wc -l "$MCPATH/server.log" | awk '{print $1}'`-$pre_log_len] "$MCPATH/server.log"

    fi

}



case $1 in

    start)

        start

        exit 1

        ;;

    stop)

        stop

        exit 1

        ;;



    save-all)

        save_all

        exit 1

        ;;



    backup)

        save_all

        backup

        exit 1

        ;;

    status)

        status

        exit 1

        ;;

    writetodisk)

        sync_ram_to_disk

        exit 1

        ;;

    restart)

        stop

        start

        exit 1

        ;;

    "command" | "cmd")

        if [ $# -gt 1 ]; then

            shift

            mc_command "$*"

        else

            echo "Must specify server command (try 'help' ?)"

        fi

        ;;

    *)

        echo "Usage: minecraft-server {start|restart|save-all|backup|writetodisk|stop|command/cmd}"

        exit 1

        ;;

esac



exit 0





This is what I use on my server, but just for safety's sake: USE THIS SOFTWARE AT YOUR OWN RISK. THIS SCRIPT IS NOT WARRANTIED TO WORK PROPERLY OR AT ALL. PROVIDER(S) (i.e. me) ARE NOT LIABLE FOR ANY DAMAGE YOU MIGHT INVOKE UPON YOUR OR ANYONE ELSE'S MACHINE.



If you have any questions as to what's going on in the script I'd be glad to help but the commands are fairly self-explanatory: 
Usage: minecraft-server {start|restart|save-all|backup|writetodisk|stop|command/cmd}
The "cmd" code of is great value since it passes commands directly to the console without having to manually invoke the screen. Lets say you want to whitelist someone without having to edit the file/restart the server or promote a user within minecraft to op. You just type the command from your linux prompt/ssh session:

/etc/init.d/minecraft-server cmd whitelist add SomePlayerName
  • 1 month later...
Posted

Any chance you could tell me how to set this up? I connect to my dedicated server through a vnc server. its running debian and i dont understand how to use this to allow tekkit to install. please help? :)

Posted

im still not entirely sure wat the script does. is it possible to just use a script like the one for windows, like a .bat file?

Yes, this is just a much more sophisticated version of that, handling things in a cleaner and more optimized way for a linux client. It runs with a bunch of command line options as well. Starting, stopping, opping a player/giving an item, all done through the interface (./script start, ./script start, ./script cmd op player, ./script cmd give player 1 64) etc.

Posted

im still not entirely sure wat the script does. is it possible to just use a script like the one for windows, like a .bat file?

Make a new file called start in Tekkit.jar folder, then chmod +x start

Then you add this into the file with your favourite editor

#!/bin/bash

java -Xincgc -Xmx1536M -Xms100M -jar Tekkit.jar nogui

and then you just ./start when you saved your file.

If you want the server upp all time, type screen first then you ./start it.

ctrl+alt+d to get back to your normal screen and the server should be up until it crash or you reboot server :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...