ansible-role-minecraft/templates/stop-server.sh

40 lines
788 B
Bash

#! /bin/bash
# vim:ft=bash
instance="{{ minecraft_name }}"
screen="/usr/bin/screen -p 0 -S $instance"
stuff() {
[ -z "$1" ] && return 1
$screen -X eval "stuff \"$1\"\\015"
}
# Junk FD used for read waiting
exec 1023<> <(:)
stuff "say Server is going down for maintenance!"
if [ -n "$MC_RESTART_DELAY" ] && [ "$MC_RESTART_DELAY" -gt 0 ]; then
for (( i="$MC_RESTART_DELAY"; i>0; i-- )); do
case "$i" in
300)
stuff "say Server is going down in 5 minutes!"
;;
60)
stuff "say Server is going down in 1 minute!"
;;
30|10|5|4|3|2)
stuff "say Server is going down in "$i" seconds!"
;;
1)
stuff "say Server is going down NOW!"
;;
*)
;;
esac
read -t 1 -u 1023 || :
done
fi
stuff "save-all"
read -t 10 -u 1023 || :
stuff "stop"
exit 0