-
-
Notifications
You must be signed in to change notification settings - Fork 784
/
command_start.sh
198 lines (180 loc) · 6.13 KB
/
command_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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
# LinuxGSM command_start.sh function
# Author: Daniel Gibbs
# Contributor: UltimateByte
# Website: https://linuxgsm.com
# Description: Starts the server.
local modulename="START"
local commandaction="Starting"
local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
fn_start_teamspeak3(){
if [ ! -f "${servercfgfullpath}" ]; then
fn_print_warn_nl "${servercfgfullpath} is missing"
fn_script_log_warn "${servercfgfullpath} is missing"
echo " * Creating blank ${servercfg}"
fn_script_log_info "Creating blank ${servercfg}"
fn_sleep_time
echo " * ${servercfg} can remain blank by default."
fn_script_log_info "${servercfgfullpath} can remain blank by default."
fn_sleep_time
echo " * ${servercfg} is located in ${servercfgfullpath}."
fn_script_log_info "${servercfg} is located in ${servercfgfullpath}."
sleep 5
touch "${servercfgfullpath}"
fi
# Accept license.
if [ ! -f "${executabledir}/.ts3server_license_accepted" ]; then
install_eula.sh
fi
fn_start_tmux
}
fn_start_tmux(){
if [ "${parmsbypass}" ]; then
parms=""
else
fn_parms
fi
# check for tmux size variables.
if [[ "${servercfgtmuxwidth}" =~ ^[0-9]+$ ]]; then
sessionwidth="${servercfgtmuxwidth}"
else
sessionwidth="80"
fi
if [[ "${servercfgtmuxheight}" =~ ^[0-9]+$ ]]; then
sessionheight="${servercfgtmuxheight}"
else
sessionheight="23"
fi
# Log rotation.
fn_script_log_info "Rotating log files"
if [ "${engine}" == "unreal2" ]&&[ -f "${gamelog}" ]; then
mv "${gamelog}" "${gamelogdate}"
fi
if [ -f "${lgsmlog}" ]; then
mv "${lgsmlog}" "${lgsmlogdate}"
fi
if [ -f "${consolelog}" ]; then
mv "${consolelog}" "${consolelogdate}"
fi
# Create lockfile
date > "${rootdir}/${lockselfname}"
cd "${executabledir}" || exit
tmux new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${selfname}" "${executable} ${parms}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
# Create logfile.
touch "${consolelog}"
# Get tmux version.
tmuxversion=$(tmux -V | sed "s/tmux //" | sed -n '1 p')
# Tmux compiled from source will return "master", therefore ignore it.
if [ "$(tmux -V | sed "s/tmux //" | sed -n '1 p')" == "master" ]; then
fn_script_log "Tmux version: master (user compiled)"
echo -e "Tmux version: master (user compiled)" >> "${consolelog}"
if [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
tmux pipe-pane -o -t "${selfname}" "exec cat >> '${consolelog}'"
fi
elif [ "${tmuxversion}" ]; then
# Get the digit version of tmux.
tmuxversion=$(tmux -V | sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')
# tmux pipe-pane not supported in tmux versions < 1.6.
if [ "${tmuxversion}" -lt "16" ]; then
echo -e "Console logging disabled: Tmux => 1.6 required
https://linuxgsm.com/tmux-upgrade
Currently installed: $(tmux -V)" > "${consolelog}"
# Console logging disabled: Bug in tmux 1.8 breaks logging.
elif [ "${tmuxversion}" -eq "18" ]; then
echo -e "Console logging disabled: Bug in tmux 1.8 breaks logging
https://linuxgsm.com/tmux-upgrade
Currently installed: $(tmux -V)" > "${consolelog}"
# Console logging enable or not set.
elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
tmux pipe-pane -o -t "${selfname}" "exec cat >> '${consolelog}'"
fi
else
echo -e "Unable to detect tmux version" >> "${consolelog}"
fn_script_log_warn "Unable to detect tmux version"
fi
# Console logging disabled.
if [ "${consolelogging}" == "off" ]; then
echo -e "Console logging disabled by user" >> "${consolelog}"
fn_script_log_info "Console logging disabled by user"
fi
fn_sleep_time
# If the server fails to start.
check_status.sh
if [ "${status}" == "0" ]; then
fn_print_fail_nl "Unable to start ${servername}"
fn_script_log_fatal "Unable to start ${servername}"
if [ -s "${lgsmlogdir}/.${selfname}-tmux-error.tmp" ]; then
fn_print_fail_nl "Unable to start ${servername}: Tmux error:"
fn_script_log_fatal "Unable to start ${servername}: Tmux error:"
echo -e ""
echo -e "Command"
echo -e "================================="
echo -e "tmux new-session -d -s \"${selfname}\" \"${executable} ${parms}\"" | tee -a "${lgsmlog}"
echo -e ""
echo -e "Error"
echo -e "================================="
cat "${lgsmlogdir}/.${selfname}-tmux-error.tmp" | tee -a "${lgsmlog}"
# Detected error https://linuxgsm.com/support
if grep -c "Operation not permitted" "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
then
echo -e ""
echo -e "Fix"
echo -e "================================="
if ! grep "tty:" /etc/group | grep "$(whoami)"; then
echo -e "$(whoami) is not part of the tty group."
fn_script_log_info "$(whoami) is not part of the tty group."
group=$(grep tty /etc/group)
echo -e ""
echo -e " ${group}"
fn_script_log_info "${group}"
echo -e ""
echo -e "Run the following command with root privileges."
echo -e ""
echo -e " usermod -G tty $(whoami)"
echo -e ""
echo -e "https://linuxgsm.com/tmux-op-perm"
fn_script_log_info "https://linuxgsm.com/tmux-op-perm"
else
echo -e "No known fix currently. Please log an issue."
fn_script_log_info "No known fix currently. Please log an issue."
echo -e "https://linuxgsm.com/support"
fn_script_log_info "https://linuxgsm.com/support"
fi
fi
fi
core_exit.sh
else
fn_print_ok "${servername}"
fn_script_log_pass "Started ${servername}"
fi
rm "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp"
echo -en "\n"
}
check.sh
fn_print_dots "${servername}"
# Is the server already started.
# $status comes from check_status.sh, which is run by check.sh for this command
if [ "${status}" != "0" ]; then
fn_print_info_nl "${servername} is already running"
fn_script_log_error "${servername} is already running"
if [ -z "${exitbypass}" ]; then
core_exit.sh
fi
fi
if [ -z "${fixbypass}" ]; then
fix.sh
fi
info_config.sh
logs.sh
# Will check for updates is updateonstart is yes.
if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
exitbypass=1
unset updateonstart
command_update.sh
fi
if [ "${shortname}" == "ts3" ]; then
fn_start_teamspeak3
else
fn_start_tmux
fi
core_exit.sh