From e82c1d9b0ae476ba057e6a7ea5241699ae6159b5 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 26 Aug 2026 11:23:48 +0200 Subject: [PATCH] Optimierung der PM2-Instanzverwaltung: Entfernen der zweiten Instanz und Anpassung der Fehlermeldungen in den Deployment-Skripten --- deploy-production.sh | 33 ++++++--------------------------- deploy-test.sh | 12 ++++++++++-- harheimertc.config.cjs | 16 ---------------- harheimertc.test.config.cjs | 2 +- 4 files changed, 17 insertions(+), 46 deletions(-) diff --git a/deploy-production.sh b/deploy-production.sh index 1788df6..2324f48 100755 --- a/deploy-production.sh +++ b/deploy-production.sh @@ -282,17 +282,11 @@ install_dependencies_if_needed # 4. Stop running apps before replacing build artifacts echo "" echo "4. Stopping PM2 before replacing build artifacts..." -if command -v pm2 >/dev/null 2>&1; then - for instance_name in harheimertc harheimertc-3102; do - if pm2 describe "$instance_name" >/dev/null 2>&1; then - pm2 stop "$instance_name" || true - echo " ✓ $instance_name gestoppt" - else - echo " PM2-Prozess $instance_name läuft nicht" - fi - done +if command -v pm2 >/dev/null 2>&1 && pm2 describe harheimertc >/dev/null 2>&1; then + pm2 stop harheimertc || true + echo " ✓ harheimertc gestoppt" else - echo " PM2 ist nicht verfügbar" + echo " PM2-Prozess harheimertc läuft nicht oder PM2 ist nicht verfügbar" fi # 5. Remove old build (but keep data!) @@ -559,18 +553,14 @@ restart_pm2_instance() { fi } -# Starte/Neustarte beide Instanzen +# Starte/Neustarte die Produktionsinstanz INSTANCE_ERRORS=0 if ! restart_pm2_instance "harheimertc"; then INSTANCE_ERRORS=$((INSTANCE_ERRORS + 1)) fi -if ! restart_pm2_instance "harheimertc-3102"; then - INSTANCE_ERRORS=$((INSTANCE_ERRORS + 1)) -fi - -# Prüfe, ob beide Prozesse laufen +# Prüfe, ob der Prozess läuft sleep 2 echo "" echo " Checking PM2 instances status..." @@ -582,19 +572,11 @@ else INSTANCE_ERRORS=$((INSTANCE_ERRORS + 1)) fi -if pm2 describe harheimertc-3102 | grep -q "online"; then - echo " ✓ PM2-Prozess 'harheimertc-3102' läuft (online)" -else - echo " WARNING: PM2-Prozess 'harheimertc-3102' ist nicht online. Prüfe Logs: pm2 logs harheimertc-3102" - INSTANCE_ERRORS=$((INSTANCE_ERRORS + 1)) -fi - if [ "$INSTANCE_ERRORS" -gt 0 ]; then echo "" echo "WARNING: Einige PM2-Instanzen haben Probleme. Bitte manuell prüfen:" echo " pm2 status" echo " pm2 logs harheimertc" - echo " pm2 logs harheimertc-3102" fi echo "" @@ -603,8 +585,5 @@ echo "The application is now running with the latest code and your production da echo "" echo "Useful commands:" echo " pm2 logs harheimertc # View logs (Port 3100)" -echo " pm2 logs harheimertc-3102 # View logs (Port 3102)" echo " pm2 status # View status" echo " pm2 restart harheimertc # Restart instance on port 3100" -echo " pm2 restart harheimertc-3102 # Restart instance on port 3102" -echo " pm2 restart all # Restart all instances" diff --git a/deploy-test.sh b/deploy-test.sh index 237afdf..307ec60 100755 --- a/deploy-test.sh +++ b/deploy-test.sh @@ -567,9 +567,10 @@ restart_pm2_instance() { # Starte/Neustarte Test-Instanz if ! restart_pm2_instance "harheimertc.test"; then echo "" - echo "WARNING: PM2-Instanz konnte nicht gestartet werden. Bitte manuell prüfen:" + echo "ERROR: PM2-Instanz konnte nicht gestartet werden." echo " pm2 status" echo " pm2 logs harheimertc.test" + exit 1 fi # Prüfe, ob der Prozess läuft @@ -580,9 +581,16 @@ echo " Checking PM2 instance status..." if pm2 describe harheimertc.test | grep -q "online"; then echo " ✓ PM2-Prozess 'harheimertc.test' läuft (online)" else - echo " WARNING: PM2-Prozess 'harheimertc.test' ist nicht online. Prüfe Logs: pm2 logs harheimertc.test" + echo " ERROR: PM2-Prozess 'harheimertc.test' ist nicht online. Prüfe Logs: pm2 logs harheimertc.test" + exit 1 fi +if ! curl --fail --silent --show-error --max-time 15 http://127.0.0.1:3102/ >/dev/null; then + echo "ERROR: Test-Instanz antwortet nicht auf Port 3102." + exit 1 +fi +echo " ✓ HTTP-Healthcheck auf Port 3102 erfolgreich" + echo "" echo "=== Test-Instanz Deployment completed successfully! ===" echo "The test application is now running with the latest code and your test data preserved." diff --git a/harheimertc.config.cjs b/harheimertc.config.cjs index 47eae05..b3dbd48 100755 --- a/harheimertc.config.cjs +++ b/harheimertc.config.cjs @@ -61,22 +61,6 @@ module.exports = { out_file: '/var/log/pm2/harheimertc-out.log', log_file: '/var/log/pm2/harheimertc-combined.log', time: true - }, - { - name: 'harheimertc-3102', - // Zweite Instanz auf Port 3102 - script: 'node', - args: '.output/server/index.mjs', - cwd: '/var/www/harheimertc', - instances: 1, - autorestart: true, - watch: false, - max_memory_restart: '1G', - env: createEnv(3102), - error_file: '/var/log/pm2/harheimertc-3102-error.log', - out_file: '/var/log/pm2/harheimertc-3102-out.log', - log_file: '/var/log/pm2/harheimertc-3102-combined.log', - time: true } ] } diff --git a/harheimertc.test.config.cjs b/harheimertc.test.config.cjs index 3f72606..193ade6 100755 --- a/harheimertc.test.config.cjs +++ b/harheimertc.test.config.cjs @@ -58,7 +58,7 @@ module.exports = { autorestart: true, watch: false, max_memory_restart: '1G', - env: createEnv(process.env.PORT || 3102), + env: createEnv(3102), error_file: '/var/log/pm2/harheimertc.test-error.log', out_file: '/var/log/pm2/harheimertc.test-out.log', log_file: '/var/log/pm2/harheimertc.test-combined.log',