mscs/README.md

362 lines
12 KiB
Markdown
Raw Normal View History

2014-01-04 13:11:37 -07:00
Minecraft Server Control Script
2013-06-24 11:04:28 -07:00
=============================
A powerful command-line control script for Linux-powered Minecraft servers.
2014-01-04 17:03:10 -07:00
## Index
* [Features](#features)
* [Installation](#installation)
* [Usage](#usage)
* [Server Customization](#server-customization)
2014-01-04 19:15:03 -07:00
* [License](LICENSE)
2014-01-04 17:09:43 -07:00
* [Issues](#issues)
2014-01-04 17:03:10 -07:00
## Features
* Run multiple Minecraft worlds.
* Start, stop, and restart single or multiple worlds.
* Create, delete, disable, and enable worlds.
* Supports [CraftBukkit](http://bukkit.org/) in addition to the standard Mojang server distribution.
* Users automatically notified of important server events.
* Uses the Minecraft [Query protocol](http://wiki.vg/Query) 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](http://overviewer.org/) mapping software.
* Backup worlds, and remove backups older than X days.
* Update the server and client software automatically.
* Send commands to a world server from the command line.
2014-01-04 17:09:43 -07:00
See the [Usage](#usage) section below for a description on how to use these features.
2014-01-04 17:03:10 -07:00
## Installation
### Download
You can download the script from the following locations:
2014-01-04 13:11:37 -07:00
2014-01-04 17:03:10 -07:00
* Get a [zip file](https://github.com/sandain/MinecraftServerControlScript/archive/master.zip):
2014-01-04 13:11:37 -07:00
2014-01-04 17:03:10 -07:00
wget https://github.com/sandain/MinecraftServerControlScript/archive/master.zip
2014-01-04 13:11:37 -07:00
2014-01-04 19:24:05 -07:00
* Make a clone of the [git repository](https://github.com/sandain/MinecraftServerControlScript.git):
2014-01-04 13:11:37 -07:00
2014-01-04 17:03:10 -07:00
git clone https://github.com/sandain/MinecraftServerControlScript.git
2014-01-04 13:11:37 -07:00
2014-01-04 17:03:10 -07:00
### Configuration
2013-06-24 12:04:31 -07:00
To get your server to run the script on startup, and cleanly down the server
2014-01-04 17:41:07 -07:00
on shutdown, the `minecraft_server` script must be copied to `/etc/init.d`,
2013-12-08 14:27:13 -07:00
have its execute permissions set, and the system must be instructed to use
the script on startup and shutdown. For Bash programmable completion
support, the `mscs_completion` script must be copied to
2013-12-08 14:27:13 -07:00
`/etc/bash_completion.d`. For security reasons, the script uses a user
2014-01-04 19:23:04 -07:00
account named `minecraft` rather than `root` and the account must be created
2013-12-08 14:27:13 -07:00
before the script is used.
2013-12-02 14:24:07 -07:00
2013-12-08 14:27:13 -07:00
This can all be done automatically with the included Makefile in Debian and
Ubuntu like environments by running:
2013-12-08 14:27:13 -07:00
sudo make install
2013-12-08 14:27:13 -07:00
It can also be accomplished manually with the following commands:
2013-12-08 14:27:13 -07:00
sudo cp minecraft_server /etc/init.d/minecraft_server
sudo cp mscs_completion /etc/bash_completion.d/mscs_completion
sudo chmod 755 /etc/init.d/minecraft_server
sudo update-rc.d minecraft_server defaults
sudo adduser minecraft
2013-12-08 14:27:13 -07:00
The Minecraft server software will be automatically downloaded to the
following location on the first run:
2013-12-08 14:27:13 -07:00
/home/minecraft/minecraft_server/
2014-01-04 17:03:10 -07:00
### Requirements
We've made an attempt to utilize only features that are normally installed in
2013-06-24 12:04:31 -07:00
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
2013-06-24 12:04:31 -07:00
preinstalled.
* Python - Required by the Minecraft Overviewer mapping software.
* GNU Wget - Allows the script to download software updates via the
2013-06-24 12:04:31 -07:00
internet.
* rdiff-backup - Allows the script to efficiently run backups.
* Socat - Allows the script to communicate with the Minecraft server.
* Iptables - Although not explicitly required, a good firewall should be
2013-06-24 12:04:31 -07:00
installed.
If you are running Debian or Ubuntu, you can make sure that these are
installed by running:
sudo apt-get install default-jre perl python wget rdiff-backup socat iptables
2014-01-04 17:03:10 -07:00
### Mapping Software
2014-01-04 13:11:37 -07:00
The script uses the [Minecraft Overviewer](http://overviewer.org) mapping
software to generate maps of your worlds. Minecraft Overviewer is a
command-line tool for rendering high-resolution maps of Minecraft worlds. It
generates a set of static html and image files and uses the Google Maps API to
display a nice interactive map.
You can [download](http://overviewer.org/downloads) premade binaries for
supported systems, or build your own binary from source if needed.
2014-01-04 13:11:37 -07:00
Repositories for automatic installation are also available:
* [Debian/Ubuntu](http://overviewer.org/debian/info)
* [RHEL/CentOS/Fedora](http://overviewer.org/rpms/info)
2014-01-04 17:03:10 -07:00
### Firewall / NAT
2013-06-24 12:04:31 -07:00
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:
2014-01-04 17:41:07 -07:00
* The default port for the Minecraft server is: `25565`.
* If you wish to run multiple world servers using this script, you will
2014-01-04 19:21:12 -07:00
want to open a range of ports (for example `25565 - 25575`).
2013-06-24 12:04:31 -07:00
2014-01-04 17:09:43 -07:00
See the [iptables.rules](iptables.rules)
file for a very basic set of rules that you can use with the Iptables firewall.
2014-01-04 17:03:10 -07:00
## Usage
### Permissions
2014-01-04 17:41:07 -07:00
All commands below assume that you are running them as either the `minecraft`
user or as `root` (through sudo).
2014-01-04 17:41:07 -07:00
Note: If the script is run as the `root` user, all important server processes
will be started using the `minecraft` user instead for security purposes.
2013-12-08 14:42:24 -07:00
su minecraft
2014-01-04 17:03:10 -07:00
/etc/init.d/minecraft_server [option]
or
2014-01-04 17:03:10 -07:00
sudo /etc/init.d/minecraft_server [option]
2014-01-04 17:03:10 -07:00
### Options
2014-01-04 13:11:37 -07:00
* start [world]
Start the Minecraft world server. Start all worlds by default.
* stop [world]
2014-01-04 13:11:37 -07:00
Stop the Minecraft world server. Stop all worlds by default.
* force-stop [world]
Forcibly stop the Minecraft world server. Forcibly stop all worlds by
default.
* restart [world]
Restart the Minecraft world server. Restart all worlds by default.
* force-restart [world]
Forcibly restart the Minecraft world server. Forcibly restart all
worlds 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.
2014-01-04 13:11:37 -07:00
* delete [world]
2014-01-04 13:11:37 -07:00
Delete a Minecraft world server.
2014-01-04 13:11:37 -07:00
* disable [world]
2014-01-04 13:11:37 -07:00
Temporarily disable a world server.
2014-01-04 13:11:37 -07:00
* enable [world]
2014-01-04 13:11:37 -07:00
Enable a disabled world server.
2014-01-04 13:11:37 -07:00
* list [option]
2014-01-04 13:11:37 -07:00
Display a list of worlds.
Options:
2014-01-04 13:11:37 -07:00
* enabled
2014-01-04 13:11:37 -07:00
Display a list of enabled worlds, default.
2014-01-04 13:11:37 -07:00
* disabled
2014-01-04 13:11:37 -07:00
Display a list of disabled worlds.
2014-01-04 13:11:37 -07:00
* running
2014-01-04 13:11:37 -07:00
Display a list of running worlds.
2014-01-04 13:11:37 -07:00
* stopped
2014-01-04 13:11:37 -07:00
Display a list of stopped worlds.
* status [world]
2014-01-04 13:11:37 -07:00
Display the status of the Minecraft world server. Display the
status of all worlds 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.
2014-02-06 15:49:55 -07:00
* console [world]
Connect to the Minecraft world server's console. Hit [Ctrl-D] to detach.
2014-01-04 13:11:37 -07:00
* watch [world]
Watch the log file for the Minecraft world server.
* map [world]
Run the Minecraft Overviewer mapping software on the Minecraft world.
Map all worlds by default.
* update
Update the client and server software packages.
2014-01-04 17:03:10 -07:00
### Examples
To start all of the world servers, issue the command:
2013-12-08 14:42:24 -07:00
/etc/init.d/minecraft_server start
To create a world named alpha, issue the command:
2013-12-08 14:42:24 -07:00
/etc/init.d/minecraft_server create alpha 25565
To start just the world named alpha, issue the command:
2013-12-08 14:42:24 -07:00
/etc/init.d/minecraft_server start alpha
To send a command to a world server, issue the command:
2014-01-04 17:03:10 -07:00
/etc/init.d/minecraft_server send [world] [command]
ie.
2014-01-04 13:11:37 -07:00
2013-12-08 14:42:24 -07:00
/etc/init.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
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. Also ensure that `enable-query` is set to `true`. If you do not have `enable-query` and a `query.port` set, you will not be able to check the status of the world with the script.
2014-01-04 17:03:10 -07:00
## Server Customization
The server settings for each world can be customized by adding certain
2014-01-04 17:41:07 -07:00
key/value pairs to the world's `server.properties` file.
The following keys are available:
* mscs-version-type - Assign the version type (release or snapshot).
2014-01-04 13:11:37 -07:00
* mscs-client-version - Assign the version of the client software.
* mscs-client-jar - Assign the .jar file for the client software.
* mscs-client-url - Assign the download URL for the client software.
* mscs-client-location - Assign the location of the client .jar file.
* mscs-server-version - Assign the version of the server software.
* mscs-server-jar - Assign the .jar file for the server software.
* mscs-server-url - Assign the download URL for the server software.
* mscs-server-args - Assign the arguments to the server.
* mscs-initial-memory - Assign the initial amount of memory for the server.
* mscs-maximum-memory - Assign the maximum amount of memory for the server.
* mscs-server-location - Assign the location of the server .jar file.
* mscs-server-command - Assign the command to run for the server.
The following variables may be used in some of the values of the above keys:
2014-01-04 13:11:37 -07:00
* $JAVA - The Java virtual machine.
* $CURRENT_VERSION - The current Mojang Minecraft release version.
* $CLIENT_VERSION - The version of the client software.
* $SERVER_VERSION - The version of the server software.
* $SERVER_JAR - The .jar file to run for the server.
* $SERVER_ARGS - The arguments to the server.
* $INITIAL_MEMORY - The initial amount of memory for the server.
* $MAXIMUM_MEMORY - The maximum amount of memory for the server.
* $SERVER_LOCATION - The location of the server .jar file.
2014-01-04 17:03:10 -07:00
### Example key/value pairs
Equivalent to the default values:
2014-01-04 13:11:37 -07:00
mscs-version-type=release
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_ARGS
2014-01-04 17:03:10 -07:00
Run a Minecraft version 1.6.4 server:
2014-01-04 13:11:37 -07:00
mscs-client-version=1.6.4
mscs-server-version=1.6.4
2014-01-04 17:03:10 -07:00
Use the latest CraftBukkit recommended build:
2014-01-04 13:11:37 -07:00
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
2014-01-04 17:03:10 -07:00
## License
2014-01-04 17:09:43 -07:00
See [LICENSE](LICENSE)
2014-01-04 17:03:10 -07:00
## Issues
2013-06-24 14:44:41 -07:00
2014-01-04 17:03:10 -07:00
We have only tested this code in a Debian/Ubuntu environment, but there is no
2013-06-24 14:44:41 -07:00
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
2014-01-04 17:03:10 -07:00
environment where the error occurs to the support thread, and we will try to
2013-06-24 14:44:41 -07:00
work out a solution with you.
Support thread: http://www.minecraftforum.net/viewtopic.php?f=10&t=129833
2014-01-04 13:11:37 -07:00
Github Issues: https://github.com/sandain/MinecraftServerControlScript/issues