blob: bfaad750b8c750adb4532426cc8b1ec48aea9368 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/sbin/openrc-run
# Copyright 1999-2021 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} ${MINECRAFT_OPTS}"
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
}
|