New Minecraft Role
This commit is contained in:
11
roles/minecraft/templates/1minecraft-rc.j2
Normal file
11
roles/minecraft/templates/1minecraft-rc.j2
Normal file
@@ -0,0 +1,11 @@
|
||||
# /etc/conf.d/minecraft
|
||||
#
|
||||
# Minecraft - OpenRC scripts
|
||||
# Copyright (C) 2017-2019 João Brázio [joao@brazio.org]
|
||||
#
|
||||
|
||||
MINHEAP={{ MINHEAP }}
|
||||
MAXHEAP={{ MAXHEAP }}
|
||||
|
||||
# https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
|
||||
#CUSTOMARGS="-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1"
|
||||
125
roles/minecraft/templates/1minecraft.j2
Normal file
125
roles/minecraft/templates/1minecraft.j2
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/sbin/openrc-run
|
||||
# /etc/init.d/minecraft
|
||||
#
|
||||
# Minecraft - OpenRC scripts
|
||||
# Copyright (C) 2017-2019 João Brázio [joao@brazio.org]
|
||||
#
|
||||
# Expects the game folder to be located at /srv/minecraft/<instance>
|
||||
# Don't use directly the /etc/init.d/minecraft script, create a symlink for you instance.
|
||||
#
|
||||
# This is an example for Paper:
|
||||
# - mkdir -p /srv/minecraft/paper
|
||||
# - Download paper jar and place it there
|
||||
# - ln -s /etc/init.d/minecraft /etc/init.d/minecraft.paper
|
||||
# - cp /etc/conf.d/minecraft /etc/conf.d/minecraft.paper
|
||||
#
|
||||
# Dependencies:
|
||||
# - Java VM at /usr/bin/java
|
||||
# - mcrcon [https://github.com/Tiiffi/mcrcon]
|
||||
#
|
||||
|
||||
USER={{ server_user }}
|
||||
GROUP={{ server_user }}
|
||||
|
||||
INSTANCE=${RC_SVCNAME##*.}
|
||||
BASE="/home/{{ server_user }}/minecraft"
|
||||
PIDFILE="/var/run/${RC_SVCNAME}.pid"
|
||||
RCON="/usr/bin/rcon"
|
||||
BIN="$(ls ${BASE} -v 2>/dev/null | grep -i "craftbukkit.*jar\\|spigot.*jar\\|paper*.*jar\\|minecraft_server.*jar" | head -n 1)"
|
||||
|
||||
config_get () {
|
||||
echo $(grep ${1} "${BASE}/server.properties" | cut -d '=' -f 2)
|
||||
}
|
||||
|
||||
depend () {
|
||||
need net
|
||||
}
|
||||
|
||||
start_pre () {
|
||||
if [ -z "${BIN}" ]; then
|
||||
eerror "${RC_SVCNAME} cannot find a proper server jar."
|
||||
eerror "Check your game installation at ${BASE}."
|
||||
return 1
|
||||
fi
|
||||
|
||||
[ -f "${PIDFILE}" ] && rm ${PIDFILE}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
start () {
|
||||
ebegin "Starting Minecraft server ${INSTANCE}"
|
||||
start-stop-daemon --start --chdir ${BASE} --pidfile ${PIDFILE} --make-pidfile \
|
||||
--exec /usr/bin/java --user ${USER} --group ${GROUP} \
|
||||
--background -- -server -Xms${MINHEAP:-128M} -Xmx${MAXHEAP:-1024M} \
|
||||
${CUSTOMARGS} -jar ${BIN} nogui
|
||||
eend $?
|
||||
}
|
||||
|
||||
stop_pre () {
|
||||
if [ ! -f "${BASE}/server.properties" ]; then
|
||||
eerror "${RC_SVCNAME} cannot find a proper server config file."
|
||||
eerror "Check your game installation at ${BASE}."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
stop () {
|
||||
ebegin "Stopping Minecraft server ${INSTANCE}"
|
||||
|
||||
if [ "$(config_get enable-rcon)" = "true" ]; then
|
||||
# Fetch rcon configuration
|
||||
RCON_SRV=$(config_get server.ip)
|
||||
RCON_PORT=$(config_get rcon.port)
|
||||
RCON_PASS=$(config_get rcon.password)
|
||||
|
||||
# Try to soft kill the server
|
||||
${RCON} -H ${RCON_SRV:-127.0.0.1} -p ${RCON_PORT} -m -P ${RCON_PASS} save-all 1>/dev/null 2>&1
|
||||
${RCON} -H ${RCON_SRV:-127.0.0.1} -p ${RCON_PORT} -m -P ${RCON_PASS} stop 1>/dev/null 2>&1
|
||||
|
||||
i=0
|
||||
PID=$(cat ${PIDFILE})
|
||||
|
||||
while [ "${i}" -le 30 ]; do
|
||||
kill -0 ${PID} 2>/dev/null && sleep 1 || break
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
fi
|
||||
|
||||
# Hard stop the server
|
||||
start-stop-daemon --stop --chdir ${BASE} --pidfile ${PIDFILE} --user ${USER} --group ${GROUP} --retry 5 2>/dev/null
|
||||
eend 0
|
||||
}
|
||||
|
||||
status () {
|
||||
if [ "$(config_get enable-rcon)" = "true" ]; then
|
||||
# Fetch rcon configuration
|
||||
RCON_SRV=$(config_get server.ip)
|
||||
RCON_PORT=$(config_get rcon.port)
|
||||
RCON_PASS=$(config_get rcon.password)
|
||||
|
||||
${RCON} -H ${RCON_SRV:-127.0.0.1} -p ${RCON_PORT} -m -P ${RCON_PASS} version
|
||||
${RCON} -H ${RCON_SRV:-127.0.0.1} -p ${RCON_PORT} -m -P ${RCON_PASS} tps
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
backup() {
|
||||
saveoff
|
||||
|
||||
NOW=`date "+%Y-%m-%d_%Hh%M"`
|
||||
BACKUP_FILE="${BACKUP_BASE}/backup_${NOW}.tar"
|
||||
einfo "Backing up minecraft world..."
|
||||
as_user "tar -C \"${BASE}\" -cf \"$BACKUP_FILE\" ${WORLDS}"
|
||||
|
||||
einfo "Backing up ${BIN}"
|
||||
as_user "tar -C \"${BASE}\" -rf \"$BACKUP_FILE\" ${BIN} server.properties"
|
||||
|
||||
saveon
|
||||
|
||||
einfo "Compressing backup..."
|
||||
as_user "gzip -f \"$BACKUP_FILE\""
|
||||
einfo "Done."
|
||||
}
|
||||
8
roles/minecraft/templates/backup_server.j2
Normal file
8
roles/minecraft/templates/backup_server.j2
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Working dir
|
||||
cd /home/{{ server_user }}/backups
|
||||
# Delete old backups
|
||||
find . -name "backup_*.tar.gz" -type f -mtime +1 -delete
|
||||
# Start backup
|
||||
rc-service minecraftd backup
|
||||
1
roles/minecraft/templates/hosts.j2
Normal file
1
roles/minecraft/templates/hosts.j2
Normal file
@@ -0,0 +1 @@
|
||||
127.0.0.1 {{ inventory_hostname }}.my.domain {{ inventory_hostname }} localhost.localdomain localhost
|
||||
23
roles/minecraft/templates/minecraft-rc.j2
Normal file
23
roles/minecraft/templates/minecraft-rc.j2
Normal file
@@ -0,0 +1,23 @@
|
||||
# /etc/conf.d/minecraft
|
||||
#
|
||||
# Minecraft - OpenRC scripts
|
||||
# Copyright (C) 2024 Santic Zombie [email@santic-zombie.ru]
|
||||
#
|
||||
#
|
||||
|
||||
MINHEAP={{ MINHEAP }}
|
||||
MAXHEAP={{ MAXHEAP }}
|
||||
|
||||
USER={{ server_user }}
|
||||
GROUP={{ server_user }}
|
||||
|
||||
BASE="/home/{{ server_user }}/minecraft"
|
||||
BACKUP_BASE="/home/{{ server_user }}/backups"
|
||||
|
||||
SCREENNAME="Minecraft"
|
||||
|
||||
WORLDS="{{ level_name }} {{ level_name }}_nether {{ level_name }}_the_end"
|
||||
|
||||
|
||||
# https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
|
||||
#CUSTOMARGS="-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1"
|
||||
158
roles/minecraft/templates/minecraft.j2
Normal file
158
roles/minecraft/templates/minecraft.j2
Normal file
@@ -0,0 +1,158 @@
|
||||
#!/sbin/openrc-run
|
||||
# /etc/init.d/minecraft
|
||||
#
|
||||
# Minecraft - OpenRC scripts
|
||||
# Copyright (C) 2024 Santic Zombie [email@santic-zombie.ru]
|
||||
#
|
||||
#
|
||||
|
||||
extra_commands="reload backup listen"
|
||||
|
||||
INSTANCE=${RC_SVCNAME##*.}
|
||||
PIDFILE="/var/run/${RC_SVCNAME}.pid"
|
||||
BIN="$(ls ${BASE} -v 2>/dev/null | grep -i "craftbukkit.*jar\\|spigot.*jar\\|paper*.*jar\\|minecraft_server.*jar" | head -n 1)"
|
||||
INVOCATION="/usr/bin/java -server -Xms${MINHEAP:-128M} -Xmx${MAXHEAP:-1024M} \
|
||||
${CUSTOMARGS} -jar ${BIN} nogui"
|
||||
|
||||
depend() {
|
||||
need net localmount
|
||||
after bootmisc
|
||||
use logger
|
||||
}
|
||||
|
||||
ME=`whoami`
|
||||
as_user() {
|
||||
if [ "${ME}" = "${USER}" ] ; then
|
||||
ash -c "$1"
|
||||
else
|
||||
su - "${USER}" -c "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
start_pre () {
|
||||
if [ -z "${BIN}" ]; then
|
||||
eerror "${RC_SVCNAME} cannot find a proper server jar."
|
||||
eerror "Check your game installation at ${BASE}."
|
||||
return 1
|
||||
fi
|
||||
|
||||
[ -f "${PIDFILE}" ] && rm ${PIDFILE}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
start () {
|
||||
ebegin "Starting Minecraft server daemon"
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
einfo "Minecraft server is already running!"
|
||||
else
|
||||
ebegin "Starting in progress"
|
||||
cd "${BASE}"
|
||||
as_user "cd ${BASE} && screen -dmS ${SCREENNAME} ${INVOCATION}"
|
||||
sleep 10
|
||||
pgrep -f "${BIN}" | tail -1 > "${PIDFILE}"
|
||||
if pgrep -u "${USER}" -f "${BIN}" | tail -1 > /dev/null ; then
|
||||
einfo "${INSTANCE} is now running."
|
||||
else
|
||||
eerror "Error! Could not start ${INSTANCE}! :("
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
stop() {
|
||||
ebegin "Stopping Minecraft server daemon"
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
ebegin "Stopping in progress"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER SHUTTING DOWN IN 30 SECONDS. Saving map...\"\015'"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-all\"\015'"
|
||||
sleep 10
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"stop\"\015'"
|
||||
sleep 10
|
||||
else
|
||||
einfo "${INSTANCE} was not running."
|
||||
fi
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
eerror "Error! ${INSTANCE} could not be stopped."
|
||||
else
|
||||
einfo "${INSTANCE} is stopped."
|
||||
fi
|
||||
|
||||
# Hard stop the server
|
||||
start-stop-daemon --stop --chdir ${BASE} --pidfile ${PIDFILE} --user ${USER} --group ${GROUP} --retry 5 2>/dev/null
|
||||
eend 0
|
||||
}
|
||||
|
||||
restart() {
|
||||
ebegin "Reload Minecraft server daemon"
|
||||
stop
|
||||
start
|
||||
eend $?
|
||||
}
|
||||
|
||||
reload() {
|
||||
ebegin "Reload Minecraft server"
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
ebegin "Reloading in progress"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER RELOADING IN 40 SECONDS. Saving map...\"\015'"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-all\"\015'"
|
||||
sleep 10
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"reload\"\015'"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"reload confirm\"\015'"
|
||||
sleep 10
|
||||
else
|
||||
einfo "${INSTANCE} was not running."
|
||||
fi
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
einfo "Server reloaded."
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER SUCCESSFULLY RELOADED!\"\015'"
|
||||
else
|
||||
eerror "Error! ${INSTANCE} could not reloaded! :("
|
||||
fi
|
||||
}
|
||||
|
||||
saveoff() {
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
einfo "Server is running... suspending saves"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER BACKUP STARTING. Server going readonly...\"\015'"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-off\"\015'"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-all\"\015'"
|
||||
sync
|
||||
sleep 10
|
||||
else
|
||||
einfo "${INSTANCE} is not running."
|
||||
fi
|
||||
}
|
||||
|
||||
saveon() {
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
einfo "Server is running... re-enabling saves"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"save-on\"\015'"
|
||||
as_user "screen -p 0 -S ${SCREENNAME} -X eval 'stuff \"say SERVER BACKUP ENDED. Server going read-write...\"\015'"
|
||||
else
|
||||
echo "${INSTANCE} is not running. Not resuming saves."
|
||||
fi
|
||||
}
|
||||
|
||||
backup() {
|
||||
saveoff
|
||||
|
||||
NOW=`date "+%Y-%m-%d_%Hh%M"`
|
||||
BACKUP_FILE="${BACKUP_BASE}/backup_${NOW}.tar"
|
||||
einfo "Backing up minecraft server..."
|
||||
as_user "tar -C \"${BASE}\" -cf \"$BACKUP_FILE\" ."
|
||||
|
||||
saveon
|
||||
|
||||
einfo "Compressing backup..."
|
||||
as_user "gzip -f \"$BACKUP_FILE\""
|
||||
einfo "Done."
|
||||
}
|
||||
|
||||
listen() {
|
||||
if pgrep -u "${USER}" -f "${BIN}" > /dev/null ; then
|
||||
as_user "tail -f ${BASE}/logs/latest.log"
|
||||
else
|
||||
echo "${INSTANCE} is not running. Cannot listen to server."
|
||||
fi
|
||||
}
|
||||
14
roles/minecraft/templates/motd.j2
Normal file
14
roles/minecraft/templates/motd.j2
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
Welcome to {{ inventory_hostname }} Server! ^_^
|
||||
|
||||
:\ /; _
|
||||
; \___/ ; ; ;
|
||||
,:-"' `"-:. / ;
|
||||
_ /,---. ,---.\ _ _; /
|
||||
_:>(( | ) ( | ))<:_ ,-""_,"
|
||||
\````` `````/""""",-""
|
||||
'-.._ v _..-' )
|
||||
/ ___ ____,.. \
|
||||
/ / | | | ( \. \
|
||||
nya / / | | | | \ \
|
||||
`" `" `" `"
|
||||
58
roles/minecraft/templates/nginx.j2
Normal file
58
roles/minecraft/templates/nginx.j2
Normal file
@@ -0,0 +1,58 @@
|
||||
user {{ nginx_user }};
|
||||
worker_processes {{ worker_processes }};
|
||||
|
||||
error_log {{ log_dir }}/error.log;
|
||||
error_log {{ log_dir }}/error.log notice;
|
||||
error_log {{ log_dir }}/error.log info;
|
||||
|
||||
events {
|
||||
worker_connections {{ worker_connections }};
|
||||
}
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log {{ log_dir }}/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
#keepalive_timeout 65;
|
||||
gzip on;
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
#server_name _;
|
||||
|
||||
root /srv/dynmap/web;
|
||||
|
||||
index index.php index.html index.htm;
|
||||
|
||||
location / {
|
||||
# First attempt to serve request as file, then
|
||||
# as directory, then fall back to displaying a 404.
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# pass PHP scripts to FastCGI server
|
||||
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
location ~ /\.ht {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
|
||||
#include sites-enabled/*;
|
||||
}
|
||||
59
roles/minecraft/templates/server.properties.j2
Normal file
59
roles/minecraft/templates/server.properties.j2
Normal file
@@ -0,0 +1,59 @@
|
||||
enable-jmx-monitoring=false
|
||||
rcon.port={{ rcon_port }}
|
||||
level-seed=
|
||||
gamemode={{ gamemode }}
|
||||
enable-command-block=false
|
||||
enable-query=false
|
||||
generator-settings={}
|
||||
enforce-secure-profile={{ enforce_secure_profile }}
|
||||
level-name={{ level_name }}
|
||||
motd={{ server_status }}
|
||||
query.port={{ game_port }}
|
||||
pvp={{ pvp }}
|
||||
generate-structures=true
|
||||
max-chained-neighbor-updates={{ neighbor_updates }}
|
||||
difficulty={{ difficulty }}
|
||||
network-compression-threshold={{ network_compression_threshold }}
|
||||
max-tick-time=60000
|
||||
require-resource-pack=false
|
||||
use-native-transport=true
|
||||
max-players={{ max_players }}
|
||||
online-mode=false
|
||||
enable-status=true
|
||||
allow-flight=false
|
||||
initial-disabled-packs=
|
||||
broadcast-rcon-to-ops=true
|
||||
view-distance={{ view_distance }}
|
||||
server-ip=
|
||||
resource-pack-prompt=
|
||||
allow-nether=true
|
||||
server-port={{ game_port }}
|
||||
enable-rcon={{ enable_rcon }}
|
||||
sync-chunk-writes=true
|
||||
resource-pack-id=
|
||||
op-permission-level={{ op_permission_level }}
|
||||
prevent-proxy-connections=false
|
||||
hide-online-players=false
|
||||
resource-pack=
|
||||
entity-broadcast-range-percentage={{ entity_broadcast_range }}
|
||||
simulation-distance={{ simulation_distance }}
|
||||
rcon.password={{ rcon_password }}
|
||||
player-idle-timeout=0
|
||||
debug=false
|
||||
force-gamemode=false
|
||||
rate-limit=0
|
||||
hardcore=false
|
||||
white-list=false
|
||||
broadcast-console-to-ops=true
|
||||
spawn-npcs=true
|
||||
spawn-animals=true
|
||||
log-ips=true
|
||||
function-permission-level=2
|
||||
initial-enabled-packs=vanilla
|
||||
level-type=minecraft\:normal
|
||||
text-filtering-config=
|
||||
spawn-monsters=true
|
||||
enforce-whitelist=false
|
||||
spawn-protection={{ spawn_protection }}
|
||||
resource-pack-sha1=
|
||||
max-world-size=29999984
|
||||
6
roles/minecraft/templates/sshd_config.j2
Normal file
6
roles/minecraft/templates/sshd_config.j2
Normal file
@@ -0,0 +1,6 @@
|
||||
Port {{ ssh_port }}
|
||||
PubkeyAuthentication yes
|
||||
PasswordAuthentication no
|
||||
PermitEmptyPasswords no
|
||||
ChallengeResponseAuthentication no
|
||||
Subsystem sftp /usr/lib/ssh/sftp-server
|
||||
Reference in New Issue
Block a user