mineserver is fully functional per initial testing

This commit is contained in:
Henry Corse
2022-12-12 17:18:05 -05:00
parent 2e0f62a5aa
commit 17bb4b9997

View File

@ -0,0 +1,68 @@
#!/bin/bash
PID=/opt/minecraft/mc.pid
status() {
screen -S minecraft -X stuff "list
"
echo
echo "== Status =="
ps -p $(cat $PID) -o %cpu,%mem,cmd
echo
LAST_STATUS=$(cat logs/latest.log | grep -n "players online:" | tail -n1 | cut -d ":" -f 1)
tail -n +$LAST_STATUS logs/latest.log
echo
}
serve() {
java -Xms1G -Xmx5G -jar server.jar nogui
}
start() {
if test -f "$PID"; then
echo "Server already running with pid: $(cat $PID)"
status
exit 0
fi
screen -S minecraft -dm serve
pgrep -P "$(screen -list | sed -E -n 's/\s*([0-9]+).minecraft.*/\1/p')" > $PID
}
stop() {
if test -f "$PID"; then
screen -S minecraft -X stuff "stop
"
echo -n "Waiting for shutdown..."
while screen -list | grep -q "minecraft"; do
sleep 3
echo -n "."
done
echo " Shutdown Complete!"
rm $PID
exit 0
fi
echo "No server is running..."
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
*)
echo
echo "Usage: $0 { start | stop | restart | status }"
echo
exit 1
;;
esac