Initial commit

This commit is contained in:
Philip Abernethy 2015-07-03 19:16:00 +02:00
commit 2c972cc099
8 changed files with 294 additions and 0 deletions

33
.SRCINFO Normal file
View File

@ -0,0 +1,33 @@
pkgbase = minecraft-server
pkgdesc = Minecraft server unit files, script, and jar
pkgver = 1.8.6
pkgrel = 1
url = http://minecraft.net/
install = minecraft-server.install
arch = any
license = custom
depends = java-runtime-headless
depends = systemd
depends = screen
depends = expect
conflicts = minecraft-server-systemd
conflicts = minecraft-canary
noextract = minecraft_server.1.8.6.jar
options = !strip
options = emptydirs
backup = etc/conf.d/minecraft
source = https://s3.amazonaws.com/Minecraft.Download/versions/1.8.6/minecraft_server.1.8.6.jar
source = minecraftd
source = minecraftd-diag
source = minecraftd.service
source = minecraftctl
source = conf.minecraft
sha256sums = 7fc66b2b54f0f4d65fdd6d6484a50f432c144ef02072d3435d5660f120f58e0d
sha256sums = 043101c29d4b4f9092cb93ef52168cfe3d16d49ff573136f4fbb45071a38a5d1
sha256sums = de03317d02668bb71ec160fff497c7fbfe8b03ffff2950c6a0bcfb39f69cd214
sha256sums = 6eb4c085b8377712671445b891a3a2cf2a17cf7a7bea66be456a980c2b620e23
sha256sums = 472e06e1bd63838e88ace0bd2f971f72f2efd9e541cc0956599a44c324fd49ac
sha256sums = 738e10185df160d190a5f4f0226de110d67ba023877e4999a6d3ef41c9918ed6
pkgname = minecraft-server

40
PKGBUILD Normal file
View File

@ -0,0 +1,40 @@
# Maintainer: Philip Abernethy <chais.z3r0@gmail.com>
pkgname=minecraft-server
pkgver=1.8.6
pkgrel=1
pkgdesc="Minecraft server unit files, script, and jar"
arch=(any)
url="http://minecraft.net/"
license=('custom')
depends=('java-runtime-headless' 'systemd' 'screen' 'expect')
conflicts=('minecraft-server-systemd' 'minecraft-canary')
options=(!strip emptydirs)
install=minecraft-server.install
backup=('etc/conf.d/minecraft')
source=(https://s3.amazonaws.com/Minecraft.Download/versions/${pkgver}/minecraft_server.${pkgver}.jar
minecraftd
minecraftd-diag
minecraftd.service
minecraftctl
conf.minecraft)
noextract=("minecraft_server.${pkgver}.jar")
sha256sums=('7fc66b2b54f0f4d65fdd6d6484a50f432c144ef02072d3435d5660f120f58e0d'
'043101c29d4b4f9092cb93ef52168cfe3d16d49ff573136f4fbb45071a38a5d1'
'de03317d02668bb71ec160fff497c7fbfe8b03ffff2950c6a0bcfb39f69cd214'
'6eb4c085b8377712671445b891a3a2cf2a17cf7a7bea66be456a980c2b620e23'
'472e06e1bd63838e88ace0bd2f971f72f2efd9e541cc0956599a44c324fd49ac'
'738e10185df160d190a5f4f0226de110d67ba023877e4999a6d3ef41c9918ed6')
package() {
install -Dm755 "${srcdir}/minecraftd" "${pkgdir}/usr/bin/minecraftd"
install -Dm755 "${srcdir}/minecraftd-diag" "${pkgdir}/usr/bin/minecraftd-diag"
install -Dm755 "${srcdir}/minecraftctl" "${pkgdir}/usr/bin/minecraftctl"
install -Dm644 "${srcdir}/minecraft_server.${pkgver}".jar "${pkgdir}/srv/minecraft/minecraft_server.${pkgver}".jar
ln -s "minecraft_server.${pkgver}.jar" "${pkgdir}/srv/minecraft/minecraft_server.jar"
install -Dm644 "${srcdir}/minecraftd.service" "${pkgdir}/usr/lib/systemd/system/minecraftd.service"
install -Dm644 "${srcdir}/conf.minecraft" "${pkgdir}/etc/conf.d/minecraft"
install -d "${pkgdir}/srv/minecraft/backup"
}

