Skip to content

Commit 3856182

Browse files
committed
Updating for V1.4
Updated template-vars settings and comments. Fixed/added to minecraftctl.sh . Updated README, including V1.4 changelog. More details within README
1 parent b620d96 commit 3856182

3 files changed

Lines changed: 199 additions & 131 deletions

File tree

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This project defines a template systemd service unit file for hosting several minecraft servers via docker.
44
This repo was forked from the version by [nathanielc](https://github.com/nathanielc/minecraft-multi-server)
55

6-
# Install
6+
## Install
77

88
This system runs the minecraft server in a docker container, so you must first install docker.
99

@@ -21,11 +21,11 @@ NOTE: `grep` and `sed` are also required in order to watch the minecraft logs fo
2121

2222
NOTE: You may need to add your user to the minecraft group to modify files within `/srv/minecraft/` without the need to use super user.
2323

24-
# AUR Package
24+
### AUR Package
2525

2626
AUR package available [here](https://aur.archlinux.org/packages/minecraft-server-manager/)
2727

28-
# Usage
28+
## Usage
2929

3030
Run `minecraftctl` to view usage message.
3131

@@ -36,7 +36,7 @@ Running `minecraftctl start <NAME>` will start the server without the systemd se
3636
Each is given a name and can be configured in an `/etc/minecraft/<NAME>` file.
3737
A template configuration file is supplied as `/etc/minecraft/default` with most available options
3838

39-
## EULA
39+
### EULA
4040

4141
Minecraft requires that you accept the EULA in order to run a server.
4242
Either add `EULA=true` to all your `/etc/minecraft/<NAME>` files, or edit the `minecraftctl.sh` script to set `EULA=true` for all worlds.
@@ -99,7 +99,22 @@ sudo systemctl enable minecraftd-backup@<NAME>.timer
9999
sudo systemctl start minecraftd-backup@<NAME>.timer
100100
```
101101

102+
If you would like a one time backup instead, your can run the backup service or use the control script.
103+
104+
For example:
105+
106+
```
107+
sudo systemctl start minecraftd-backup@<NAME>.service
108+
```
109+
110+
or
111+
112+
```
113+
minecraftctl backup <NAME>
114+
```
115+
102116
This will enable weekly backups of a server.
117+
103118
Backups are stored in `$DATA_DIR/$BACKUP_DIR` which is `/srv/minecraft/<NAME>/backups` by default.
104119
If you want to copy them off-site you will need to manage that yourself.
105120

@@ -119,3 +134,22 @@ If you run into an issue (especially any that you believe to be a bug), please f
119134
This project is based on nathianielc's minecraft-multi-server [here](https://github.com/nathanielc/minecraft-multi-server) and as such, is leveraging the work of the https://hub.docker.com/r/itzg/minecraft-server/ docker container for minecraft.
120135
Many thanks to both projects for making this one possible.
121136

137+
## Changelog
138+
139+
- 1.1
140+
- Initial rewrite of code to fit personal style
141+
- 1.2
142+
- Fixed an error in `Makefile` which caused failed builds
143+
- 1.3
144+
- Fixed an error in `Makefile` which caused `minecraftctl` script to be non-executable
145+
- 1.3.1
146+
- Fixed memory allocation issue which was causing servers to always be limited to 1G memory
147+
- Setting memory within `JVM_OPTS` using the `-Xmx` and `-Xms` flags fails to set memory, using docker flags `MAX_MEMORY` and `INIT_MEMORY` works properly
148+
- Within the start-minecraftFinalSetup file from https://github.com/itgz/docker-minecraft-server/ (line 155 as of March 13, 2021), the setup overrides the `-Xmx` and `-Xms` JVM flags using the `MAX_MEMORY` and `INIT_MEMORY` variables
149+
- 1.4
150+
- Updated template-vars file with some additional settings and better comments on settings
151+
- Added WORLD and SPAWN_PROTECTION settings
152+
- Fixed an issue with copying server-icon.png that would cause an existing world to fail to restart if a server icon exists and should be copied
153+
- When starting, the script would only check if the desired icon file exists, which would cause the script to attempt to overwrite the icon within the server directory, leading to permission denied and the script exiting due to failure
154+
- Added SPAWN_PROTECTION option to docker call for starting server
155+
- Reordered environment variables checks to look a bit nicer

src/minecraftctl.sh

Lines changed: 118 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function start {
5656
stop_container
5757

5858
# Copy requested server icon if it exists
59-
if [[ -f "${ICON}" ]]; then
59+
if [[ -f "${ICON}" ]] && [[ ! -f "${DATA_DIR}/${name}/server-icon.png" ]]; then
6060
mkdir "${DATA_DIR}/${name}"
6161
cp "${ICON}" "${DATA_DIR}/${name}/server-icon.png"
6262
fi
@@ -66,7 +66,7 @@ function start {
6666
vol_mount=""
6767
echo "Ephemeral server, a restart will lose all world data"
6868
fi
69-
# -e "JVM_OPTS=-Xmx${MAXHEAP}M -Xms${MINHEAP}M -D${name}" \
69+
7070
$DOCKER run -d -i \
7171
--name "$name" \
7272
$vol_mount \
@@ -109,6 +109,7 @@ function start {
109109
-e "GID=$MINECRAFT_GID" \
110110
-e "ENABLE_AUTOPAUSE=$AUTOPAUSE" \
111111
-e "TIMEOUT=$TIMEOUT" \
112+
-e "SPAWN_PROTECTION=$SPAWN_PROTECTION" \
112113
itzg/minecraft-server
113114

114115
echo "Started minecraft container $name"
@@ -196,120 +197,151 @@ if [[ -z "$name" ]]; then
196197
elif [[ "x$name" == "xdefault" ]]; then
197198
unuseable_name
198199
fi
200+
199201
# Attempt to source the related configuration file
200202
if [[ -f "/etc/minecraft/$name" ]]; then
201203
source "/etc/minecraft/$name"
202204
fi
205+
206+
# Check Environment variables
207+
208+
# Get system default docker path if none is provided in configuration file
209+
if [[ -z $DOCKER ]]; then
210+
DOCKER=$(which docker)
211+
fi
212+
# Default listen port
213+
# This is the published host port,
214+
# internally, the container always listens on 25565
215+
if [[ -z $PORT ]]; then
216+
PORT="25565"
217+
fi
218+
# Default listen port for Rcon
219+
# This is the published host port,
220+
# internally, the container always listens on 25575
221+
if [[ -z $RCON_PORT ]]; then
222+
RCON_PORT="25575"
223+
fi
224+
# Default Rcon password
225+
if [[ -z $RCON_PASSWORD ]]; then
226+
RCON_PASSWORD="minecraft"
227+
fi
228+
# Set Rcon command template
229+
RCON_CMD="mcrcon -P ${RCON_PORT} -p ${RCON_PASSWORD}"
230+
# Default min java heap size in MB
231+
if [[ -z $MINHEAP ]]; then
232+
MINHEAP="512"
233+
fi
234+
# Default max java heap size in MB
235+
if [[ -z $MAXHEAP ]]; then
236+
MAXHEAP="2048"
237+
fi
238+
# EULA - Defaults to false, must be set to true to start server
239+
if [[ -z $EULA ]]; then
240+
EULA=false
241+
fi
203242
# Server type
204243
if [[ -z $TYPE ]]; then
205244
TYPE="vanilla"
206245
fi
207-
# Docker autopause
208-
if [[ -z $AUTOPAUSE ]]; then
209-
AUTOPAUSE=true
210-
fi
211-
# Level type
212-
if [[ -z $LEVEL_TYPE ]]; then
213-
LEVEL_TYPE="default"
246+
# Game version
247+
if [[ -z $VERSION ]]; then
248+
VERSION="LATEST"
214249
fi
215-
# PVP
216-
if [[ -z $PVP ]]; then
217-
PVP=true
250+
# Game difficulty
251+
if [[ -z $DIFFICULTY ]]; then
252+
DIFFICULTY="normal"
218253
fi
219-
# Message of the day
220-
if [[ -z $MOTD ]]; then
221-
MOTD="A Minecraft server"
254+
# Server icon
255+
if [[ -z $ICON ]]; then
256+
ICON="/srv/minecraft/default/server-icon.png"
222257
fi
223-
# View distance
224-
if [[ -z $VIEW_DISTANCE ]]; then
225-
VIEW_DISTANCE=10
258+
# Max players
259+
if [[ -z $MAX_PLAYERS ]]; then
260+
MAX_PLAYERS="10"
226261
fi
227-
# Spawn NPCs
228-
if [[ -z $SPAWN_NPCS ]]; then
229-
SPAWN_NPCS=true
262+
# Max world size
263+
if [[ -z $MAX_WORLD_SIZE ]]; then
264+
MAX_WORLD_SIZE="29999984"
230265
fi
231-
# Spawn monsters
232-
if [[ -z $SPAWN_MONSTERS ]]; then
233-
SPAWN_MONSTERS=true
266+
# Allow nether
267+
if [[ -z $ALLOW_NETHER ]]; then
268+
ALLOW_NETHER=true
234269
fi
235-
# Max tick time
236-
if [[ -z $MAX_TICK_TIME ]]; then
237-
MAX_TICK_TIME=60000
270+
# Announce player achievements
271+
if [[ -z $ANNOUNCE_PLAYER_ACHIEVEMENTS ]]; then
272+
ANNOUNCE_PLAYER_ACHIEVEMENTS=true
238273
fi
239-
# Max build height
240-
if [[ -z $MAX_BUILD_HEIGHT ]]; then
241-
MAX_BUILD_HEIGHT=256
274+
# Enable command blocks
275+
if [[ -z $ENABLE_COMMAND_BLOCK ]]; then
276+
ENABLE_COMMAND_BLOCK=false
242277
fi
243-
# Hardcore
244-
if [[ -z $HARDCORE ]]; then
245-
HARDCORE=false
278+
# Force gamemode
279+
if [[ -z $FORCE_GAMEMODE ]]; then
280+
FORCE_GAMEMODE=false
246281
fi
247282
# Generate structures
248283
if [[ -z $GENERATE_STRUCTURES ]]; then
249284
GENERATE_STRUCTURES=true
250285
fi
251-
# Force gamemode
252-
if [[ -z $FORCE_GAMEMODE ]]; then
253-
FORCE_GAMEMODE=false
286+
# Hardcore
287+
if [[ -z $HARDCORE ]]; then
288+
HARDCORE=false
254289
fi
255-
# Enable command blocks
256-
if [[ -z $ENABLE_COMMAND_BLOCK ]]; then
257-
ENABLE_COMMAND_BLOCK=false
290+
# Max build height
291+
if [[ -z $MAX_BUILD_HEIGHT ]]; then
292+
MAX_BUILD_HEIGHT=256
258293
fi
259-
# Announce player achievements
260-
if [[ -z $ANNOUNCE_PLAYER_ACHIEVEMENTS ]]; then
261-
ANNOUNCE_PLAYER_ACHIEVEMENTS=true
294+
# Max tick time
295+
if [[ -z $MAX_TICK_TIME ]]; then
296+
MAX_TICK_TIME=60000
262297
fi
263-
# Allow nether
264-
if [[ -z $ALLOW_NETHER ]]; then
265-
ALLOW_NETHER=true
298+
# Spawn monsters
299+
if [[ -z $SPAWN_MONSTERS ]]; then
300+
SPAWN_MONSTERS=true
266301
fi
267-
# Max world size
268-
if [[ -z $MAX_WORLD_SIZE ]]; then
269-
MAX_WORLD_SIZE="29999984"
302+
# Spawn NPCs
303+
if [[ -z $SPAWN_NPCS ]]; then
304+
SPAWN_NPCS=true
270305
fi
271-
# Max players
272-
if [[ -z $MAX_PLAYERS ]]; then
273-
MAX_PLAYERS="10"
306+
# View distance
307+
if [[ -z $VIEW_DISTANCE ]]; then
308+
VIEW_DISTANCE=10
274309
fi
275-
# Server icon
276-
if [[ -z $ICON ]]; then
277-
ICON="/srv/minecraft/default/server-icon.png"
310+
# Gamemode ?
311+
if [[ -z $MODE ]]; then
312+
MODE="survival"
278313
fi
279-
# Game difficulty
280-
if [[ -z $DIFFICULTY ]]; then
281-
DIFFICULTY="normal"
314+
# Message of the day
315+
if [[ -z $MOTD ]]; then
316+
MOTD="A Minecraft server"
282317
fi
283-
# Game version
284-
if [[ -z $VERSION ]]; then
285-
VERSION="LATEST"
318+
# PVP
319+
if [[ -z $PVP ]]; then
320+
PVP=true
286321
fi
287-
# Default listen port
288-
# This is the published host port,
289-
# internally the container always listens on 25565
290-
if [[ -z $PORT ]]; then
291-
PORT="25565"
322+
# Level type
323+
if [[ -z $LEVEL_TYPE ]]; then
324+
LEVEL_TYPE="default"
292325
fi
293-
# Default listen port for rcon
294-
# This is the published host port,
295-
# internally the container always listens on 25575
296-
if [[ -z $RCON_PORT ]]; then
297-
RCON_PORT="25575"
326+
# Name of world dir
327+
if [[ -z $LEVEL ]]; then
328+
LEVEL="world"
298329
fi
299-
if [[ -z $RCON_PASSWORD ]]; then
300-
RCON_PASSWORD="minecraft"
330+
# World folder name ?
331+
if [[ -z $WORLD ]]; then
332+
WORLD="world"
301333
fi
302-
RCON_CMD="mcrcon -P ${RCON_PORT} -p ${RCON_PASSWORD}"
303-
# Default max java heap size in MB
304-
if [[ -z $MAXHEAP ]]; then
305-
MAXHEAP="2048"
334+
# IDs of minecraft user and group
335+
MINECRAFT_UID=$(id -u minecraft)
336+
MINECRAFT_GID=$(id -g minecraft)
337+
# Docker autopause
338+
if [[ -z $AUTOPAUSE ]]; then
339+
AUTOPAUSE=true
306340
fi
307-
# Default min java heap size in MB
308-
if [[ -z $MINHEAP ]]; then
309-
MINHEAP="512"
341+
# Game command timeout
342+
if [[ -z $TIMEOUT ]]; then
343+
TIMEOUT="0"
310344
fi
311-
# Path to docker executable
312-
DOCKER=$(which docker)
313345
# Wether to mount a persistent volume for the server
314346
# If true a volume will not be mounted and a restart will lose all world data
315347
if [[ -z $EPHEMERAL ]]; then
@@ -323,26 +355,15 @@ fi
323355
if [[ -z $BACKUP_DIR ]]; then
324356
BACKUP_DIR="./backups"
325357
fi
326-
# IDs of minecraft user and group
327-
MINECRAFT_UID=$(id -u minecraft)
328-
MINECRAFT_GID=$(id -g minecraft)
329-
# Name of world dir
330-
if [[ -z $LEVEL ]]; then
331-
LEVEL="world"
332-
fi
333-
# Game command timeout
334-
if [[ -z $TIMEOUT ]]; then
335-
TIMEOUT="0"
358+
# Default spawn protection region
359+
if [[ -z $SPAWN_PROTECTION ]]; then
360+
SPAWN_PROTECTION=64
336361
fi
337-
# EULA
338-
if [[ -z $EULA ]]; then
339-
EULA=false
340-
fi
341-
362+
# Set debug flag to print trace for select commands
342363
if [[ -n "$DEBUG" ]]; then
343364
set -x
344365
fi
345-
366+
# Handle command issued to script
346367
case "$1" in
347368
status) status;;
348369
start) start;;

0 commit comments

Comments
 (0)