diff options
author | Conrad Kostecki <conikost@gentoo.org> | 2020-08-23 18:51:05 +0200 |
---|---|---|
committer | Conrad Kostecki <conikost@gentoo.org> | 2020-08-23 19:21:45 +0200 |
commit | 12cf26ce1ef4d7712b2aba972d805aea7f6ca545 (patch) | |
tree | b0562268a3107ddc2276c7ad4171937af9608aaa /games-server/minecraft-server/files | |
parent | x11-misc/j4-dmenu-desktop: drop old version (diff) | |
download | gentoo-12cf26ce1ef4d7712b2aba972d805aea7f6ca545.tar.gz gentoo-12cf26ce1ef4d7712b2aba972d805aea7f6ca545.tar.bz2 gentoo-12cf26ce1ef4d7712b2aba972d805aea7f6ca545.zip |
games-server/minecraft-server: add custom attach command
Since the minecraft-server is running as an interactive console process
in background, this custom command 'attach' enables the possibility to
connect with dtach to that interactive console and send commands to
the running server.
Closes: https://github.com/gentoo/gentoo/pull/15055
Package-Manager: Portage-3.0.4, Repoman-3.0.1
Signed-off-by: Conrad Kostecki <conikost@gentoo.org>
Diffstat (limited to 'games-server/minecraft-server/files')
3 files changed, 100 insertions, 0 deletions
diff --git a/games-server/minecraft-server/files/README.gentoo-r1 b/games-server/minecraft-server/files/README.gentoo-r1 new file mode 100644 index 000000000000..903ef5a7d9d7 --- /dev/null +++ b/games-server/minecraft-server/files/README.gentoo-r1 @@ -0,0 +1,26 @@ +This package provides an init script and a conf file. +You don't have to modify those files directly, +but instead you can make a symlink of that init script +and a copy of that conf file. +You would do this for every server, you want to setup. + +For example, you wan't to setup an world called 'gentoo', +you would do: + +cd /etc/init.d +ln -s minecraft-server minecraft-server.gentoo + +cd /etc/conf.d +cp minecraft-server minecraft-server.gentoo + +After that, make your settings in +/etc/conf.d/minecraft-server.gentoo. + +If you don't make a symlink, but use the default scripts, +your world will be called 'main'. + +To interact with the console of the corresponding world, +you can use the extra command attach: + +rc-service minecraft-server attach +rc-service minecraft-server.gentoo attach diff --git a/games-server/minecraft-server/files/minecraft-server.confd-r1 b/games-server/minecraft-server/files/minecraft-server.confd-r1 new file mode 100644 index 000000000000..8b380349e9ac --- /dev/null +++ b/games-server/minecraft-server/files/minecraft-server.confd-r1 @@ -0,0 +1,12 @@ +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# Dtach options, which will used, when the `attach` extra command is called. +# By default, CTRL+D is used, and no redraw is done, +# when you want to detach from the attached console. +DTACH_OPTS="-e '^D' -r none" + +# Java options for your started server +# You should at least define some memory settings (-Xms, -Xmx), +# for maximum memory, as the java default is far to low for Minecraft +MINECRAFT_OPTS="-Xms1024m -Xmx1024m" diff --git a/games-server/minecraft-server/files/minecraft-server.initd-r4 b/games-server/minecraft-server/files/minecraft-server.initd-r4 new file mode 100644 index 000000000000..e81337a7d19f --- /dev/null +++ b/games-server/minecraft-server/files/minecraft-server.initd-r4 @@ -0,0 +1,62 @@ +#!/sbin/openrc-run +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +if [ "${SVCNAME}" = "minecraft-server" ]; then + instance="main" +else + instance="${SVCNAME#minecraft-server.}" +fi + +dtach_tmpfile="$(mktemp -u)" +minecraft_command="/usr/bin/minecraft-server" +minecraft_logs="/var/log/minecraft-server" +minecraft_logs_instance="${minecraft_logs}/${instance}" +minecraft_path="/var/lib/minecraft-server" +minecraft_path_instance="${minecraft_path}/${instance}" +name="Minecraft Server (World: ${instance})" +pidfile="/run/minecraft-server.${instance}.pid" +start_stop_daemon_args="--chdir ${minecraft_path_instance} --env JAVA_OPTS='${MINECRAFT_OPTS}'" + +description_attach="Attaches to the session (interactive console) of the Minecraft server" +extra_started_commands="attach" + +command="/usr/bin/dtach" +command_background="true" +command_args="-N ${dtach_tmpfile} ${minecraft_command}" +command_group="minecraft" +command_user="minecraft" + +depend() { + use net +} + +start_pre() { + checkpath -d -o "${command_user}:${command_group}" -q "${minecraft_path}" "${minecraft_path_instance}" + + checkpath -f -o "${command_user}:${command_group}" -q "${minecraft_path_instance}"/eula.txt + echo "eula=true" > "${minecraft_path_instance}"/eula.txt + + checkpath -d -o "${command_user}:${command_group}" -q "${minecraft_logs}" "${minecraft_logs_instance}" + + if [ ! -L "${minecraft_path_instance}"/logs ]; then + cd "${minecraft_path_instance}" && ln -s ../../../log/minecraft-server/"${instance}" logs + fi + + if [ -z "${MINECRAFT_OPTS}" ]; then + eerror "You must define 'MINECRAFT_OPTS' in '/etc/conf.d/${SVCNAME}'!" + return 1 + fi +} + +attach() { + pidnumber="$(cat ${pidfile})" + dtach_tmpfile="$(cat /proc/${pidnumber}/cmdline | tr '\0' ' ' | awk '{print $3}')" + + if [ -S "${dtach_tmpfile}" ]; then + eval "${command}" -a "${dtach_tmpfile}" "${DTACH_OPTS}" + else + eerror "The determined socket file for dtach could not be found!" + eerror "Did the process crash?" + fi +} |