slight hanges to the startup struktur with respkt to the more sufisticatet and gracefull start up sequenz
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
# Automatische Subdomain-Hosts-Synchronisation
|
||||
|
||||
## Problem
|
||||
Nach jedem Neustart waren die Subdomains nicht mehr im `/etc/hosts` eingetragen, was zu Verbindungsproblemen führte. Das musste manuell mit `sync_dev_hosts.sh` behoben werden.
|
||||
|
||||
## Lösung
|
||||
|
||||
Diese Lösung bietet drei Ebenen der Automatisierung:
|
||||
|
||||
Hinweis für neue Systeme: `sudo ./setup-first-install.sh` richtet den Hosts-Sync-Service zusammen mit dem restlichen Basis-Setup automatisch ein.
|
||||
|
||||
### 1. Automatische Sync bei Container-Start
|
||||
Dateien: `Website/launch_prod.sh` und `Website/launch_dev.sh`
|
||||
|
||||
- Nach `docker compose up` wird `sync_dev_hosts.sh` automatisch aufgerufen
|
||||
- Ein Background-Daemon sorgt für regelmäßige Synchronisation
|
||||
- **Development:** Alle 30 Sekunden (konfigurierbar via `DEV_HOSTS_REFRESH_INTERVAL`)
|
||||
- **Production:** Alle 3600 Sekunden/1 Stunde (konfigurierbar via `PROD_HOSTS_REFRESH_INTERVAL`)
|
||||
|
||||
### 2. systemd Service für permanente Automatisierung
|
||||
Dateien: `invario-hosts-sync.service`, `setup-hosts-sync.sh`
|
||||
|
||||
Der systemd-Service stellt sicher, dass die Hosts-Synchronisation auch nach System-Reboots aktiviert bleibt.
|
||||
|
||||
#### Installation:
|
||||
```bash
|
||||
cd /home/max/Dokumente/repos/Key-service-Server
|
||||
sudo ./setup-hosts-sync.sh
|
||||
```
|
||||
|
||||
#### Status überprüfen:
|
||||
```bash
|
||||
sudo systemctl status invario-hosts-sync
|
||||
```
|
||||
|
||||
#### Logs anschauen:
|
||||
```bash
|
||||
sudo journalctl -u invario-hosts-sync -f
|
||||
```
|
||||
|
||||
#### Deinstallation:
|
||||
```bash
|
||||
sudo systemctl disable invario-hosts-sync
|
||||
sudo systemctl stop invario-hosts-sync
|
||||
sudo rm /etc/systemd/system/invario-hosts-sync.service
|
||||
sudo systemctl daemon-reload
|
||||
```
|
||||
|
||||
### 3. Manuelle Synchronisation
|
||||
Jederzeit manuell möglich:
|
||||
```bash
|
||||
cd /home/max/Dokumente/repos/Key-service-Server/Website
|
||||
./sync_dev_hosts.sh
|
||||
```
|
||||
|
||||
## Wie es funktioniert
|
||||
|
||||
1. **sync_dev_hosts.sh** liest alle Subdomains aus der MongoDB-Datenbank
|
||||
2. Aktualisiert `/etc/hosts` mit den gültigen Subdomains
|
||||
3. Läuft auf verschiedenen Ebenen:
|
||||
- Beim Container-Start (launch_prod.sh/launch_dev.sh)
|
||||
- Im Hintergrund als regelmäßiger Job
|
||||
- Als systemd-Service für permanente Überwachung
|
||||
|
||||
## Konfiguration
|
||||
|
||||
### Environment-Variablen:
|
||||
|
||||
**Für Development:**
|
||||
```bash
|
||||
DEV_HOSTS_IP=192.168.1.100 # Optionale IP (Standard: auto-detect)
|
||||
DEV_HOSTS_REFRESH_INTERVAL=30 # Sekunden zwischen Syncs (0 = deaktiviert)
|
||||
```
|
||||
|
||||
**Für Production:**
|
||||
```bash
|
||||
PROD_HOSTS_REFRESH_INTERVAL=3600 # Sekunden zwischen Syncs (0 = deaktiviert)
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Service startet nicht
|
||||
```bash
|
||||
# Logs prüfen
|
||||
sudo journalctl -u invario-hosts-sync --no-pager
|
||||
|
||||
# Service neu laden
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart invario-hosts-sync
|
||||
```
|
||||
|
||||
### Hosts werden nicht aktualisiert
|
||||
```bash
|
||||
# Manuell testen
|
||||
./Website/sync_dev_hosts.sh
|
||||
|
||||
# MongoDB-Verbindung prüfen
|
||||
docker compose ps mongodb
|
||||
docker compose logs mongodb
|
||||
```
|
||||
|
||||
### Berechtigungen
|
||||
Das Skript benötigt Zugriff auf `/etc/hosts`. Normalerweise wird es als `root` ausgeführt:
|
||||
```bash
|
||||
# Wenn nötig mit sudo
|
||||
sudo ./Website/sync_dev_hosts.sh
|
||||
```
|
||||
@@ -41,19 +41,9 @@ services:
|
||||
MONGO_WAIT_QUEUE_TIMEOUT_MS: ${MONGO_WAIT_QUEUE_TIMEOUT_MS:-2000}
|
||||
SESSION_COOKIE_SECURE: ${SESSION_COOKIE_SECURE:-0}
|
||||
JWT_SECRET_KEY: change-this-in-production
|
||||
INSTANCE_PROVISION_SCRIPT: /app/provision_instance.sh
|
||||
INSTANCE_BASE_DIR: /opt/inventarsystem-instances
|
||||
INSTANCE_PARENT_DOMAIN: ${INSTANCE_PARENT_DOMAIN:-meine-domain}
|
||||
INSTANCE_REPO_URL: ${INSTANCE_REPO_URL:-https://github.com/AIIrondev/legendary-octo-garbanzo}
|
||||
INSTANCE_TLS_MODE: ${INSTANCE_TLS_MODE:-development}
|
||||
INSTANCE_WILDCARD_CERT_FILE: ${INSTANCE_WILDCARD_CERT_FILE:-/etc/nginx/certs/wildcard.meine-domain.crt}
|
||||
INSTANCE_WILDCARD_KEY_FILE: ${INSTANCE_WILDCARD_KEY_FILE:-/etc/nginx/certs/wildcard.meine-domain.key}
|
||||
INSTANCE_BASE_DIR: /opt/Invario_Website
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /opt/inventarsystem-instances:/opt/inventarsystem-instances
|
||||
- /etc/nginx/sites-available:/etc/nginx/sites-available
|
||||
- /etc/nginx/sites-enabled:/etc/nginx/sites-enabled
|
||||
- /etc/nginx/certs:/etc/nginx/certs
|
||||
ports:
|
||||
- "4999:4999"
|
||||
mem_limit: 256m
|
||||
|
||||
+26
-4
@@ -4,6 +4,26 @@ set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
DOCKER_CMD=()
|
||||
|
||||
resolve_docker_cmd() {
|
||||
if docker info >/dev/null 2>&1; then
|
||||
DOCKER_CMD=(docker)
|
||||
return 0
|
||||
fi
|
||||
|
||||
if sudo -n docker info >/dev/null 2>&1; then
|
||||
DOCKER_CMD=(sudo docker)
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "[FEHLER] Kein Zugriff auf den Docker Daemon (/var/run/docker.sock)." >&2
|
||||
echo "Führe das Script mit sudo aus oder füge deinen User zur docker-Gruppe hinzu:" >&2
|
||||
echo " sudo usermod -aG docker $USER" >&2
|
||||
echo "Danach neu einloggen und Script erneut starten." >&2
|
||||
exit 3
|
||||
}
|
||||
|
||||
export SESSION_COOKIE_SECURE="0"
|
||||
export INSTANCE_TLS_MODE="development"
|
||||
export INSTANCE_PARENT_DOMAIN="${INSTANCE_PARENT_DOMAIN:-meine-domain}"
|
||||
@@ -21,8 +41,10 @@ if [ ! -f "$SCRIPT_DIR/gunicorn.conf.py" ]; then
|
||||
exit 2
|
||||
fi
|
||||
|
||||
docker compose build website
|
||||
docker compose up -d
|
||||
resolve_docker_cmd
|
||||
|
||||
"${DOCKER_CMD[@]}" compose build website
|
||||
"${DOCKER_CMD[@]}" compose up -d
|
||||
|
||||
# Wait for website to become healthy (simple HTTP check)
|
||||
check_url="http://localhost:4999"
|
||||
@@ -43,9 +65,9 @@ done
|
||||
if [ $elapsed -ge $timeout_seconds ]; then
|
||||
echo "[FEHLER] Website nicht erreichbar nach ${timeout_seconds}s. Sammle Diagnosedaten..."
|
||||
echo "--- docker compose ps ---"
|
||||
docker compose ps || true
|
||||
"${DOCKER_CMD[@]}" compose ps || true
|
||||
echo "--- docker logs website (tail 200) ---"
|
||||
docker logs --tail 200 website-website-1 || true
|
||||
"${DOCKER_CMD[@]}" logs --tail 200 website-website-1 || true
|
||||
echo "Bitte prüfe Container-Logs und nginx-Konfiguration."
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "Error: docker is not installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DOCKER_CMD=(docker)
|
||||
|
||||
if ! docker info >/dev/null 2>&1; then
|
||||
if command -v sudo >/dev/null 2>&1 && sudo -n docker info >/dev/null 2>&1; then
|
||||
DOCKER_CMD=(sudo docker)
|
||||
echo "==> Docker daemon requires elevated permissions; using sudo docker"
|
||||
else
|
||||
echo "Error: cannot access Docker daemon (/var/run/docker.sock)."
|
||||
echo ""
|
||||
echo "Fix options:"
|
||||
echo " 1) Run once with sudo: sudo ./start_docker_build.sh"
|
||||
echo " 2) Permanent fix (recommended):"
|
||||
echo " sudo usermod -aG docker $USER"
|
||||
echo " newgrp docker"
|
||||
echo " # or logout/login"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! "${DOCKER_CMD[@]}" compose version >/dev/null 2>&1; then
|
||||
echo "Error: docker compose plugin is not available."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "==> Building website image (pure Python runtime)"
|
||||
"${DOCKER_CMD[@]}" compose build website
|
||||
|
||||
echo "==> Starting internal MongoDB + Website containers"
|
||||
"${DOCKER_CMD[@]}" compose up -d
|
||||
|
||||
echo "==> Container status"
|
||||
"${DOCKER_CMD[@]}" compose ps
|
||||
|
||||
echo "Application is starting on: http://localhost:4999"
|
||||
echo "Use: docker compose logs -f website"
|
||||
echo "Provisioning is available in the container via /app/provision_instance.sh"
|
||||
@@ -105,16 +105,16 @@
|
||||
<section class="module-shell" aria-label="Module Übersicht">
|
||||
<div class="module-nav" role="navigation" aria-label="Module Navigation">
|
||||
<ul>
|
||||
<li class="active" data-module="mod1"><a href="#mod1">Modul 1</a></li>
|
||||
<li data-module="mod2"><a href="#mod2">Modul 2</a></li>
|
||||
<li data-module="mod3"><a href="#mod3">Modul 3</a></li>
|
||||
<li data-module="mod4"><a href="#mod4">Modul 4</a></li>
|
||||
<li class="active" data-module="mod1"><a href="#mod1">Inventarsystem</a></li>
|
||||
<li data-module="mod2"><a href="#mod2">Bibliothekssystem</a></li>
|
||||
<li data-module="mod3"><a href="#mod3">Terminplaner</a></li>
|
||||
<li data-module="mod4"><a href="#mod4">Mail Add On</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="module-content" id="moduleContent">
|
||||
<article id="mod1" class="module-panel">
|
||||
<h2>Modul 1 — Titel</h2>
|
||||
<h2>Inventarsystem</h2>
|
||||
<p class="lede">Kurze Zusammenfassung des Moduls. (Platzhalter — du ersetzt den Inhalt später.)</p>
|
||||
<h3>Was ist das?</h3>
|
||||
<p>Beschreibe hier den Zweck, Zielgruppe und schnelle Anwendungsfälle.</p>
|
||||
@@ -132,17 +132,17 @@
|
||||
</article>
|
||||
|
||||
<article id="mod2" class="module-panel hidden">
|
||||
<h2>Modul 2 — Titel</h2>
|
||||
<h2>Bibliothekssystem</h2>
|
||||
<p class="lede">Platzhaltertext für Modul 2.</p>
|
||||
</article>
|
||||
|
||||
<article id="mod3" class="module-panel hidden">
|
||||
<h2>Modul 3 — Titel</h2>
|
||||
<h2>Terminplaner</h2>
|
||||
<p class="lede">Platzhaltertext für Modul 3.</p>
|
||||
</article>
|
||||
|
||||
<article id="mod4" class="module-panel hidden">
|
||||
<h2>Modul 4 — Titel</h2>
|
||||
<h2>Mail Add On</h2>
|
||||
<p class="lede">Platzhaltertext für Modul 4.</p>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user