aboutsummaryrefslogtreecommitdiff
path: root/minecraft/minecraft
blob: 33e31dc32ce497c8040c73a0df3832712e209365 (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
#!/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() {
	echo Starting Minecraft server...
	(cd $MCPATH && screen -h 1024 -dmS $SESSION $CMD)
}

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.
}