Resume timer after pause
This commit is contained in:
1 parent
7e0d562d9f
commit
cf920dc76f
7 files changed
+110
-11
No files matched your search
@@ -9,11 +9,11 @@ STATE_DIR="/var/lib/cleanup-smartcam-data"
|
||||
PAUSED_STATE="${STATE_DIR}/capture-paused"
|
||||
LOCK_FILE="/run/cleanup-smartcam-data.lock"
|
||||
|
||||
# Start deleting confirmed bundles below 15 GiB, pause capture below 8 GiB,
|
||||
# and resume only after the filesystem has recovered to 15 GiB.
|
||||
CLEAN_TARGET_BYTES="${CLEAN_TARGET_BYTES:-16106127360}"
|
||||
PAUSE_BELOW_BYTES="${PAUSE_BELOW_BYTES:-8589934592}"
|
||||
CRITICAL_BELOW_BYTES="${CRITICAL_BELOW_BYTES:-5368709120}"
|
||||
# Start deleting confirmed bundles below 10 GiB, pause capture below 5 GiB,
|
||||
# raise a critical alert below 3 GiB, and resume after recovery to 10 GiB.
|
||||
CLEAN_TARGET_BYTES="${CLEAN_TARGET_BYTES:-10737418240}"
|
||||
PAUSE_BELOW_BYTES="${PAUSE_BELOW_BYTES:-5368709120}"
|
||||
CRITICAL_BELOW_BYTES="${CRITICAL_BELOW_BYTES:-3221225472}"
|
||||
MIN_FILE_AGE_MINUTES="${MIN_FILE_AGE_MINUTES:-60}"
|
||||
SAFE_WINDOW_SECONDS="${SAFE_WINDOW_SECONDS:-10}"
|
||||
|
||||
@@ -70,6 +70,15 @@ camera_is_stopped() {
|
||||
ps -o stat= -p "$pid" 2>/dev/null | grep -q '^T'
|
||||
}
|
||||
|
||||
start_fast_resume_checks() {
|
||||
systemctl start cleanup-smartcam-data-resume.timer 2>/dev/null ||
|
||||
log ERROR "failed to start fast resume checks"
|
||||
}
|
||||
|
||||
stop_fast_resume_checks() {
|
||||
systemctl --no-block stop cleanup-smartcam-data-resume.timer 2>/dev/null || true
|
||||
}
|
||||
|
||||
wait_for_safe_window() {
|
||||
local newest size1 size2
|
||||
newest="$(find "$DATA_ROOT/videos_raw" -maxdepth 1 -type f -name '*.mp4' \
|
||||
@@ -91,6 +100,7 @@ pause_capture() {
|
||||
fi
|
||||
if camera_is_stopped "$pid"; then
|
||||
printf 'pid=%s\npaused_at=%s\n' "$pid" "$(date --iso-8601=seconds)" > "$PAUSED_STATE"
|
||||
start_fast_resume_checks
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -99,6 +109,7 @@ pause_capture() {
|
||||
fi
|
||||
kill -STOP "$pid"
|
||||
printf 'pid=%s\npaused_at=%s\n' "$pid" "$(date --iso-8601=seconds)" > "$PAUSED_STATE"
|
||||
start_fast_resume_checks
|
||||
alert CRITICAL "capture paused at free=$(human_bytes "$free_bytes"); SFTP/Kafka uploader remains running; automatic resume target=$(human_bytes "$CLEAN_TARGET_BYTES")"
|
||||
}
|
||||
|
||||
@@ -110,16 +121,19 @@ resume_capture_if_ready() {
|
||||
if ! valid_camera_pid "$pid"; then
|
||||
log WARNING "discarding stale capture pause state (pid=${pid:-unknown})"
|
||||
rm -f "$PAUSED_STATE"
|
||||
stop_fast_resume_checks
|
||||
return 0
|
||||
fi
|
||||
if ! camera_is_stopped "$pid"; then
|
||||
log WARNING "capture is already running; clearing stale pause state"
|
||||
rm -f "$PAUSED_STATE"
|
||||
stop_fast_resume_checks
|
||||
return 0
|
||||
fi
|
||||
if [[ "$free_bytes" -ge "$CLEAN_TARGET_BYTES" ]]; then
|
||||
kill -CONT "$pid"
|
||||
rm -f "$PAUSED_STATE"
|
||||
stop_fast_resume_checks
|
||||
alert RECOVERED "free space reached $(human_bytes "$free_bytes"); capture resumed automatically"
|
||||
else
|
||||
log WARNING "capture remains paused: free=$(human_bytes "$free_bytes"), resume target=$(human_bytes "$CLEAN_TARGET_BYTES")"
|
||||
|
||||
Reference in new issue
Block a user