User Tools

Site Tools




Motion watchdog to fix daemon shutting down

If you are using Motion for your security cameras, you may have noticed that sometimes the daemon shut down unexpectedly for a reason or another. E.g., I've noticed that sometimes it stops when the fps of one camera are too low (don't ask me why that triggers a crash of the daemon).

Whatever the case, it could happen at any time for any reason, and since this is a kind of mission critical software it's always a good idea to have a watchdog to restart the service whatever the case.

# MOTION WATCHDOG - restart the service if stopped
# Call this script from root crontab
# Where to write the log...
# ... and the user that can manage the log without sudo
if ! pidof "$SERVICE" >/dev/null
   #echo "$SERVICE stopped"
   #restart the service
   if [ ! -f "$LOG" ]; then
      touch "$LOG"
      chown "$OWNER" "$LOG"
   echo $(date +'%F %T') 'Restart' >> "$LOG"
   motion -c /etc/motion/motion.conf

Call this script from the Linux cron every minute and you are done. The watch.log will show when and how many times the daemon has shut down and restarted by this script.

software/motion-watchdog-to-fix-daemon-shutting-down.txt · Last modified: 2020/01/31 08:18 by rik