-
Notifications
You must be signed in to change notification settings - Fork 3
/
start.sh
146 lines (125 loc) · 4.2 KB
/
start.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# minecraft server start script
# read server files
source server.settings
source server.functions
# parse arguments
ParseArgs "$@"
ArgHelp
# safety checks
RootSafety
ScriptSafety
# debug
Debug "executing $0 script"
# change to server directory
ChangeServerDirectory
# check for existence of executable
CheckExecutable
# look if server is running
LookForScreen
# check if private network is online
CheckPrivate
# check if public network is online
CheckPublic
# user information
Print "info" "starting minecraft server. to view window type screen -r ${serverName}."
Print "info" "to minimise the window and let the server run in the background, press ctrl+a then ctrl+d"
# main start command
Start
# check if screen is available
AwaitStart
# if no screen output error
if ! screen -list | grep -q "${serverName}"; then
Log "fatal" "something went wrong - server failed to start!" "${screenLog}"
Print "fatal" "something went wrong - server failed to start!"
Print "info" "crash dump - last 10 lines of ${screenLog}"
tail -10 "${screenLog}"
exit 1
fi
# successful start sequence
Log "ok" "server is on startup..." "${screenLog}"
Print "ok" "server is on startup..."
# check if screen log contains start confirmation
count="0"
counter="0"
startupChecks="0"
while [ ${startupChecks} -lt 120 ]; do
if tail "${screenLog}" | grep -q "Time elapsed:"; then
Log "ok" "server startup successful - up and running" "${screenLog}"
Print "ok" "server startup successful - up and running"
break
fi
if tail -20 "${screenLog}" | grep -q "FAILED TO BIND TO PORT"; then
Log "error" "server port is already in use - please change to another port" "${screenLog}"
Print "error" "server port is already in use - please change to another port"
exit 1
fi
if tail -20 "${screenLog}" | grep -q "Address already in use"; then
Log "error" "server address is already in use - please change to another port" "${screenLog}"
Print "error" "server address is already in use - please change to another port"
exit 1
fi
if tail -20 "${screenLog}" | grep -q "session.lock: already locked"; then
Log "error" "session is locked - is the world in use by another instance?" "${screenLog}"
Print "error" "session is locked - is the world in use by another instance?"
exit 1
fi
if ! screen -list | grep -q "${serverName}"; then
Log "fatal" "something went wrong - server appears to have crashed!" "${screenLog}"
Print "fatal" "something went wrong - server appears to have crashed!"
Print "info" "crash dump - last 10 lines of ${screenLog}"
tail -10 "${screenLog}"
exit 1
fi
if tail "${screenLog}" | grep -q "Preparing spawn area"; then
counter=$((counter + 1))
fi
if tail "${screenLog}" | grep -q "Environment"; then
if [ ${count} -eq 0 ]; then
Print "info" "server is loading the environment..."
fi
count=$((count + 1))
fi
if tail "${screenLog}" | grep -q "Reloading ResourceManager"; then
count=$((count + 1))
fi
if tail "${screenLog}" | grep -q "Starting minecraft server"; then
count=$((count + 1))
fi
if [ ${counter} -ge 10 ]; then
Print "info" "server is preparing spawn area..."
counter="0"
fi
if [ ${count} -eq 0 ] && [ ${startupChecks} -eq 20 ]; then
Log "warn" "the server could be crashed" "${screenLog}"
Print "warn" "the server could be crashed"
exit 1
fi
startupChecks=$((startupChecks + 1))
sleep 1s
done
# check if screen log does not contain startup confirmation
if ! tail "${screenLog}" | grep -q "Time elapsed:"; then
Log "warn" "server startup unsuccessful" "${screenLog}"
Print "warn" "server startup unsuccessful"
Print "info" "crash dump - last 10 lines of ${screenLog}"
tail -10 "${screenLog}"
fi
# enable worker script
nice -n 19 ./worker.sh &
if [[ "${enableBackupsWatchdog}" == true ]]; then
Print "info" "activating backups watchdog..."
fi
if [[ "${enableWelcomeMessage}" == true ]]; then
Print "info" "activating welcome messages..."
fi
if [[ "${enableAutoStartOnCrash}" == true ]]; then
Print "info" "activating auto start on crash..."
fi
if [[ "${changeToConsole}" == true ]]; then
Print "info" "changing to server console..."
screen -r "${serverName}"
fi
Print "info" "if you would like to change to server console - type screen -r ${serverName}"
Debug "executed $0 script"
exit 0