-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathCONTAINER_SETUP.sh
184 lines (144 loc) · 6.49 KB
/
CONTAINER_SETUP.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
#!/bin/bash
#
# Copyright (C) <2015-present> <it-novum GmbH>
#
# This file is dual licensed
#
# 1.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 2.
# If you purchased an openITCOCKPIT Enterprise Edition you can use this file
# under the terms of the openITCOCKPIT Enterprise Edition license agreement.
# License agreement and license key will be shipped with the order
# confirmation.
#
# This SETUP Script should ONLY BE USED WHEN running inside of an container like for example Docker
if ! [ $(id -u) = 0 ]; then
echo "You need to run this script as root user or via sudo!"
exit 1
fi
# Enable debug mode so that CakePHP will create missing folders
# https://github.com/it-novum/openITCOCKPIT/issues/1446
# https://github.com/cakephp/migrations/issues/565
export OITC_DEBUG=1
APPDIR="/opt/openitc/frontend"
INIFILE=/opt/openitc/etc/mysql/mysql.cnf
DUMPINIFILE=/opt/openitc/etc/mysql/dump.cnf
BASHCONF=/opt/openitc/etc/mysql/bash.conf
OSVERSION=$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)
OS_BASE="debian"
echo "Copy required system files"
rsync -K -a ${APPDIR}/system/etc/. /etc/ # we use rsync because the destination can be a symlink on RHEL
chown root:root /etc
cp -r ${APPDIR}/system/usr/. /usr/
cp ${APPDIR}/system/nginx/ssl_options_$OSVERSION /etc/nginx/openitc/ssl_options.conf
cp ${APPDIR}/system/nginx/ssl_cert.conf /etc/nginx/openitc/ssl_cert.conf
echo "# This file will NOT be overwritten during an update" >> /etc/nginx/openitc/custom.conf
chmod +x /usr/bin/oitc
echo "Create required system folders"
mkdir -p /opt/openitc/etc/{mysql,grafana,carbon,frontend,nagios,nsta}
mkdir -p /opt/openitc/nagios/etc/config
mkdir -p /opt/openitc/etc/nagios/nagios.cfg.d
chown www-data:www-data /opt/openitc/logs/frontend
chown nagios:www-data /opt/openitc/nagios/etc/config
chown nagios:www-data /opt/openitc/etc/nagios/nagios.cfg.d
chmod 775 /opt/openitc/logs/frontend
chown www-data:www-data /opt/openitc/frontend/tmp
mkdir -p /opt/openitc/frontend/webroot/img/charts
chown www-data:www-data /opt/openitc/frontend/webroot/img/charts
if [[ -d /opt/openitc/frontend/plugins/MapModule/webroot/img/ ]]; then
chown -R www-data:www-data /opt/openitc/frontend/plugins/MapModule/webroot/img/
fi
# It is important that the statusengine-worker container is already up and running and has created all
# the Statusengine related MySQL tables, because the setup will add partitions to the tables
echo "Checking if Statusengine Tables where already created..."
COUNTER=0
MYSQL_ONLINE=0
set +e
while [ "$COUNTER" -lt 30 ]; do
#Is Grafana Server Online?
OUTPUT=$(mysql "--defaults-extra-file=$INIFILE" -e "SELECT 1 FROM statusengine_nodes;" -B -s 2>/dev/null)
if [ "$OUTPUT" ]; then
echo "Tables are present."
MYSQL_ONLINE=1
break
fi
echo "Waiting for Statusengine to create tables..."
COUNTER=$((COUNTER + 1))
sleep 1
done
if [[ "$MYSQL_ONLINE" == 0 ]]; then
echo "ERROR!"
echo "Statusengine tables are missing! ABORT!"
exit 1
fi
set -e
#mkdir -p /opt/openitc/var/prometheus
#chown nagios:nagios /opt/openitc/var/prometheus
#mkdir -p /opt/openitc/var/prometheus/victoria-metrics
echo "---------------------------------------------------------------"
echo "Import openITCOCKPIT Core database schema"
oitc migrations migrate
echo "---------------------------------------------------------------"
echo "Load default database"
oitc migrations seed
echo "Running openITCOCKPIT Module database migration/s"
for PLUGIN in $(ls -1 "${APPDIR}/plugins"); do
if [[ "$PLUGIN" == *Module ]]; then
if [[ -d "${APPDIR}/plugins/${PLUGIN}/config/Migrations" ]]; then
echo "Running openITCOCKPIT ${PLUGIN} database migration"
oitc migrations migrate -p "${PLUGIN}"
fi
if [[ -d "${APPDIR}/plugins/${PLUGIN}/config/Seeds" ]]; then
num_files=$(find "${APPDIR}/plugins/${PLUGIN}/config/Seeds" -mindepth 1 -iname "*.php" -type f | wc -l)
if [[ "$num_files" -gt 0 ]]; then
echo "Importing default records for ${PLUGIN} into database"
oitc migrations seed -p "${PLUGIN}"
fi
fi
fi
done
if [ -d "${APPDIR}/plugins/CheckmkModule/src" ]; then
oitc checkmkNagiosExport --init
fi
echo "---------------------------------------------------------------"
echo "Create new WebSocket Key"
WEBSOCKET_KEY=$(php -r "echo bin2hex(openssl_random_pseudo_bytes(80, \$cstrong));")
mysql "--defaults-extra-file=${INIFILE}" -e "UPDATE systemsettings SET \`systemsettings\`.\`value\`='${WEBSOCKET_KEY}' WHERE \`key\`='SUDO_SERVER.API_KEY';"
oitc config_generator_shell --generate-container
echo "---------------------------------------------------------------"
echo "Configure Grafana"
echo $OITC_GRAFANA_ADMIN_PASSWORD > /opt/openitc/etc/grafana/admin_password
if [[ -d /opt/openitc/frontend/plugins/GrafanaModule ]]; then
oitc GrafanaModule.service_account --grafana-hostname "$OITC_GRAFANA_HOSTNAME" --grafana-url "$OITC_GRAFANA_URL" --graphite-web-host "$OITC_GRAPHITE_WEB_ADDRESS" --graphite-web-port "$OITC_GRAPHITE_WEB_PORT" --victoria-metrics-host "$VICTORIA_METRICS_HOST" --victoria-metrics-port "$VICTORIA_METRICS_PORT"
fi
echo "---------------------------------------------------------------"
echo "Scan and import ACL objects. This will take a while..."
oitc Acl.acl_extras aco_sync
oitc compress
oitc setup --fast
oitc nagios_export
if [[ -d "/opt/openitc/nagios/rollout" ]]; then
if [[ ! -f "/opt/openitc/nagios/rollout/resource.cfg" ]]; then
ln -s /opt/openitc/nagios/etc/resource.cfg /opt/openitc/nagios/rollout/resource.cfg
fi
fi
echo "Enabling webserver configuration"
if [[ ! -f "/etc/nginx/sites-enabled/openitc" ]]; then
ln -s /etc/nginx/sites-available/openitc /etc/nginx/sites-enabled/openitc
fi
rm -f /etc/nginx/sites-enabled/default
#Set default permissions, check for always allowed permissions and dependencies
oitc roles --enable-defaults --admin
date > /opt/openitc/var/.installation_done