forked from simylein/minecraft-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.sh
91 lines (79 loc) · 2.84 KB
/
worker.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# minecraft server worker script
# read server files
source server.settings
source server.functions
# parse arguments
ParseArgs "$@"
ArgHelp
# safety checks
RootSafety
ScriptSafety
# debug
Debug "executing $0"
# change to server directory
ChangeServerDirectory
# check if server is running
CheckScreen
# run various functions every second until server exits
counter=0
while true; do
if ! [[ -d ${serverDirectory} ]]; then
exit 0
fi
if ! screen -list | grep -q "\.${serverName}"; then
Debug "executed $0 script"
exit 0
fi
lineBuffer=$(tail -1 "${screenLog}")
if [[ ! ${lineBuffer} == ${lastLineBuffer} ]]; then
if [[ ${enableWelcomeMessage} == true ]]; then
size=${#welcome[@]}
index=$((${RANDOM} % ${size}))
timeStamp=$(date +"%H:%M:%S")
if tail -1 screen.log | grep -q "joined the game"; then
welcomeMessage=${welcome[$index]}
player=$(tail -1 screen.log | grep -oP '.*?(?=joined the game)' | cut -d ' ' -f 4- | sed 's/.$//')
TellrawWelcome "${welcomeMessage}" "${player}" "player ${player} joined at ${timeStamp}"
fi
fi
Help
ListTasks
ListBackups
if [[ ${enablePerformBackup} == true ]]; then
PerformBackup
fi
if [[ ${enablePerformRestart} == true ]]; then
PerformRestart
fi
if [[ ${enablePerformUpdate} == true ]]; then
PerformUpdate
fi
if [[ ${enablePerformReset} == true ]]; then
PerformReset
fi
fi
if [[ ${enableBackupsWatchdog} == true ]]; then
if [[ ${counter} -eq 120 ]]; then
source server.settings
timeStamp=$(date +"%H:%M:%S")
lastTimeStamp=$(date -d -"2 minute" +"%H:%M:%S")
if [[ ${worldSizeBytes} -lt $((${lastWorldSizeBytes} - 65536)) ]]; then
Log "warn" "your world-size is getting smaller - this may result in a corrupted world" "${backupLog}"
Log "info" "world-size at ${lastTimeStamp} was ${lastWorldSizeBytes} bytes, world-size at ${timeStamp} is ${worldSizeBytes} bytes" "${backupLog}"
TellrawScript "warn: your world-size is getting smaller - this may result in a corrupted world" "world-size at ${lastTimeStamp} was ${lastWorldSizeBytes} bytes, world-size at ${timeStamp} is ${worldSizeBytes} bytes"
fi
if [[ ${backupSizeBytes} -lt $((${lastBackupSizeBytes} - 65536)) ]]; then
Log "warn" "your backup-size is getting smaller - this may result in corrupted backups" "${backupLog}"
Log "info" "backup-size at ${lastTimeStamp} was ${lastBackupSizeBytes} bytes, backup-size at ${timeStamp} is ${backupSizeBytes} bytes" "${backupLog}"
TellrawScript "warn: your backup-size is getting smaller - this may result in corrupted backups" "backup-size at ${lastTimeStamp} was ${lastBackupSizeBytes} bytes, backup-size at ${timeStamp} is ${backupSizeBytes} bytes"
fi
lastWorldSizeBytes=${worldSizeBytes}
lastBackupSizeBytes=${backupSizeBytes}
counter=0
fi
fi
lastLineBuffer="${lineBuffer}"
counter=$((counter + 1))
sleep 1s
done