forked from TheRemote/RaspberryPiMinecraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart.sh
executable file
·45 lines (40 loc) · 1.49 KB
/
restart.sh
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
38
39
40
41
42
43
44
45
#!/bin/sh
# James Chambers - July 4th 2020
# More information at https://jamesachambers.com/raspberry-pi-minecraft-server-script-with-startup-service/
# Check if server is running
if ! screen -list | grep -q "minecraft"; then
echo "Server is not currently running!"
exit 1
fi
echo "Sending restart notifications to server..."
# Minecraft Server restart and pi reboot.
screen -Rd minecraft -X stuff "say Server is restarting in 30 seconds! $(printf '\r')"
sleep 23s
screen -Rd minecraft -X stuff "say Server is restarting in 7 seconds! $(printf '\r')"
sleep 1s
screen -Rd minecraft -X stuff "say Server is restarting in 6 seconds! $(printf '\r')"
sleep 1s
screen -Rd minecraft -X stuff "say Server is restarting in 5 seconds! $(printf '\r')"
sleep 1s
screen -Rd minecraft -X stuff "say Server is restarting in 4 seconds! $(printf '\r')"
sleep 1s
screen -Rd minecraft -X stuff "say Server is restarting in 3 seconds! $(printf '\r')"
sleep 1s
screen -Rd minecraft -X stuff "say Server is restarting in 2 seconds! $(printf '\r')"
sleep 1s
screen -Rd minecraft -X stuff "say Server is restarting in 1 second! $(printf '\r')"
sleep 1s
screen -Rd minecraft -X stuff "say Closing server...$(printf '\r')"
screen -Rd minecraft -X stuff "stop $(printf '\r')"
# Wait up to 30 seconds for server to close
echo "Closing server..."
StopChecks=0
while [ $StopChecks -lt 30 ]; do
if ! screen -list | grep -q "minecraft"; then
break
fi
sleep 1;
StopChecks=$((StopChecks+1))
done
echo "Restarting now."
sudo reboot