diff --git a/src/icinga2/install-service.sh b/src/icinga2/install-service.sh index 346d291..41afb4e 100644 --- a/src/icinga2/install-service.sh +++ b/src/icinga2/install-service.sh @@ -70,20 +70,29 @@ _install() { grafana \ icingaweb2 icingacli - echo "[INFO] Icinga Director Modul wird installiert." - if [ ! -d /usr/share/icingaweb2/modules/director ]; then - ICINGA_DIRECTOR_VERSION=$(curl -s "https://api.github.com/repos/Icinga/icingaweb2-module-director/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+') - wget -O /tmp/director.tar.gz "https://github.com/Icinga/icingaweb2-module-director/archive/refs/tags/v${ICINGA_DIRECTOR_VERSION}.tar.gz" - tar -C /usr/share/icingaweb2/modules -xzf /tmp/director.tar.gz - mv /usr/share/icingaweb2/modules/icingaweb2-module-director-* /usr/share/icingaweb2/modules/director - rm /tmp/director.tar.gz - echo "[INFO] Icinga Director v${ICINGA_DIRECTOR_VERSION} installiert." - else - echo "[INFO] Icinga Director ist bereits installiert." - fi + echo "[INFO] Icinga Web 2 Module (Abhängigkeiten für Director) werden installiert." + # Funktion zum Herunterladen und Entpacken von Modulen + install_icinga_module() { + local module_name="$1" + local repo_name="$2" + if [ ! -d "/usr/share/icingaweb2/modules/${module_name}" ]; then + echo "[INFO] Installiere Modul: ${module_name}" + local version=$(curl -s "https://api.github.com/repos/Icinga/${repo_name}/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+') + wget -O "/tmp/${module_name}.tar.gz" "https://github.com/Icinga/${repo_name}/archive/refs/tags/v${version}.tar.gz" + tar -C /usr/share/icingaweb2/modules -xzf "/tmp/${module_name}.tar.gz" + mv "/usr/share/icingaweb2/modules/${repo_name}-"* "/usr/share/icingaweb2/modules/${module_name}" + rm "/tmp/${module_name}.tar.gz" + else + echo "[INFO] Modul ${module_name} ist bereits installiert." + fi + } + + install_icinga_module "ipl" "icingaweb2-module-ipl" + install_icinga_module "reactbundle" "icingaweb2-module-reactbundle" + install_icinga_module "director" "icingaweb2-module-director" echo "[INFO] Systemd Services werden aktiviert." - systemctl enable --now icinga2 postgresql nginx php${PHP_VERSION}-fpm influxdb2 grafana-server + systemctl enable --now icinga2 postgresql nginx php${PHP_VERSION}-fpm influxdb grafana-server } _configure() { @@ -144,10 +153,8 @@ _configure() { sudo -u postgres createdb -O icinga_ido icinga_ido &>/dev/null || echo "[INFO] Postgres-DB 'icinga_ido' existiert bereits." sudo -u postgres psql -d icinga_ido -c "GRANT ALL ON SCHEMA public TO icinga_ido;" - # 3. Icinga2 konfigurieren - echo "[INFO] Icinga2 (ido-pgsql, api, influxdb2-writer) wird konfiguriert." - icinga2 feature enable ido-pgsql api influxdb2-writer >/dev/null - + # 3. Icinga2 Konfigurationsdateien schreiben + echo "[INFO] Icinga2 Konfigurationsdateien werden geschrieben." bash -c "cat > /etc/icinga2/features-available/ido-pgsql.conf" < /etc/icingaweb2/resources.ini" < /etc/icinga2/features-available/api.conf" < /etc/nginx/sites-available/icinga-stack" </dev/null PGPASSWORD="${ICINGAWEB_DB_PASS}" psql -h localhost -U icingaweb2 -d icingaweb2 -f /usr/share/icingaweb2/etc/schema/pgsql.schema.sql &>/dev/null - # 2. Icinga Web 2 Setup + # 2. Icinga2 Features aktivieren (NACHDEM die DB bereit ist) + echo "[INFO] Icinga2 Features werden aktiviert." + icinga2 feature enable ido-pgsql api influxdb2-writer >/dev/null + + # 3. Icinga Web 2 Module in korrekter Reihenfolge aktivieren + echo "[INFO] Icinga Web 2 Module werden aktiviert." + icingacli module enable ipl + icingacli module enable reactbundle + icingacli module enable director + + # 4. Alle Dienste neu starten + echo "[INFO] Alle Services werden neu gestartet, um Konfigurationen zu laden." + systemctl restart postgresql + systemctl restart icinga2 + systemctl restart php${PHP_VERSION}-fpm + systemctl restart nginx + systemctl restart grafana-server + + # 5. Icinga Web 2 Setup ausführen (NACHDEM die Dienste laufen) echo "[INFO] Icinga Web 2 Setup wird ausgeführt." ICINGAWEB_SETUP_TOKEN=$(icingacli setup token create) icingacli setup config webserver nginx --document-root /usr/share/icingaweb2/public @@ -315,23 +354,14 @@ _setup() { --backend-type ido --resource icinga_ido icingacli user add icingaadmin --password "$ICINGAWEB_ADMIN_PASS" --role "Administrators" - # 3. Director Setup + # 6. Director Setup ausführen (als letzter Schritt) + echo "[INFO] Warte auf Icinga2 API..." + sleep 15 # Gibt Icinga2 Zeit, vollständig zu starten echo "[INFO] Icinga Director Setup wird ausgeführt." + icingacli director migration run # Importiert das Director DB Schema icingacli director kickstart --endpoint localhost --user director --password "${ICINGA_API_USER_PASS}" icingacli director config set 'endpoint' 'localhost' --user 'director' --password "${ICINGA_API_USER_PASS}" - icingacli director migration run icingacli director automation run - - # 4. Services neu starten, um alle Konfigurationen zu laden - echo "[INFO] Alle Services werden neu gestartet." - systemctl restart postgresql - systemctl restart icinga2 - systemctl restart php${PHP_VERSION}-fpm - systemctl restart nginx - systemctl restart grafana-server - - echo "[INFO] Warte auf Icinga2 API..." - sleep 15 echo "[INFO] Director Konfiguration wird angewendet." icingacli director config deploy } @@ -352,9 +382,9 @@ _info() { echo " Icinga Web 2: https://${ZAMBA_HOSTNAME:-$(hostname -f)}/icingaweb2" echo " Grafana: https://${ZAMBA_HOSTNAME:-$(hostname -f)}/grafana" echo "" - echo "Hinweis zu TLS: Der Server verwendet aktuell ein selbst-signiertes 'snakeoil'-Zertifikat." - echo "Ersetzen Sie die Symlinks in /etc/nginx/ssl/ mit Ihren echten Zertifikaten und starten Sie Nginx neu:" - echo " systemctl restart nginx" + echo "Hinweis zu TLS: Der Server verwendet aktuell die Icinga2-eigenen, selbst-signierten Zertifikate." + echo "Wenn Sie externe Zertifikate (z.B. von Let's Encrypt) verwenden möchten," + echo "passen Sie die Pfade in /etc/nginx/sites-available/icinga-stack und /etc/icinga2/features-available/api.conf an und starten Sie die Dienste neu." echo "" } @@ -368,17 +398,4 @@ _info() { # exit 1 # fi # -source zamba.conf -source constants-service.conf -# # Load constants if running standalone -ZAMBA_HOSTNAME=$(hostname -f) -source ./constants-service.conf -# -# set -e # Exit on first error -_install -_configure -_setup -_info -set +e -# -exit 0 +# # Load constants if runn