summaryrefslogtreecommitdiff
blob: ec659d145f85c3468dc23d162f9490d90aeb2218 (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
#!/sbin/openrc-run
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

if [ "${SVCNAME}" = "minecraft-server" ]; then
	instance="main"
else
	instance="${SVCNAME#minecraft-server.}"
fi

minecraft_command="/usr/bin/minecraft-server"
minecraft_logs="/var/log/minecraft-server"
minecraft_path="/var/lib/minecraft-server/${instance}"
name="Minecraft Server (World: ${instance})"
pidfile="/run/minecraft-server.${instance}.pid"
screen_name="minecraft-server.${instance}"
start_stop_daemon_args="--chdir ${minecraft_path} --env JAVA_OPTS=\"${MINECRAFT_OPTS}\""

command="screen"
command_args="-DmUS ${screen_name} ${minecraft_command}"
command_background="true"
command_group="minecraft"
command_user="minecraft"

depend() {
	use net
}

start_pre() {
	checkpath -d -o "${command_user}:${command_group}" -q "${minecraft_path}"

	checkpath -f -o "${command_user}:${command_group}" -q "${minecraft_path}"/eula.txt
	echo "eula=true" > "${minecraft_path}"/eula.txt

	checkpath -d -o "${command_user}:${command_group}" -q "${minecraft_logs}"/"${instance}"

	if [ ! -L "${minecraft_path}"/logs ]; then
		cd "${minecraft_path}" && ln -s ../../../log/minecraft-server/"${instance}" logs
	fi

	if [ -z "${MINECRAFT_OPTS}" ]; then
		eerror "You must define MINECRAFT_OPTS in /etc/conf.d/minecraft.${SVCNAME}!"
		return 1
	fi

	return 0
}