diff options
author | Conrad Kostecki <conikost@gentoo.org> | 2020-08-23 18:55:54 +0200 |
---|---|---|
committer | Conrad Kostecki <conikost@gentoo.org> | 2020-08-23 19:21:46 +0200 |
commit | 994460e2b528685f89fc41ba0df32768ee9553a0 (patch) | |
tree | 8380f9d619d7dca19e64abdbc84a8c1fd6085ced /games-server | |
parent | games-server/minecraft-server: drop old version (diff) | |
download | gentoo-994460e2b528685f89fc41ba0df32768ee9553a0.tar.gz gentoo-994460e2b528685f89fc41ba0df32768ee9553a0.tar.bz2 gentoo-994460e2b528685f89fc41ba0df32768ee9553a0.zip |
games-server/bedrock-server: add custom attach command
Since the bedrock-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.
Package-Manager: Portage-3.0.4, Repoman-3.0.1
Signed-off-by: Conrad Kostecki <conikost@gentoo.org>
Diffstat (limited to 'games-server')
3 files changed, 122 insertions, 0 deletions
diff --git a/games-server/bedrock-server/bedrock-server-1.16.20.03-r1.ebuild b/games-server/bedrock-server/bedrock-server-1.16.20.03-r1.ebuild new file mode 100644 index 000000000000..a60cb02addb6 --- /dev/null +++ b/games-server/bedrock-server/bedrock-server-1.16.20.03-r1.ebuild @@ -0,0 +1,53 @@ +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +DESCRIPTION="The official bedrock (non-java) based server for the sandbox video game" +HOMEPAGE="https://www.minecraft.net/" +SRC_URI="https://minecraft.azureedge.net/bin-linux/${P}.zip" + +LICENSE="Mojang" +SLOT="0" +KEYWORDS="-* ~amd64" + +RDEPEND=" + acct-group/bedrock + acct-user/bedrock + app-misc/dtach + dev-libs/openssl:0/1.1 + net-misc/curl[ssl] +" + +BDEPEND="app-arch/unzip" + +RESTRICT="bindist mirror" + +S="${WORKDIR}" + +DOCS=( + "bedrock_server_how_to.html" + "release-notes.txt" +) + +QA_PREBUILT=" + opt/bedrock-server/bedrock_server + opt/bedrock-server/libCrypto.so +" + +src_install() { + exeinto /opt/bedrock-server + doexe bedrock_server libCrypto.so + + insinto /opt/bedrock-server + doins {permissions,whitelist}.json server.properties + doins -r {behavior,resource}_packs definitions structures + + dodir /opt/bin + dosym ../bedrock-server/bedrock_server /opt/bin/bedrock-server + + newinitd "${FILESDIR}"/bedrock-server.initd-r2 bedrock-server + newconfd "${FILESDIR}"/bedrock-server.confd bedrock-server + + einstalldocs +} diff --git a/games-server/bedrock-server/files/bedrock-server.confd b/games-server/bedrock-server/files/bedrock-server.confd new file mode 100644 index 000000000000..d4185934e066 --- /dev/null +++ b/games-server/bedrock-server/files/bedrock-server.confd @@ -0,0 +1,7 @@ +# 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" diff --git a/games-server/bedrock-server/files/bedrock-server.initd-r2 b/games-server/bedrock-server/files/bedrock-server.initd-r2 new file mode 100644 index 000000000000..1ff60aa7816f --- /dev/null +++ b/games-server/bedrock-server/files/bedrock-server.initd-r2 @@ -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}" = "bedrock-server" ]; then + instance="main" +else + instance="${SVCNAME#*.}" +fi + +bedrock_command="/opt/bin/bedrock-server" +bedrock_path="/var/lib/bedrock-server" +bedrock_path_data="/opt/bedrock-server" +bedrock_path_instance="${bedrock_path}/${instance}" +dtach_tmpfile="$(mktemp -u)" +name="Minecraft Bedrock server (${instance})" +pidfile="/run/bedrock-server.${instance}.pid" +start_stop_daemon_args="--chdir ${bedrock_path_instance}" + +description_attach="Attaches to the session (interactive console) of the Minecraft Bedrock server" +extra_started_commands="attach" + +command="/usr/bin/dtach" +command_background="true" +command_args="-N ${dtach_tmpfile} ${bedrock_command}" +command_group="bedrock" +command_user="bedrock" + +depend() { + use net +} + +start_pre() { + checkpath -d -o "${command_user}:${command_group}" -q "${bedrock_path}" "${bedrock_path_instance}" + + local bedrock_configs=( "permissions.json" "server.properties" "whitelist.json" ) + for bedrock_config in ${bedrock_configs[@]}; do + if [ ! -f "${bedrock_path_instance}/${bedrock_config}" ]; then + cp "${bedrock_path_data}/${bedrock_config}" "${bedrock_path_instance}" + checkpath -f -o "${command_user}:${command_group}" -q "${bedrock_path_instance}/${bedrock_config}" + fi + done + + local bedrock_ressources=( "behavior_packs" "definitions" "resource_packs" "structures" ) + for bedrock_ressource in ${bedrock_ressources[@]}; do + if [ ! -L "${bedrock_path_instance}/${bedrock_ressource}" ]; then + ln -sf "${bedrock_path_data}/${bedrock_ressource}" "${bedrock_path_instance}" + fi + done +} + +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 +} |