37
conf.minecraft Normal file
View File

@ -0,0 +1,37 @@
# MINECRAFT SERVER LAUNCH CONFIGS
# not to be confused with server.properties.
# Server root directory
_SRVDIR=/srv/minecraft
# World directory (relative to SRVDIR)
# Ensure that this matches what is in your server.properties,
# or else the wrong folder will be backed up!
WORLD=world
# Maximum RAM usage (change to suit your needs)
MAXHEAP=1024M
# Minimum RAM usage (change to suit your needs)
MINHEAP=512M
# Number of concurrent threads (no more than the number of logical processors in your system)
THREADS=1
# Where to store backup files
BACKUPPATH=/srv/minecraft/backup
# What to say to the server when backup starts
BACKUPSTARTMSG="WORLD BACKUP STARTING. Server going read-only..."
# What to say when to the server when backup ends
BACKUPENDMSG="WORLD BACKUP ENDED. Server going read-write..."
## Only change these if you know what you're doing
# Server JAR file
SERVERJAR=minecraft_server.jar
SERVICE=${SERVERJAR}
# User to run server under
MCUSER=minecraft

33
minecraft-server.install Normal file
View File

@ -0,0 +1,33 @@
post_install() {
post_upgrade
}
post_upgrade() {
getent group "minecraft" &>/dev/null || groupadd -r minecraft 1>/dev/null
getent passwd "minecraft" &>/dev/null && usermod -s "/usr/bin/nologin" minecraft &>/dev/null || useradd -r -g minecraft -d "/srv/minecraft" -s "/usr/bin/nologin" minecraft 1>/dev/null
touch /srv/minecraft/server.log
chown -R minecraft:minecraft "/srv/minecraft" 1>/dev/null
ln -s /srv/minecraft/server.log /var/log/minecraft.log &>/dev/null
# Removes old data from previous version
cat << EOF
==> World data is stored under /srv/minecraft
==> The server runs as "minecraft", not root
==> You can access the server's console as root with:
$ screen -r minecraft
==> The systemd service is called "minecraftd.service"
==> Calling "stop" or "restart" with systemctl will gracefully exit the server, saving world data
==> Modify /etc/conf.d/minecraft to change the invocation of the server if you wish
==> A script at /usr/bin/minecraftctl is also provided. See the wiki for details on its usage.
==> For the server to start you have to accept the EULA in /srv/minecraft/eula.txt
EOF
}
post_remove() {
if getent passwd "minecraft" >/dev/null; then
userdel minecraft >/dev/null
fi
if getent group "minecraft" >/dev/null; then
groupdel minecraft >/dev/null
fi
}

124
minecraftctl Normal file
View File

