guysoft / OctoPi

Scripts to build OctoPi, a Raspberry PI distro for controlling 3D printers over the web
GNU General Public License v3.0
2.49k stars 369 forks source link

webcamd service keeps endlessly restarting every second if there's no compatible camera attached #740

Closed foosel closed 3 years ago

foosel commented 3 years ago

What were you doing?

  1. Booting an image on a Pi without an attached camera to test
  2. Looked into /var/log/syslog and noticed the camera daemon kept restarting every other second

What did you expect to happen?

The daemon not to restart right away, but to keep running but sleep for 120s between each scan loop.

What happened instead?

The daemon script exited. The systemd file then made it immediately restart again. Endless loop.

Did the same happen when running OctoPrint in safe mode?

Not tied to OctoPrint.

Version of OctoPi

1.0.0, current devel branch pulled this morning. Also confirmed on 0.18.0.

Printer model & used firmware incl. version

Not tied to a printer (also no printer connected)

Screenshot(s)/video(s) showing the problem:

Jun 29 12:26:15 octopiC systemd[1]: Starting the OctoPi webcam daemon with the user specified config...
Jun 29 12:26:15 octopiC root: Starting USB webcam
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: starting application
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: Using V4L2 device.: /dev/video10
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: Desired Resolution: 640 x 480
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: Frames Per Second.: 10
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: Format............: JPEG
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: TV-Norm...........: DEFAULT
Jun 29 12:26:15 octopiC MJPG-streamer [22341]: init_VideoIn failed
Jun 29 12:26:16 octopiC systemd[1]: webcamd.service: Succeeded.
Jun 29 12:26:16 octopiC systemd[1]: Started the OctoPi webcam daemon with the user specified config.
Jun 29 12:26:18 octopiC systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 812.
Jun 29 12:26:18 octopiC systemd[1]: Stopped the OctoPi webcam daemon with the user specified config.
Jun 29 12:26:18 octopiC systemd[1]: Starting the OctoPi webcam daemon with the user specified config...
Jun 29 12:26:18 octopiC root: Starting USB webcam
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: starting application
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: Using V4L2 device.: /dev/video10
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: Desired Resolution: 640 x 480
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: Frames Per Second.: 10
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: Format............: JPEG
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: TV-Norm...........: DEFAULT
Jun 29 12:26:18 octopiC MJPG-streamer [22367]: init_VideoIn failed
Jun 29 12:26:19 octopiC systemd[1]: webcamd.service: Succeeded.
Jun 29 12:26:19 octopiC systemd[1]: Started the OctoPi webcam daemon with the user specified config.
Jun 29 12:26:20 octopiC systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 813.
Jun 29 12:26:20 octopiC systemd[1]: Stopped the OctoPi webcam daemon with the user specified config.
Jun 29 12:26:20 octopiC systemd[1]: Starting the OctoPi webcam daemon with the user specified config...
Jun 29 12:26:20 octopiC root: Starting USB webcam
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: starting application
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: Using V4L2 device.: /dev/video10
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: Desired Resolution: 640 x 480
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: Frames Per Second.: 10
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: Format............: JPEG
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: TV-Norm...........: DEFAULT
Jun 29 12:26:20 octopiC MJPG-streamer [22393]: init_VideoIn failed
Jun 29 12:26:21 octopiC systemd[1]: webcamd.service: Succeeded.
Jun 29 12:26:21 octopiC systemd[1]: Started the OctoPi webcam daemon with the user specified config.
Jun 29 12:26:22 octopiC systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 814.
Jun 29 12:26:22 octopiC systemd[1]: Stopped the OctoPi webcam daemon with the user specified config.
Jun 29 12:26:22 octopiC systemd[1]: Starting the OctoPi webcam daemon with the user specified config...
Jun 29 12:26:22 octopiC root: Starting USB webcam
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: starting application
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: Using V4L2 device.: /dev/video10
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: Desired Resolution: 640 x 480
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: Frames Per Second.: 10
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: Format............: JPEG
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: TV-Norm...........: DEFAULT
Jun 29 12:26:22 octopiC MJPG-streamer [22423]: init_VideoIn failed
Jun 29 12:26:23 octopiC systemd[1]: webcamd.service: Succeeded.
Jun 29 12:26:23 octopiC systemd[1]: Started the OctoPi webcam daemon with the user specified config.

Additional notes

This seems to be caused by a combination of these lines in the webcamd script:

  if [[ ${#array_camera[@]} -eq ${#array_assigned_device[@]} ]]; then
    echo "Done bring up all configured video device"
    exit 0

and the Restart: always behaviour of the system unit file.

webcamd was originally intended to never exit (which is also while there's a while true in there) and only sleep 2min whenever inactive before running another rescan. Some changes introduced with 555b28b06fccf10b4423c9ee9a807aa2c7916475 / #596 / #597 have changed this, and now things end in a restart storm if no webcam is connected as a consequence.

I suggest we remove the while True and instead leave it up to the restart policy in the system unit to take care of the 2min rescans. At least that's the only thing I can see working right now, since the multi cam support and array matching there changed the script so much from the original that I have no idea what I would break in touching THAT.

foosel commented 3 years ago

Small addendum and correction, no working camera attached. The script will find some hardcoded video devices that apparently are memory mapped devices for encoding purposes and not compatible to mjpg streamer.

foosel commented 3 years ago

Never mind, that's the RPi camera devices.