dev-python/agate: Bump to 1.13.0
[gentoo/gentoo.git] / games-server / bedrock-server / files / bedrock-server.initd-r5
blob40946197b7c5236d83eaea3e259d706a174d340a
1 #!/sbin/openrc-run
2 # Copyright 1999-2020 Gentoo Authors
3 # Distributed under the terms of the GNU General Public License v2
5 if [ "${SVCNAME}" = "bedrock-server" ]; then
6         instance="main"
7 else
8         instance="${SVCNAME#*.}"
9 fi
11 bedrock_command="/opt/bin/bedrock-server"
12 bedrock_path="/var/lib/bedrock-server"
13 bedrock_path_data="/opt/bedrock-server"
14 bedrock_path_instance="${bedrock_path}/${instance}"
15 directory="${bedrock_path_instance}/"
16 dtach_tmpfile="$(mktemp -u)"
17 name="Minecraft Bedrock server (${instance})"
18 pidfile="/run/bedrock-server.${instance}.pid"
20 description_attach="Attaches to the session (interactive console) of the Minecraft Bedrock server"
21 extra_started_commands="attach"
23 command="/usr/bin/dtach"
24 command_background="true"
25 command_args="-N ${dtach_tmpfile} ${bedrock_command}"
26 command_group="bedrock"
27 command_user="bedrock"
29 depend() {
30         use net
33 start_pre() {
34         checkpath -d -o "${command_user}:${command_group}" -q "${bedrock_path}" "${bedrock_path_instance}"
36         set -- "allowlist.json" "permissions.json" "server.properties"
37         for bedrock_config in $@; do
38                 if [ ! -f "${bedrock_path_instance}/${bedrock_config}" ]; then
39                         cp "${bedrock_path_data}/${bedrock_config}" "${bedrock_path_instance}"
40                         checkpath -f -o "${command_user}:${command_group}" -q "${bedrock_path_instance}/${bedrock_config}"
41                 fi
42         done
44         set -- "behavior_packs" "definitions" "resource_packs" "structures"
45         for bedrock_ressource in $@; do
46                 if [ ! -L "${bedrock_path_instance}/${bedrock_ressource}" ]; then
47                         ln -sf "${bedrock_path_data}/${bedrock_ressource}" "${bedrock_path_instance}"
48                 fi
49         done
52 attach() {
53         pidnumber="$(cat ${pidfile})"
54         dtach_tmpfile="$(cat /proc/${pidnumber}/cmdline | tr '\0' ' ' | awk '{print $3}')"
56         if [ -S "${dtach_tmpfile}" ]; then
57                 eval "${command}" -a "${dtach_tmpfile}" "${DTACH_OPTS}"
58         else
59                 eerror "The determined socket file for dtach could not be found!"
60                 eerror "Did the process crash?"
61         fi