aboutsummaryrefslogtreecommitdiff
path: root/minecraft
blob: 64c786b20c9e2af0f52625552cfd67f9b83d291f (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
#!/sbin/openrc-run

name=minecraft
description='Minecraft server'

MCPATH=/srv/minecraft
JAR=$MCPATH/paper.server.jar
CMD="java -Xmx1G -Xms1G -jar $JAR nogui"
SESSION=minecraft

depend() {
	use net
}

start() {
	if which shiftdown > /dev/null && shiftdown
	then
		echo Not starting Minecraft server because Shift is held.
		return 1
	else
		echo Starting Minecraft server...
		(cd $MCPATH && screen -h 1024 -dmS $SESSION $CMD)
	fi
}

stop() {
	if pgrep -f "$JAR" > /dev/null
	then
		screen -p 0 -S $SESSION -X eval 'stuff "stop"\015'
		echo Waiting for Minecraft server to shut down...
		while pgrep -f "$JAR" > /dev/null
		do
			sleep 0.2
		done
	fi
	echo Minecraft server is shut down.
}