fix: graceful stop via systemctl + targeted kill, no pkill -9
This commit is contained in:
parent
7b9902f788
commit
a1f05012b4
2 changed files with 32 additions and 17 deletions
|
|
@ -39,18 +39,29 @@ if ! command -v sudo &>/dev/null; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# ── 1. Kill all existing instances ──
|
||||
# ── 1. Stop all existing instances ──
|
||||
log "Stopping any running NextNVR instances..."
|
||||
|
||||
# Graceful stop via systemd first.
|
||||
if systemctl is-active --quiet "${SERVICE_NAME}" 2>/dev/null; then
|
||||
sudo systemctl stop "${SERVICE_NAME}" 2>/dev/null || true
|
||||
sudo pkill -9 -f "/opt/nextnvr/nextnvr" 2>/dev/null || true
|
||||
sudo pkill -9 -f "go2rtc -config" 2>/dev/null || true
|
||||
sudo pkill -9 -f "ffmpeg.*-i rtsp" 2>/dev/null || true
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
# Kill any remaining processes by PID (targeted, no wildcard pkill).
|
||||
for proc in "/opt/nextnvr/nextnvr" "go2rtc"; do
|
||||
for pid in $(pgrep -f "${proc}" 2>/dev/null || true); do
|
||||
sudo kill "${pid}" 2>/dev/null || true
|
||||
done
|
||||
done
|
||||
sleep 2
|
||||
|
||||
if pgrep -f "/opt/nextnvr/nextnvr" > /dev/null 2>&1; then
|
||||
err "Cannot kill existing NextNVR processes. Please stop them manually and retry."
|
||||
exit 1
|
||||
fi
|
||||
# Final check — force kill stragglers.
|
||||
for pid in $(pgrep -f "/opt/nextnvr/nextnvr" 2>/dev/null || true); do
|
||||
sudo kill -9 "${pid}" 2>/dev/null || true
|
||||
done
|
||||
|
||||
sleep 1
|
||||
log "All instances stopped."
|
||||
|
||||
# ── 2. Detect greenfield vs update ──
|
||||
|
|
|
|||
18
remove.sh
18
remove.sh
|
|
@ -11,17 +11,21 @@ echo ""
|
|||
|
||||
# Stop service.
|
||||
echo "Stopping service..."
|
||||
if systemctl is-active --quiet "${SERVICE_NAME}" 2>/dev/null; then
|
||||
sudo systemctl stop "${SERVICE_NAME}" 2>/dev/null || true
|
||||
sudo systemctl disable "${SERVICE_NAME}" 2>/dev/null || true
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
# Kill any lingering processes (target only NextNVR binaries, not the script).
|
||||
echo "Killing processes..."
|
||||
sudo pkill -9 -f "/opt/nextnvr/nextnvr" 2>/dev/null || true
|
||||
sudo pkill -9 -f "go2rtc -config" 2>/dev/null || true
|
||||
sudo pkill -9 -f "ffmpeg.*-i rtsp" 2>/dev/null || true
|
||||
# Kill remaining processes by PID (targeted).
|
||||
for proc in "/opt/nextnvr/nextnvr" "go2rtc"; do
|
||||
for pid in $(pgrep -f "${proc}" 2>/dev/null || true); do
|
||||
sudo kill "${pid}" 2>/dev/null || true
|
||||
done
|
||||
done
|
||||
sleep 1
|
||||
|
||||
# Remove systemd service file.
|
||||
# Remove systemd service.
|
||||
sudo systemctl disable "${SERVICE_NAME}" 2>/dev/null || true
|
||||
if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then
|
||||
sudo rm -f "/etc/systemd/system/${SERVICE_NAME}.service"
|
||||
sudo systemctl daemon-reload
|
||||
|
|
|
|||
Loading…
Reference in a new issue