Minecraft Server on CentOS 6

I downloaded the minecraft server package and extracted it to /opt/minecraft

I installed screen and Java (OpenJDK) using yum as follows:

The SysV init startup scripts provided on the Wiki didn’t work for me so I cobbled the following together which works for me. Anyone else wishing to use this should set the variables at the top correctly. Place this file in the /etc/init.d/ directory and make it executable

Then to stop and start minecraft use the following:

It would also be good to ensure that minecraft starts automatically when the system boots:

The SysV init script I used is shown below:

# Check dependencies
if [ ! -f $PATH_TO_JRE/java ];
then
echo “Please configure this script by setting the path to a Java runtime.”
exit 1
fi
if [ ! -f $PATH_TO_SCREEN ];
then
echo “Please ensure screen is installed (yum install screen) and the path is set correctly at the top of this script.”
exit 1
fi
if [ ! -f $PATH_TO_MINECRAFT/minecraft_server.jar ];
then
echo “Please ensure the minecraft server jar file is in the correct location and configured at the top of this script.”
exit 1
fi

# Start the service
start() {
if [ -f /var/lock/subsys/$SERVICE_NAME ];
then
echo “Lock file $FILE exists. Is $SERVICE_NAME still running?”
exit 1
fi
echo -n $”Starting $SERVICE_NAME server: ”

export LD_LIBRARY_PATH=”$PATH_TO_JRE_LIBS”
cd $PATH_TO_MINECRAFT
$PATH_TO_SCREEN -h 1024 -dmS minescreen $PATH_TO_JRE/java -Xmx$MEMORY_SIZE -Xms$MEMORY_SIZE -jar $PATH_TO_MINECRAFT/minecraft_server.jar nogui

### Create the lock file ###
touch /var/lock/subsys/$SERVICE_NAME
success $”$SERVICE_NAME server startup”
echo
}
stop() {
echo -n $”Stopping $SERVICE_NAME server: ”

PIDS=

1
ps -ef | grep "minecraft" | grep -v "grep" | awk '{print $2}' | head -1

for PID in $PIDS
do
kill $PID
done

### Now, delete the lock file ###
rm -f /var/lock/subsys/$SERVICE_NAME
}
### main logic ###
case “$1″ in
start)
start
;;
stop)
stop
;;
status)
status $SERVICE_NAME
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $”Usage: $0 {start|stop|restart|status}”
exit 1
esac
exit 0

Backups

I added a cron job to backup the minecraft directory regularly using the following script. You will need to create the target directories first e.g.
mkdir -p /var/backups/minecraft/byday/{Sun,Mon,Tue,Wed,Thu,Fri,Sat}

Screen

Since we are using ‘screen’ to hold the session output we can use the following screen commands:
To view the current list of available screen sessions:
screen -ls
To re-attach to one of these screen sessions:
screen -r 12345
To detach again from the session (while leaving the minecraft server running):
Ctrl-A d

Whitelist

I wanted a private minecraft server for my son and a few of his friends so I added their usernames to the white-list.txt file. One username per line – it looks like the username or the email address will work. I then changed the server.properties file and set white-list=true

Operations

I added my sons username to the ops.txt file which should allow him to send server commands e.g. whitelisting other users or setting the difficulty. A list of the ops commands is available here:
http://www.minecraftwiki.net/wiki/SMP_Server_commands#Operator-only_commands

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">