Refactor deployment scripts to improve Node.js version handling and PM2 process management
- Updated `ensure_node_version` function in `deploy-production.sh` and `deploy-test.sh` to use a common script for Node.js version validation. - Simplified PM2 instance restart logic by introducing `deploy_restart_pm2` function in a new `deploy-runtime.sh` script. - Replaced direct PM2 commands with the new function to handle instance restarts and HTTP readiness checks. - Modified PM2 configuration files to set the script directly instead of using `node` as the interpreter, allowing for better compatibility with older Node.js versions. - Added tests for the new deployment runtime functions in `deploy-runtime.spec.ts` to ensure correct behavior during deployment. - Updated `package-lock.json` to include new dependencies and ensure compatibility with the latest changes.
This commit is contained in:
45
scripts/deploy-runtime.sh
Normal file
45
scripts/deploy-runtime.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# Sourced by the test and production deployment scripts.
|
||||
|
||||
deploy_restart_pm2() {
|
||||
local instance_name="$1"
|
||||
local config_file="$2"
|
||||
local node_binary
|
||||
|
||||
if [ ! -f "$config_file" ]; then
|
||||
echo "ERROR: PM2-Konfigurationsdatei nicht gefunden: $config_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
node_binary="$(node -p 'process.execPath')" || return 1
|
||||
echo " Starting/restarting $instance_name using Node: $node_binary"
|
||||
# PM2 retains the old script path even when restarting via a config file.
|
||||
# Recreate only this app so legacy `script: node` entries migrate as well.
|
||||
if pm2 describe "$instance_name" >/dev/null 2>&1; then
|
||||
pm2 delete "$instance_name" || return 1
|
||||
fi
|
||||
DEPLOY_NODE_BINARY="$node_binary" pm2 start "$config_file" \
|
||||
--only "$instance_name" --update-env
|
||||
}
|
||||
|
||||
deploy_wait_for_http() {
|
||||
local instance_name="$1"
|
||||
local url="$2"
|
||||
local attempt
|
||||
|
||||
echo " Waiting for $instance_name: $url"
|
||||
for ((attempt = 1; attempt <= 30; attempt++)); do
|
||||
if curl --fail --silent --max-time 2 "$url" >/dev/null; then
|
||||
echo " ✓ HTTP-Healthcheck erfolgreich: $url"
|
||||
return 0
|
||||
fi
|
||||
if [ "$attempt" -lt 30 ]; then
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
|
||||
echo "ERROR: $instance_name antwortet nicht erfolgreich auf $url"
|
||||
pm2 describe "$instance_name" || true
|
||||
pm2 logs "$instance_name" --nostream --lines 30 || true
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user