- Run multiple Minecraft worlds.
- Start, stop, and restart single or multiple worlds.
- Create, delete, disable, and enable worlds.
- Supports CraftBukkit in addition to the standard Mojang server distribution.
- Users automatically notified of important server events.
- Uses the Minecraft Query protocol to keep track of current server conditions.
- LSB-compatible init script, allows for seamless integration with your server's startup and shutdown sequences.
- Map worlds using the Minecraft Overviewer mapping software.
- Backup worlds, and remove backups older than X days.
- Update the server and client software.
- Send commands to a world server from the command line.
The script can be downloaded from Github:
To get your server to run the script on startup, and cleanly down the server on shutdown, you need to copy the script to /etc/init.d, set execute permissions on the file, and instruct the system to use the script on startup and shutdown. The following commands will work in Debian and Ubuntu like environments, ymmv in others.
sudo cp minecraft_server /etc/init.d/minecraft_server sudo chmod 755 /etc/init.d/minecraft_server sudo update-rc.d minecraft_server defaults
For security reasons, the script uses a user account named minecraft rather than root. As such, you need to create the user before using this script:
sudo adduser minecraft
If the Minecraft server software is not located when the server start command is issued, the software will be downloaded to the proper location: /home/minecraft/minecraft_server/minecraft_server.jar
I've made an attempt to utilize only features that are normally installed in most Linux and UNIX environments in this script, but there are a few requirements that this script has that may not already be in place:
- Java JRE - The Minecraft server software requires this.
- Perl - Most, if not all, Unix and Linux like systems have this preinstalled.
- Python - Required by the Minecraft Overviewer mapping software.
- GNU Wget - Allows the script to download software updates via the internet.
- rdiff-backup - Allows the script to efficiently run backups.
- Socat - Allows the script to communicate with the query server.
- Iptables - Although not explicitly required, a good firewall should be installed.
sudo apt-get install default-jre perl python wget rdiff-backup socat iptables
The script now uses the Minecraft Overviewer mapping software to generate maps of your worlds. You can download premade binaries for supported systems (Debian/Ubuntu, CentOS/RHEL/Fedora), or build your own binary from source if needed.
Firewall / NAT
If you have a firewall installed on your computer, or a router using NAT installed in your network, you will need to route some ports to your server. Instructions on how to accomplish this are beyond the scope of this post, but here are some things you will need to know:
- The default port for the Minecraft server is: 25565.
- If you wish to run multiple world servers using this script, you will want to open a range of ports (for example 25565 - 25575).
All commands below assume that you are running them as either the minecraft user or as root (through sudo).
Note: If the script is run as the root user, all important server processes will be started using the minecraft user for security purposes.
su minecraft /etc/init.d/minecraft_server <option>or
sudo /etc/init.d/minecraft_server <option>
- start <world>
Start the Minecraft world server. Starts all world servers by default.
- stop <world>
Stop the Minecraft world server. Stops all world servers by default.
- force-stop <world>
Forcibly stop the Minecraft world server. Forcibly stops all world servers by default.
- restart <world>
Restart the Minecraft world server. Restarts all world servers by default.
- force-restart <world>
Forcibly restart the Minecraft world server. Forcibly restarts all world servers by default.
- create <world> <port> <ip>
Create a Minecraft world server. The world name and port must be provided, the IP address is usually blank.
- delete <world>
Delete a Minecraft world server.
- disable <world>
Temporarily disable a world server.
- enable <world>
Enable a disabled world server.
- list <option>
Display a list of worlds.
Display a list of enabled worlds, default.
Display a list of disabled worlds.
Display a list of running worlds.
Display a list of stopped worlds.
- status <world>
Display the status of the Minecraft world server. Displays the status of all world servers by default.
- send <world> <command>
Send a command to a Minecraft world server.
- logrotate <world>
Rotate the server.log file. Rotate the server.log file for all worlds by default.
- backup <world>
Backup the Minecraft world. Backup all worlds by default.
- watch <world>
Watch the log file for the Minecraft world server.
- map <world>
Run the Mincraft Overviewer mapping software on the Minecraft world. Maps all worlds by default.
Update the client and server software.
To create a world named alpha, issue the command:
/etc/init.d/minecraft_server create alpha 25565
To start just the world named alpha, issue the command:
/etc/init.d/minecraft_server start alpha
To send a command to a world server, issue the command:
/etc/init.d/minecraft_server send <world> <command> ie. /etc/inid.d/minecraft_server send alpha say Hello world!
Import Existing Worlds
You just need to create a new directory in the worlds folder for the world you wish to import. Suppose the world you wish to import is called alpha, you would create a new folder in /home/minecraft/worlds, then copy the data files over to that directory.
If the directory containing the world alpha you wish to import looks like this:
$ ls alpha banned-ips.txt banned-players.txt crash-reports logs ops.txt server.properties white-list.txt
You can just copy your world into the worlds directory:
mkdir /home/minecraft/worlds/alpha cd /path/to/world/to/import/alpha cp -R * /home/minecraft/worlds/alpha
Make sure you check server-port and query.port in server.properties to make sure it does not overlap with other servers created by the MSCS script. If you do not have a query.port set, you will not be able to check the status of the world with the script.
Message of the Day (MOTD)
To whisper the message of the day to users as they log into the world, add a file called motd.txt to the /home/minecraft directory.
To add colors to your Help or MOTD files, insert the following color codes into your text:
- §0 - black
- §1 - blue
- §2 - deep green
- §3 - aqua
- §4 - deep red
- §5 - purple
- §6 - gold
- §7 - gray
- §8 - dark gray
- §9 - light blue
- §a - green
- §b - teal
- §c - red
- §d - magenta
- §e - yellow
- §f - white
§fWelcome to Minecraft! §fToday's theme is §4red§f. §fLook out for those §2creepers§f!
The server settings for each world can be customized by adding certain
key/value pairs to the world's server.properties file.
The following keys are available:
Assign the version of the client software.
Assign the .jar file for the client software.
Assign the download URL for the client software.
Assign the location of the client .jar file.
Assign the version of the server software.
Assign the .jar file for the server software.
Assign the download URL for the server software.
Assign the arguments to the server.
Assign the initial amount of memory for the server.
Assign the maximum amount of memory for the server.
Assign the location of the server .jar file.
Assign the command to run for the server.
The following variables may be used in some of the values of the above keys:
The Java virtual machine.
The current Mojang Minecraft release version.
The version of the client software.
The version of the server software.
The .jar file to run for the server.
The arguments to the server.
The initial amount of memory for the server.
The maximum amount of memory for the server.
The location of the server .jar file.
The following example key/value pairs are equivalent to the default values:
mscs-client-version=$CURRENT_VERSION mscs-client-jar=$CLIENT_VERSION.jar mscs-client-url=https://s3.amazonaws.com/Minecraft.Download/versions/$CLIENT_VERSION/$CLIENT_VERSION.jar mscs-client-location=/home/minecraft/.minecraft/versions/$CLIENT_VERSION mscs-server-version=$CURRENT_VERSION mscs-server-jar=minecraft_server.$SERVER_VERSION.jar mscs-server-url=https://s3.amazonaws.com/Minecraft.Download/versions/$SERVER_VERSION/minecraft_server.$SERVER_VERSION.jar mscs-server-args=nogui mscs-initial-memory=128M mscs-maximum-memory=2048M mscs-server-location=/home/minecraft/minecraft_server mscs-server-command=$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGSThe following example key/value pairs will run a Minecraft version 1.6.4 server:
mscs-client-version=1.6.4 mscs-server-version=1.6.4The following example key/value pairs will use the latest CraftBukkit recommended build:
mscs-server-jar=craftbukkit.jar mscs-server-url=http://dl.bukkit.org/latest-rb/craftbukkit.jar mscs-server-args= mscs-initial-memory=128M mscs-maximum-memory=2048M
On systems that support lib notify, you can modify the script to print a message on your desktop of important server events.
First, you need to know the name of the display you want to route the messages to. This is usually ":0.0", but it may be something different on your system.
glxinfo | grep "name of display"
If your username is different than the user used for the Minecraft server, replace $USER_NAME in LIBNOTIFY_USER_NAME=$USER_NAME with the correct username.
Modify the following lines of code in the script.
## Lib-notify configuration # To use lib-notify to print a message on your desktop of important server events, change the following to a 1. USE_LIBNOTIFY=0 # The username and display that notifications will be routed to. LIBNOTIFY_USER_NAME=$USER_NAME LIBNOTIFY_DISPLAY=":0.0"
Copyright (c) 2011-2014, Jason M. Wood <[email protected]> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
I have only tested this code in a Debian/Ubuntu environment, but there is no reason that it shouldn't work in any appropriately configured UNIX-like environment, including Apple Mac OSX and the other BSD variants, with only minor modifications. If you experience errors running this script, please post a copy of the error message and a note detailing the operating environment where the error occurs, and I'll try to work out a solution with you.