@ -0,0 +1,124 @@
#!/bin/bash
# Adapted from generic minecraft init script
# http://www.minecraftwiki.net/wiki/Tutorials/Server_startup_script
#
# Main Differences:
# - Start stop and reload is handled by systemd, removed
# - update handled by pacman, removed
# - changed from init script to "minecraftctl" command.
# - uses /etc/conf.d/minecraftd for variables
#
# Changes:
#
# Changed running screen to work as root, broke it out into mc_docommand
# Commented echo commands for successful execution to not spam the log.
. /etc/conf.d/minecraft || echo "can't source /etc/conf.d/minecraft"
ME=`whoami`
as_user() {
if [ $ME == $MCUSER ] ; then
bash -c "$1"
else
su - $MCUSER -c "$1"
fi
}
mc_saveoff() {
if pgrep -u $MCUSER -f $SERVICE > /dev/null
then
#echo "$SERVICE is running... suspending saves"
mc_docommand "say $BACKUPSTARTMSG"
mc_docommand save-off
mc_docommand save-all
sync
sleep 10
else
echo "$SERVICE is not running. Not suspending saves."
fi
}
mc_saveon() {
if pgrep -u $MCUSER -f $SERVICE > /dev/null
then
#echo "$SERVICE is running... re-enabling saves"
mc_docommand save-on
mc_docommand "say $BACKUPENDMSG"
else
echo "$SERVICE is not running. Not resuming saves."
fi
}
mc_backup() {
mc_saveoff
NOW=`date "+%Y-%m-%d_%Hh%M"`
BACKUP_FILE="$BACKUPPATH/${WORLD}_${NOW}.tar"
#echo "Backing up minecraft world..."
#as_user "cd $_SRVDIR && cp -r $WORLD $BACKUPPATH/${WORLD}_`date "+%Y.%m.%d_%H.%M"`"
as_user "tar -h -C \"$_SRVDIR\" -cf \"$BACKUP_FILE\" \"$WORLD\""
#echo "Backing up $SERVICE"
as_user "tar -h -C \"$_SRVDIR\" -rf \"$BACKUP_FILE\" \"$SERVICE\""
#as_user "cp \"$_SRVDIR/$SERVICE\" \"$BACKUPPATH/minecraft_server_${NOW}.jar\""
mc_saveon
#echo "Compressing backup..."
as_user "gzip -f \"$BACKUP_FILE\""
#echo "Done."
}
mc_command() {
command="$1";
if pgrep -u $MCUSER -f $SERVICE > /dev/null
then
pre_log_len=`wc -l "$_SRVDIR/server.log" | awk '{print $1}'`
#echo "$SERVICE is running... executing command"
mc_docommand "$command"
sleep .1 # assumes that the command will run and print to the log file in less than .1 seconds
# print output
tail -n $[`wc -l "$_SRVDIR/server.log" | awk '{print $1}'`-$pre_log_len] "$_SRVDIR/server.log"
else
echo "$SERVICE is not running. Couldn't executed command."
fi
}
mc_docommand() {
screen -p 0 -S minecraft -X stuff "`printf \"$1\r\"`"
}
#Start-Stop here
case "$1" in
backup)
mc_backup
;;
status)
if pgrep -u $MCUSER -f $SERVICE > /dev/null
then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
;;
command)
if [ $# -gt 1 ]; then
shift
mc_command "$*"
else
echo "Must specify server command (try 'help'?)"
fi
;;
*)
echo "Usage: $0 {backup|status|command \"server command\"}"
exit 1
;;
esac
exit 0

6
minecraftd Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
. /etc/conf.d/minecraft || echo "can't source /etc/conf.d/minecraft"
cd $_SRVDIR
screen -dmS minecraft java -Xmx${MAXHEAP} -Xms${MINHEAP} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=${THREADS} -XX:+AggressiveOpts -jar ${_SRVDIR}/${SERVERJAR} nogui

7
minecraftd-diag Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
. /etc/conf.d/minecraft || echo "can't source /etc/conf.d/minecraft"
cd $_SRVDIR
echo "If the next command executes correctly, then something is wrong with screen."
su minecraft -c "PATH=/opt/java/bin/:/usr/bin/:$PATH java -Xmx${MAXHEAP} -Xms${MINHEAP} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=${THREADS} -XX:+AggressiveOpts -jar ${_SRVDIR}/${SERVERJAR} nogui"

14
minecraftd.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=Minecraft server daemon
After=network.target
[Service]
User=minecraft
Group=minecraft
ExecStart=/usr/bin/minecraftd
Type=oneshot
RemainAfterExit=yes
ExecStop=/usr/bin/screen -S minecraft -X stuff 'say Server Shutting Down in 5 Seconds\n' ; /usr/bin/sleep 5 ; /usr/bin/screen -S minecraft -X stuff 'stop\n' ; /usr/bin/expect -c "exec screen -x minecraft ; wait ; exit"
[Install]
WantedBy=multi-user.target