2021-02-04 17:44:55 +01:00
|
|
|
|
#!/bin/bash -x
|
|
|
|
|
|
|
|
|
|
# 1: Temps en minutes
|
|
|
|
|
# 2: Type d’extinction
|
|
|
|
|
|
2022-04-15 13:05:19 +02:00
|
|
|
|
touch /dev/shm/mccount
|
|
|
|
|
|
2021-02-04 17:44:55 +01:00
|
|
|
|
while true
|
|
|
|
|
do
|
|
|
|
|
|
|
|
|
|
mcpid=$(systemctl show minecraft-server.service --property MainPID --value)
|
|
|
|
|
mcstatus=$(ps -q "${mcpid}" -o state --no-headers 2>/dev/null)
|
|
|
|
|
|
|
|
|
|
if [[ "$mcstatus" == "T" ]]
|
|
|
|
|
then
|
|
|
|
|
echo . >> /dev/shm/mccount
|
|
|
|
|
else
|
2022-02-26 22:34:40 +01:00
|
|
|
|
players_tmp=($(mcstatus localhost query | grep players))
|
|
|
|
|
players="${players_tmp[1]%%/*}"
|
|
|
|
|
if [[ "$players" -gt 0 ]]
|
|
|
|
|
then
|
|
|
|
|
> /dev/shm/mccount
|
|
|
|
|
fi
|
2021-02-04 17:44:55 +01:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
time=$(wc -l /dev/shm/mccount | cut -d" " -f1)
|
|
|
|
|
|
|
|
|
|
if [[ "$time" -ge "${1:-5}" ]]
|
|
|
|
|
then
|
|
|
|
|
> /dev/shm/mccount
|
|
|
|
|
systemctl "${2:-suspend}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sleep 60
|
|
|
|
|
|
|
|
|
|
done
|