changes to the Trialver5sion processing to just use the functioning add and modul configuration
This commit is contained in:
+56
-9
@@ -179,6 +179,8 @@ build_website_image() {
|
||||
# ============================================================================
|
||||
TARGET_SYSTEM_DIR="/opt/Inventarsystem"
|
||||
TARGET_SCRIPT="$TARGET_SYSTEM_DIR/manage-tenant.sh"
|
||||
TRIAL_EXPIRATION_DIR="$TARGET_SYSTEM_DIR/trial-expirations"
|
||||
TRIAL_MODULES_OFF="library=off inventory=off student_cards=off terminplan=off"
|
||||
|
||||
get_free_port() {
|
||||
local requested_port="${1:-10002}"
|
||||
@@ -201,15 +203,62 @@ get_free_port() {
|
||||
echo "$check_port"
|
||||
}
|
||||
|
||||
register_trial_expiration() {
|
||||
local slug="$1"
|
||||
local expires_at="$2"
|
||||
local expires_epoch
|
||||
|
||||
expires_epoch=$(date -d "$expires_at" +%s 2>/dev/null || true)
|
||||
if [ -z "$expires_epoch" ]; then
|
||||
echo "[ERROR] Ungültiges Trial-Ablaufdatum für $slug: $expires_at" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$TRIAL_EXPIRATION_DIR"
|
||||
printf '%s\n' "$expires_epoch" > "$TRIAL_EXPIRATION_DIR/$slug.expiry"
|
||||
}
|
||||
|
||||
deactivate_expired_trials() {
|
||||
local now_epoch
|
||||
now_epoch=$(date +%s)
|
||||
|
||||
for expiry_file in "$TRIAL_EXPIRATION_DIR"/*.expiry; do
|
||||
[ -f "$expiry_file" ] || continue
|
||||
|
||||
local slug expires_epoch
|
||||
slug="${expiry_file##*/}"
|
||||
slug="${slug%.expiry}"
|
||||
expires_epoch=$(cat "$expiry_file" 2>/dev/null || true)
|
||||
if ! [[ "$expires_epoch" =~ ^[0-9]+$ ]]; then
|
||||
echo "[ERROR] Ungültige Ablaufdatei: $expiry_file" >&2
|
||||
continue
|
||||
fi
|
||||
if [ "$expires_epoch" -gt "$now_epoch" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "[INFO] Deaktiviere abgelaufene Testversion: $slug"
|
||||
if (cd "$TARGET_SYSTEM_DIR" && "$TARGET_SCRIPT" module "$slug" $TRIAL_MODULES_OFF); then
|
||||
rm -f "$expiry_file"
|
||||
echo "[SUCCESS] Testversion deaktiviert: $slug"
|
||||
else
|
||||
echo "[ERROR] Testversion konnte nicht deaktiviert werden: $slug" >&2
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
watcher_loop() {
|
||||
local trigger_dir="$1"
|
||||
echo "[INFO] Tenant Watcher gestartet. Lausche in $trigger_dir..."
|
||||
mkdir -p "$TRIAL_EXPIRATION_DIR"
|
||||
|
||||
while true; do
|
||||
deactivate_expired_trials
|
||||
for file in "$trigger_dir"/*.json; do
|
||||
[ -f "$file" ] || continue
|
||||
|
||||
echo "[INFO] Verarbeite Trigger: $file"
|
||||
EXPIRES_AT=""
|
||||
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
ACTION=$(jq -r '.action // "add"' "$file" 2>/dev/null || echo "add")
|
||||
@@ -217,6 +266,7 @@ watcher_loop() {
|
||||
PORT=$(jq -r '.port // empty' "$file" 2>/dev/null || true)
|
||||
PASS=$(jq -r '.password // empty' "$file" 2>/dev/null || true)
|
||||
MODULES=$(jq -r '.module_config // empty' "$file" 2>/dev/null || true)
|
||||
EXPIRES_AT=$(jq -r '.expires_at // empty' "$file" 2>/dev/null || true)
|
||||
else
|
||||
ACTION=$(grep -o '"action": *"[^"]*"' "$file" | cut -d'"' -f4 || echo "add")
|
||||
[ -z "$ACTION" ] && ACTION="add"
|
||||
@@ -224,6 +274,7 @@ watcher_loop() {
|
||||
PORT=$(grep -o '"port": *[0-9]*' "$file" | cut -d':' -f2 | tr -d ' ' || true)
|
||||
PASS=$(grep -o '"password": *"[^"]*"' "$file" | cut -d'"' -f4 || true)
|
||||
MODULES=$(grep -o '"module_config": *"[^"]*"' "$file" | cut -d'"' -f4 || true)
|
||||
EXPIRES_AT=$(grep -o '"expires_at": *"[^"]*"' "$file" | cut -d'"' -f4 || true)
|
||||
fi
|
||||
|
||||
if [ -z "$SLUG" ]; then
|
||||
@@ -262,6 +313,10 @@ watcher_loop() {
|
||||
sleep 8
|
||||
fi
|
||||
|
||||
if [ -n "${EXPIRES_AT:-}" ]; then
|
||||
register_trial_expiration "$SLUG" "$EXPIRES_AT" || true
|
||||
fi
|
||||
|
||||
# Um sicherzugehen, löschen wir verwaiste Container, bevor das Skript greift
|
||||
echo "[INFO] Bereinige verwaiste App-Container..."
|
||||
sudo docker rm -f inventarsystem-app-1 2>/dev/null || true
|
||||
@@ -295,15 +350,7 @@ watcher_loop() {
|
||||
fi
|
||||
;;
|
||||
"trial")
|
||||
DAYS=$(jq -r '.days // 14' "$file" 2>/dev/null || echo "14")
|
||||
ACTUAL_PORT=$(get_free_port "$PORT")
|
||||
|
||||
echo "[INFO] Erstelle Testversion für $SLUG (Port: $ACTUAL_PORT, Laufzeit: $DAYS Tage)..."
|
||||
if (cd "$TARGET_SYSTEM_DIR" && "$TARGET_SCRIPT" trial "$SLUG" "$ACTUAL_PORT" "$DAYS"); then
|
||||
echo "[SUCCESS] Testversion erfolgreich eingerichtet: $SLUG"
|
||||
else
|
||||
echo "[ERROR] Fehler beim Erstellen der Testversion für $SLUG" >&2
|
||||
fi
|
||||
echo "[ERROR] Veralteter trial-Trigger für $SLUG: Testversionen müssen über add erstellt werden." >&2
|
||||
;;
|
||||
*)
|
||||
echo "[ERROR] Unbekannte Aktion ($ACTION) in $file" >&2
|
||||
|
||||
Reference in New Issue
Block a user