-
Notifications
You must be signed in to change notification settings - Fork 7
/
idoit-support
executable file
·286 lines (230 loc) · 7.83 KB
/
idoit-support
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
##
## i-doit support
##
##
## Copyright (C) 2017-19 synetics GmbH, <https://i-doit.com/>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
set -euo pipefail
IFS=$'\n\t'
##
## Configuration
##
USER="root"
CONFIGURATION_FILE="/etc/i-doit/i-doit.sh"
DATE="$(date +%Y-%m-%d_%H-%M-%S)"
TMP_DIR="/tmp/idoit-support_${DATE}"
TARBALL="idoit-support_${DATE}.tar.gz"
##--------------------------------------------------------------------------------------------------
function execute {
log "Collect data about i-doit, installed add-ons and your system"
addTempDir
collectSystemEnvironment
collectVersions
collectDaemonStatus
collectLogs
collectPHPSettings
collectApacheSettings
collectMariaDBSettings
collectIdoitData
includeInstance
includeDatabases
collectApplianceData
packData
cleanUp
log ""
log "Tarball created at ${INSTANCE_PATH}/$TARBALL"
log "Download it by URL http://$(ip route get 1 | awk '{print $NF;exit}')/$TARBALL"
}
function addTempDir {
mkdir -p "$TMP_DIR" || \
abort "Unable to create temporary directory"
echo "Date: $DATE" >> "$TMP_DIR"/meta
}
function collectSystemEnvironment {
log "Collect hardware information"
test -x "$(command -v nproc)" && \
nproc > "$TMP_DIR"/nproc
test -x "$(command -v vmstat)" && \
vmstat --stats --unit M > "$TMP_DIR"/vmstat
log "Collect OS information"
test -x "$(command -v uname)" && \
uname -a > "$TMP_DIR"/uname
test -x "$(command -v procinfo)" && \
procinfo > "$TMP_DIR"/procinfo
test -x "$(command -v netstat)" && \
netstat -tulpen > "$TMP_DIR"/netstat
log "Collect information about systemd units"
test -x "$(command -v systemd-analyze)" && \
systemd-analyze blame > "$TMP_DIR"/systemd-analyze-blame
log "Print systemd unit dependency graph"
test -x "$(command -v systemd-analyze)" && \
systemd-analyze dot 2> /dev/null | dot -Tsvg > \
"$TMP_DIR"/systemd-analyze-dot.svg
log "Collect installed Debian packages"
test -x "$(command -v dpkg)" && \
dpkg -l > "$TMP_DIR"/dpkg
}
function collectVersions {
log "Collect version information"
test -x "$(command -v lsb_release)" && \
lsb_release -a > "$TMP_DIR"/debian_version 2> /dev/null
test -x "$(command -v php)" && \
php --version > "$TMP_DIR"/php_version
test -x "$(command -v mysql)" && \
mysql --version > "$TMP_DIR"/mariadb_version
test -x "$(command -v openssl)" && \
openssl version > "$TMP_DIR"/openssl_version
test -x "$(command -v apachectl)" && \
apachectl -v > "$TMP_DIR"/apache_version
test -x "$(command -v memcached)" && \
memcached -V > "$TMP_DIR"/memcached_version
}
function collectDaemonStatus {
log "Check services"
test -x "$(command -v systemctl)" && \
systemctl status mysql.service > "$TMP_DIR"/mariadb_service
test -x "$(command -v systemctl)" && \
systemctl status apache2.service > "$TMP_DIR"/apache_service
test -x "$(command -v systemctl)" && \
systemctl status memcached.service > "$TMP_DIR"/memcached_service
}
function collectLogs {
log "Collect log files"
copyFile /var/log/mysql/error.log mariadb_errors
copyFile /var/log/apache2/error.log apache_errors
copyDir "$INSTANCE_PATH"/log/
}
function collectPHPSettings {
log "Collect PHP settings"
test -x "$(command -v php)" && \
php --info > "$TMP_DIR"/php_cli_info
test -x "$(command -v php)" && \
php -m > "$TMP_DIR"/php_modules
echo "<?php phpinfo(); ?>" > "$INSTANCE_PATH"/phpinfo.php
test -x "$(command -v wget)" && \
wget --quiet -O "$TMP_DIR"/php_web_info http://localhost/phpinfo.php
rm "$INSTANCE_PATH"/phpinfo.php
askYesNo "Do you like to include /etc/php/?" || return
copyDir /etc/php/
}
function collectApacheSettings {
log "Collect Apache Web server settings"
test -x "$(command -v apachectl)" && \
apachectl configtest 2> "$TMP_DIR"/apache_configtest
test -x "$(command -v apachectl)" && \
apachectl -M > "$TMP_DIR"/apache_modules 2> /dev/null
askYesNo "Do you like to include /etc/apache2/?" || return
copyDir /etc/apache2/
}
function collectMariaDBSettings {
log "Collect MariaDB settings"
test -x mysqladmin && mysqladmin variables \
-h"$MARIADB_HOSTNAME" -u"$MARIADB_USERNAME" -p"$MARIADB_PASSWORD"
askYesNo "Do you like to include /etc/mysql/?" || return
copyDir /etc/mysql/
}
function collectIdoitData {
log "Collect information about i-doit"
copyFile "$INSTANCE_PATH"/VERSION idoit_version
copyFile "$INSTANCE_PATH"/REVISION idoit_revision
test -d "$INSTANCE_PATH"/src/classes/modules/ && \
cd "$INSTANCE_PATH"/src/classes/modules/
test -d "$INSTANCE_PATH"/src/classes/modules/ && \
for i in */; do echo "${i%%/}" >> "$TMP_DIR"/idoit_modules; done
}
function includeInstance {
askYesNo "Do you like to include your i-doit instance?" || return
copyDir "${INSTANCE_PATH:?}"/
}
function includeDatabases {
askYesNo "Do you like to include your i-doit databases?" || return
dumpDatabase "$SYSTEM_DATABASE"
dumpDatabase "$TENANT_DATABASE"
}
function dumpDatabase {
local dbName="$1"
log "Dump database $dbName"
/usr/bin/mysqldump \
-h"$MARIADB_HOSTNAME" -u"$MARIADB_USERNAME" -p"$MARIADB_PASSWORD" "$dbName" | \
gzip -9 > "${TMP_DIR}/${dbName}.sql.gz"
}
function collectApplianceData {
log "Collect information about the i-doit virtual appliance"
copyFile /etc/appliance_version appliance_version
}
function copyFile {
local src="$1"
local dest="$2"
test -f "$src" || log "File $src does not exist"
test -f "$src" || return
log "Copy file $src"
cp "$src" "$TMP_DIR/$dest"
}
function copyDir {
local dir="$1"
test -d "$dir" || log "Directory $dir does not exist"
test -d "$dir" || return
log "Copy directory $dir"
cp -r "${dir:?}"/ "$TMP_DIR"
}
function packData {
log "Pack data"
cd "$TMP_DIR"
tar czf "${INSTANCE_PATH}/$TARBALL" ./*
}
function cleanUp {
log "Clean up"
rm -r "${TMP_DIR:?}"/
}
function askYesNo {
echo -n -e "$1 [Y]es [n]o: "
read -r answer
case "$answer" in
""|"Y"|"Yes"|"y"|"yes")
return 0
;;
"No"|"no"|"n"|"N")
return 1
;;
*)
log "Sorry, what do you mean?"
askYesNo "$1"
esac
}
function setup {
test "$(whoami)" = "$USER" || abort "Only user '${USER}' may execute this script"
test -f "$CONFIGURATION_FILE" || abort "Missing configuration file '${CONFIGURATION_FILE}'"
# shellcheck source=/dev/null
source "$CONFIGURATION_FILE" || abort "Unable to include configuration file"
test -d "$INSTANCE_PATH" || abort "No i-doit instance found under '${INSTANCE_PATH}'"
}
function log {
echo -e "$1"
}
function finish {
log "Done. Have fun :-)"
exit 0
}
function abort {
echo -e "$1" 1>&2
echo "Operation failed. Please check what is wrong and try again." 1>&2
exit 1
}
##--------------------------------------------------------------------------------------------------
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
setup && execute && finish
fi