mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-07 07:55:16 +02:00
script fixes
This commit is contained in:
parent
2039b4ce51
commit
c76bcc3664
4 changed files with 22 additions and 22 deletions
|
|
@ -154,7 +154,7 @@ for ((w = 0; w < FASTAPI_WORKERS; w++)); do
|
|||
if [[ -f "$pidfile" ]]; then
|
||||
pid=$(<"$pidfile")
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
((old_running++))
|
||||
old_running=$((old_running + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
|
@ -168,7 +168,7 @@ log_info "Found $old_running running old worker(s)"
|
|||
# Verify new ports are free
|
||||
for ((w = 0; w < FASTAPI_WORKERS; w++)); do
|
||||
port=$((NEW_BASE + w))
|
||||
if lsof -Pi :"$port" -sTCP:LISTEN -t >/dev/null 2>&1; then
|
||||
if ss -tln "sport = :$port" | grep -q LISTEN; then
|
||||
log_error "Port $port is already in use. Cannot start new band."
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -312,14 +312,14 @@ done
|
|||
|
||||
# Generate upstream config
|
||||
sed -e "s|{{UVICORN_UPSTREAM_SERVERS}}|${UPSTREAM_SERVERS}|" \
|
||||
"$NGINX_UPSTREAM_TEMPLATE" > "$NGINX_UPSTREAM_CONF"
|
||||
"$NGINX_UPSTREAM_TEMPLATE" | sudo tee "$NGINX_UPSTREAM_CONF" > /dev/null
|
||||
|
||||
log_info "Generated nginx upstream config with $FASTAPI_WORKERS workers (ports ${NEW_BASE}–$((NEW_BASE + FASTAPI_WORKERS - 1)))"
|
||||
|
||||
# Validate config
|
||||
if ! nginx -t 2>/dev/null; then
|
||||
if ! sudo nginx -t 2>/dev/null; then
|
||||
log_error "nginx config validation failed!"
|
||||
nginx -t 2>&1 || true
|
||||
sudo nginx -t 2>&1 || true
|
||||
# Restore old upstream config
|
||||
OLD_UPSTREAM=""
|
||||
for ((w = 0; w < FASTAPI_WORKERS; w++)); do
|
||||
|
|
@ -327,14 +327,14 @@ if ! nginx -t 2>/dev/null; then
|
|||
OLD_UPSTREAM="${OLD_UPSTREAM} server 127.0.0.1:${port};\n"
|
||||
done
|
||||
sed -e "s|{{UVICORN_UPSTREAM_SERVERS}}|${OLD_UPSTREAM}|" \
|
||||
"$NGINX_UPSTREAM_TEMPLATE" > "$NGINX_UPSTREAM_CONF"
|
||||
"$NGINX_UPSTREAM_TEMPLATE" | sudo tee "$NGINX_UPSTREAM_CONF" > /dev/null
|
||||
|
||||
rollback_new_workers "$NEW_BAND"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Reload nginx (graceful — finishes in-flight requests to old upstream)
|
||||
systemctl reload nginx
|
||||
sudo systemctl reload nginx
|
||||
log_info "nginx reloaded — traffic now routed to band $NEW_BAND"
|
||||
|
||||
###############################################################################
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ if [[ -d "$RUN_DIR" ]]; then
|
|||
[[ -e "$pidfile" ]] || continue
|
||||
pid=$(<"$pidfile")
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
((live_count++))
|
||||
live_count=$((live_count + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
@ -171,17 +171,17 @@ if [[ -f "$NGINX_UPSTREAM_TEMPLATE" ]]; then
|
|||
|
||||
# Generate upstream config from template
|
||||
sed -e "s|{{UVICORN_UPSTREAM_SERVERS}}|${UPSTREAM_SERVERS}|" \
|
||||
"$NGINX_UPSTREAM_TEMPLATE" > "$NGINX_UPSTREAM_CONF"
|
||||
"$NGINX_UPSTREAM_TEMPLATE" | sudo tee "$NGINX_UPSTREAM_CONF" > /dev/null
|
||||
|
||||
echo "Generated nginx upstream config with $FASTAPI_WORKERS workers (ports ${UVICORN_BASE_PORT}-$((UVICORN_BASE_PORT + FASTAPI_WORKERS - 1)))"
|
||||
|
||||
# Test and reload nginx
|
||||
if nginx -t 2>/dev/null; then
|
||||
systemctl reload nginx
|
||||
if sudo nginx -t 2>/dev/null; then
|
||||
sudo systemctl reload nginx
|
||||
echo "Nginx reloaded successfully"
|
||||
else
|
||||
echo "ERROR: nginx config test failed, not reloading"
|
||||
nginx -t
|
||||
sudo nginx -t
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -42,17 +42,17 @@ kill_process_tree() {
|
|||
|
||||
descendants=$(get_descendants "$pid")
|
||||
|
||||
# Kill children first (bottom-up), then parent
|
||||
# Kill the parent first so supervisors don't respawn children
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
kill "$signal" "$pid" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Then kill any remaining descendants
|
||||
for desc_pid in $descendants; do
|
||||
if kill -0 "$desc_pid" 2>/dev/null; then
|
||||
kill "$signal" "$desc_pid" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
# Kill the parent
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
kill "$signal" "$pid" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
|
|
@ -113,14 +113,14 @@ for pidfile in "${pid_files[@]}"; do
|
|||
# Final check
|
||||
if kill -0 "$oldpid" 2>/dev/null; then
|
||||
echo " Error: Failed to stop $name (PID $oldpid)"
|
||||
((failed_count++))
|
||||
failed_count=$((failed_count + 1))
|
||||
else
|
||||
echo " Stopped $name (forced)"
|
||||
((stopped_count++))
|
||||
stopped_count=$((stopped_count + 1))
|
||||
fi
|
||||
else
|
||||
echo " Stopped $name"
|
||||
((stopped_count++))
|
||||
stopped_count=$((stopped_count + 1))
|
||||
fi
|
||||
else
|
||||
echo "Service $name (PID $oldpid) is not running"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue