#!/bin/bash

# Handle camera service around suspend/resume.
#
# v4l2-relayd must be stopped before suspend to avoid GStreamer crashes,
# then restarted after resume once the camera hardware is ready.
#
# The post-resume restart uses systemd-run to avoid blocking the
# password prompt while waiting for the camera to initialize.

case "$1" in
  pre)
    systemctl stop v4l2-relayd@ipu7.service 2>/dev/null || true
    ;;
  post)
    systemd-run --no-block --unit=camera-resume bash -c '
      systemctl restart camera-init.service 2>/dev/null
      systemctl reset-failed v4l2-relayd@ipu7.service 2>/dev/null || true
      systemctl start v4l2-relayd@ipu7.service 2>/dev/null || true
    '
    ;;
esac
exit 0
