Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overviewer Support #17

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ ENV SPIGOT_HOME=/minecraft \
# add extra files needed
COPY rootfs /

# add overviewer repository & key
RUN echo "deb http://overviewer.org/debian ./" >> /etc/apt/sources.list && curl http://overviewer.org/debian/overviewer.gpg.asc | apt-key add -

RUN apt-get update && \

# upgrade OS
Expand All @@ -18,17 +21,17 @@ RUN apt-get update && \
# Make info file about this build
printf "Build of nimmis/spigot:latest, date: %s\n" `date -u +"%Y-%m-%dT%H:%M:%SZ"` > /etc/BUILDS/spigot && \

# install application
apt-get install -y wget git && \
# install applications, including nginx & overviewer
apt-get install -y wget git nginx minecraft-overviewer && \

# Make special user for minecraft to run in
/usr/sbin/useradd -s /bin/bash -d /minecraft -m minecraft && \

# remove apt cache from image
apt-get clean all


# expose minecraft port
EXPOSE 25565


# expose nginx port for overviewer
EXPOSE 80
257 changes: 92 additions & 165 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
## Minecraft server SPIGIT on Ubuntu 16.04 with openjava 1.8
[![](https://images.microbadger.com/badges/image/nimmis/spigot.svg)](https://microbadger.com/images/nimmis/spigot "Get your own image badge on microbadger.com")
# Docker image with Minecraft (Spigot server) & Overviewer (Mapping)

This docker image builds and runs the spigot version of minecraft.
This docker image builds and runs the spigot version of minecraft. It deploys overviewer within the same container to view your minecraft map.

If the spigot.jar is not found in the minecraft directory the system pulls down BuildTool and build a new spigot.jar from the latest
released minecraft.jar
![Image of a minecraft overworld map rendered in overviewer showing player locations](http://i.imgur.com/846ALCA.png)

Each time the container is started the presence of the file /minecraft/spigot.jar, if the file is missing a build of spigot.jar is started.
All credit to [nimmis](https://github.com/nimmis). This image build upon their work and haphazidly adds overviewer plus some automation. Please see their [README.md](https://github.com/nimmis/docker-spigot) for more info.

The spigot daemon is started with superovisord, see my Ubuntu container for a more detailed description of my implementation of an init-process in ubuntu, see [nimmis/ubuntu](https://hub.docker.com/r/nimmis/ubuntu/)
### What's included?

Whats new is
- adjust minecraft user UID to match mounted volume
- selectable memory size for the Java process
- selectable spigot version
- do a nice shutdown of the server when the docker stop command is issued
- docker accessible commands to
- start/stop/restart the spigot server
- send console commands to the server
- look at console output from the server
-
- [Spigot](https://www.spigotmc.org) Minecraft server.
- The latest version is downloaded upon first run.
- [Overviewer](https://overviewer.org/) mapping.
- Player locations shown by default
- In-game [signs](http://minecraft.gamepedia.com/Sign) with the first row of text set to "!" can be shown or hidden.
- Automatic Overviewer map refreshes every 30 mins, with player locations and signs every 10 minutes.
- To be clear, player locations are not real time.
- Automatic Minecraft world backups.
- Saved to a tar.gz file, must be manually exported from the container.

## Why not a precompiled version of spigot is included
### Generating the container for the first time.

Due to legal reasons you can build it yourself but you can't redistribute the finished jar file.
**This is important and you only need to do it once.**

## Starting the container
1) You need your own Google Maps API key. Click this link: https://developers.google.com/maps/documentation/javascript/get-api-key and follow the instructions.

To run the latest stable version of this docker image run
2) [Install docker](https://docs.docker.com/engine/installation/)

docker run -d -p 25565:25565 -e EULA=true nimmis/spigot
3) Clone this repo and then run:

the parameter

-e EULA=true

The is because Mojang now requires the end user to access their EULA, located at
https://account.mojang.com/documents/minecraft_eula, the be able to start the server.

the parameter

-p 25565:25565

tell on witch external port the internal 25565 should be connected, in this case the same, if
you only type -p 25565 it will connect to a random port on the machine
docker build -t docker_spigot_overviewer .

4) Subsitute these values into the command below.

- Add your key to:

- `GOOGLE_MAPS_KEY=<--replace with your google maps key-->`, for example, `GOOGLE_MAPS_KEY=abcdefg-H1J2Lm4PQ-dscasdwqeqweb321321Jn`.

- Specify how much memory the minecraft server can utilise

- `MC_MAXMEM=<--megabytes-->m`, for example, `MC_MAXMEM=1500m`

or

- `MC_MAXMEM=<--gigabytes-->g`, for example, `MC_MAXMEM=4g`

## Giving the container a name
When ready, run:

To make it easier to handle you container you can give it a name instead of the long
number thats normally give to it, add a
`docker run -d -p 25565:25565 -p 80:80 -e EULA=true -e MC_MAXMEM=<--replace with megabytes-->m -e GOOGLE_MAPS_KEY=<--replace with your google maps key--> --name mcserver docker_spigot_overviewer`

--name spigot
Further information about the docker run command:

to the run command to give it the name minecraft, then you can start it easier with
|Argument|Description|
|---|---|
|`-p 25565:25565`|Required. Opens the port minecraft uses for gameplay|
|`-p 80:80`|Required. Opens the http port so you can access Overviewer|
|`-e GOOGLE_MAPS_KEY=<--replace with your google maps key-->`|Required. You must add your own API key (which you can obtain from the link above) other overviewer **will not work**.
|`-e EULA=true`|Required. By adding arguemnt this you're accepting the [Minecraft EULA](https://account.mojang.com/documents/minecraft_eula).|
|`-e MC_MAXMEM=<--megabytes-->m`|Sets the maximum memory to use <size>m for Mb or <size>g for Gb, if this parameter is not set 1 Gb is chosen.
|`--name mcserver`|Names this docker container 'mcserver' so it's easier to address later.|

docker start spigot
docker stop spigot
### First time run

## First time run
The first run will take a couple of minutes depending on computer and network speed. It pulls down the latest version of BuildTools and builds a spigot.jar from the selected minecraft version. This is done in numerous steps so please be patient.

This will take a couple of minutes depending on computer and network speed. It will pull down
the selected version on BuildTools and build a spigot.jar from the selected minecraft version.
This is done in numerous steps so be patient.
You can follow the output from the compilation with the command:

you can follow the output from the compilation with then command (assume that you given the container
the name spigot)
# docker logs -f mcserver

docker logs -f spigot
*** open logfile
*** Run files in /etc/my_runonce/
*** Running /etc/my_runonce/set_timezone...
Expand All @@ -77,7 +77,7 @@ the name spigot)
Connecting to hub.spigotmc.org (hub.spigotmc.org)|104.27.195.96|:443... connected.
HTTP request sent, awaiting response... 200 OK

Then the compilation is completed the server will start and you will see something like
When the compilation is complete your minecraft server will start and you will see something like:

*** Log: Success! Everything compiled successfully. Copying final .jar files now.
*** Log: Copying craftbukkit-1.11-R0.1-SNAPSHOT.jar to /minecraft/build/.
Expand All @@ -93,50 +93,25 @@ Then the compilation is completed the server will start and you will see somethi
spigot RUNNING pid 4825, uptime 0:00:03
syslog-ng RUNNING pid 4823, uptime 0:00:03

Exit the log by pressing CTRL-C.


you can then exit from the log with CTRL-C

### Selecting version to compile

If you don't specify it will always compile the latest version but if you want a specific version you can specify it by adding

-e SPIGOT_VER <version>

where <version> is the version you would like to use, to build it with version 1.8 add

-e SPIGOT_VER 1.8
## Starting & Stopping

to the docker run line.
After the inital run you can start and stop the entire container via:

#### versions available
docker start mcserver
docker stop mcserver

The following version is atm avaliable 1.8, 1.8.3, 1.8.7, 1.8.8, 1.9, 1.9.2 and latest. Please check
the web page for [BuildTools](https://www.spigotmc.org/wiki/buildtools/#versions) to get the latest information.

### setup memory to use
## Useful Commands

There are two environment variables to set maximum and initial memory for spigot.
### Logs
To get details of the latest events from the minecraft spigot server type

#### MC_MAXMEM
docker exec mcserver mc_log

Sets the maximum memory to use <size>m for Mb or <size>g for Gb, if this parameter is not set 1 Gb is chosen, to set the maximum memory to 2 Gb

-e MC_MAXMEM=2g

#### MC_MINMEM

sets the initial memory reservation used, use <size>m for Mb or <size>g for Gb, if this parameter is not set, it is set to MC_MAXMEM, to set the initial size t0 512 Mb

-e MC_MINMEM=512m

## look at the last output from the spigot server

To get an output of the latest events from the spigot server type

docker exec spigot mc_log

and you will see the last 10 lines from the output, this is what you will see after startup
and you will be shown the latest logs, which will continue to update. For example:

Abort with CTRL-C
[13:02:15 INFO]: Zombie Aggressive Towards Villager: true
Expand All @@ -150,16 +125,34 @@ and you will see the last 10 lines from the output, this is what you will see af
[13:02:18 INFO]: Server permissions file permissions.yml is empty, ignoring it
[13:02:18 INFO]: Done (3.650s)! For help, type "help" or "?"

It will continue to output everything from the console until you press CTRL-C
Exit the log by pressing CTRL-C.

To get details of the latest events from the overviewer processes type

docker exec mcserver ov_log

For example:

Abort with CTRL-C
20170109 22:05:01 INFO] STARTING ov_render
20170109 22:05:01 INFO] Updating map POIs...
2017-01-09 22:05:01 Looking for entities in <RegionSet regiondir='/minecraft/world/region'>
2017-01-09 22:05:12 Done.
2017-01-09 22:05:12 Loaded UUID cache from '/usr/share/nginx/html/uuidcache.dat' with 7 entries
2017-01-09 22:05:12 Done handling POIs
2017-01-09 22:05:12 Writing out javascript files
2017-01-09 22:05:12 Wrote UUID cache with 7 entries
2017-01-09 22:05:12 Done
20170109 22:05:12 INFO] Map POI update complete!

## sending commands to the server console

You don't need to have an interactive container to be able to send commands to the console. To send
a command to set the time to day you type
### Sending commands to the Minecraft server console

docker exec spigot mc_send "time set day"
Use the mc_send command to send minecraft server console commands. For example:

If this was the first command issued after a start the output should look like
docker exec mcserver mc_send "time set day"

And the output:

[13:02:15 INFO]: Zombie Aggressive Towards Villager: true
[13:02:15 INFO]: Experience Merge Radius: 3.0
Expand All @@ -173,84 +166,18 @@ If this was the first command issued after a start the output should look like
[13:02:18 INFO]: Done (3.650s)! For help, type "help" or "?"
[13:12:35 INFO]: Set the time to 1000

It will continue to output everything from the console until you press CTRL-C

## starting and stopping the server

To stop the server but not the container do

docker exec spigot mc_stop

To start it after being stopped do

docker exec spigot mc_start

Finally to restart it do

docker exec spiot mc_restart

## stopping the container

When the container is stopped with the command

docker stop spigot

the spigot server is shutdown nicely with a console stop command to give it time to save everything before
stopping the container. If you look in the output from the server this show

[13:01:51 INFO]: Stopping the server
[13:01:51 INFO]: Stopping server
[13:01:51 INFO]: Saving players
[13:01:51 INFO]: nimmis lost connection: Server closed
[13:01:51 INFO]: nimmis left the game.
[13:01:51 INFO]: Saving worlds
[13:01:51 INFO]: Saving chunks for level 'world'/Overworld
[13:01:51 INFO]: Saving chunks for level 'world_nether'/Nether
[13:01:51 INFO]: Saving chunks for level 'world_the_end'/The End

## Having the minecraft files on the host machine

If you delete the container all your filer in minecraft will be gone. To save them where it's
easier to edit and do a backup of the files you can attach a directory from the host machine
(where you run the docker command) and attach it to the local file system in the container.
The syntax for it is

-v /host/path/to/dir:/container/path/to/dir

To attach the minecraft directory in the container to directory /home/nimmis/mc-srv you add

-v /home/nimmis/mc-srv:/minecraft

### problems with external mounted volumes

When a external volume is mounted the UID of the owner of the volume may not match the UID of the minecraft user (1000). This can result in problems with write/read access to the files.

To address this problem a check is done between UID of the owner of /minecraft and the UID of the user minecraft. If there is a mismatch the UID of the minecraft user is changed to match the UID of the directory.

If you don't want to do this and want to manually set the UID of the minecraft user there is a variable named SPIGOT_UID which defines the minecraft user UID, adding

-e SPIGOT_UID=1132

sets the minecraft user UID to 1132.

## Issues
This will show you the server's response to your command. For a full list of commands check the official [wiki](http://minecraft.gamepedia.com/Commands#Summary_of_commands). Exit the log by pressing CTRL-C.

If you have any problems with or questions about this image, please contact us by submitting a ticket through a [GitHub issue](https://github.com/nimmis/docker-spigot/issues "GitHub issue")
## Starting and stopping the minecraft server

1. Look to see if someone already filled the bug, if not add a new one.
2. Add a good title and description with the following information.
- if possible an copy of the output from **cat /etc/BUILDS/*** from inside the container
- any logs relevant for the problem
- how the container was started (flags, environment variables, mounted volumes etc)
- any other information that can be helpful
To stop the minecraft server inside the container run

## Contributing
docker exec mcserver mc_stop

You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.
To start it after being stopped:

## Future features
docker exec mcserver mc_start

- automatic backup
- plugins
- more....
Finally to restart it:

docker exec mcserver mc_restart
10 changes: 9 additions & 1 deletion rootfs/etc/init.d/minecraft_server
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ buildjar() {
java -jar BuildTools.jar --rev $1
cp $SPIGOT_HOME/build/Spigot/Spigot-Server/target/spigot-*.jar $SPIGOT_HOME/spigot-$1.jar
cd $SPIGOT_HOME/
# grab the minecraft server version, download the minecraft client for overviewer
rm -Rf /overviewer/jar
mkdir -p /overviewer/jar
MC_VERSION=`ls -1 /$SPIGOT_HOME/build/work/minecraft_server.*.jar | cut -d'.' -f2- | sed 's/\(.*\)\..*/\1/'`
export MC_VERSION
wget https://s3.amazonaws.com/Minecraft.Download/versions/${MC_VERSION}/${MC_VERSION}.jar -P /overviewer/jar
ls -1t /overviewer/jar | grep -v latest | head -1 | xargs -I{} ln -s {} /overviewer/jar/minecraft_client.latest.jar
chmod -R 777 /overviewer
rm -Rf $SPIGOT_HOME/build
fi
execCMD "rm -f $SPIGOT_HOME/spigot.jar"
Expand Down Expand Up @@ -394,7 +402,7 @@ case "$1" in

log)
echo "Abort with CTRL-C"
tail -f $MC_DIR/output.con
tail -f -n 50 $MC_DIR/output.con
;;

console)
Expand Down
6 changes: 6 additions & 0 deletions rootfs/etc/my_runalways/my_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# save all env variables (incl ones from docker) for crontab use

printenv | grep -v " " | sed 's/^\(.*\)$/export \1/g' > /minecraft/my_env.sh
chmod 755 /minecraft/my_env.sh
chown minecraft:minecraft /minecraft/my_env.sh
Loading