1

Is there any way to delay the start of the Motion service on RPI restart? I'm having an issue where v4l does not make it yet to provide /dev/video0 but Motion is already trying to open it and obviously fails to the grey screen. The log shows:

[1:ml1] [NTC] [VID] [Jan 15 23:59:11] vid_v4lx_start: Using videodevice /dev/video0 and input -1
[1:ml1] [ALR] [VID] [Jan 15 23:59:11] vid_v4lx_start: Failed to open video device /dev/video0: No such file or directory

while the /dev/video0 appears in the system some milliseconds afterwards, however too late to let the Motion catch it.

Is there any way to slow or actually delay the motion server startup on boot/restart?

The OS is Raspbian Stretch on RPI 3B+:

Linux rpi-vrel-4 4.14.70-v7+ #1144 SMP Tue Sep 18 17:34:46 BST 2018 armv7l GNU/Linux

Regards,

Piotr

3
  • This may help you how to start your service after the device is setup.
    – jake
    Jan 16, 2019 at 10:09
  • Thanks for the reply. I can see the solution to modify Motion service command into something like 'sleep 10' then execute start but isn't it going to be wiped out on Motion update? Jan 18, 2019 at 15:24
  • You can do it with After=some.service and BindsTo=some.service. If you run systemctl edit motion.service [or whatever your service is called] it will generate a new .conf file and leave the original one. For more details take a look here: askubuntu.com/a/659268.
    – jake
    Jan 18, 2019 at 15:33

1 Answer 1

0

It should work if you add following line to one of the files in udev rule folder, for example /lib/udev/rules.d/99-systemd.rules

KERNEL=="video0", SYMLINK="video0", TAG+="systemd"

Then you can bind to video device in service unit file:

[Unit]
BindsTo=dev-video0.device
After=dev-video0.device

If you run systemctl edit your.service systemd will create a directory /etc/systemd/system/your.service.d with a file named override.conf in it. If you add these lines there, your original service file will stay untouched and even survive any upgrade.

Source: https://unix.stackexchange.com/a/186903/314220

4
  • Thank you for the reply. I've successfully implemented it and it seems to work as expected but now I've got another problem. One of the RPIs that has two identical cameras, references cameras in the motion.conf using i.e.: /dev/v4l/by-path/platform-3f980000.usb-usb-0:1.2:1.0-video-index0. That was necessary to identify cameras by the USB port it is connected to, to unambiguously distinguish them. Now all the branch /dev/v4l is gone. I made it working back, using alias video0 and video1 but I'm not sure if it identifies cameras unambiguously, now. Jan 19, 2019 at 18:33
  • Maybe this could help you: askubuntu.com/a/715417. Unfortunately I don't have cameras to test it.
    – jake
    Jan 19, 2019 at 18:53
  • I'd recommend to mark this as solved, because you got what you needed to delay your service. Ask a new question then on how to unambiguously identify your devices and we will figure your problems out there. You will gain more attention with a new question.
    – jake
    Jan 19, 2019 at 19:00
  • Thx- will give it some more testing before marking as solved, as it worked well on RPI2 but same modification of the configuration brought RPI3B+ unresponding after restart (don't have physical access at the moment to see what exactly happened), just wanted to simulate restart and see how it works. Jan 19, 2019 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.