1

I have a simple application which streams video with a webcam called "streamer". I'd like to start "streamer" when my Linux device boots with systemd.

Next, I have the following systemd, service file, /lib/systemd/system/streamer.service

[Unit]
Description=Webcam Service

[Service]
ExecStart=/usr/bin/streamer

[Install]
WantedBy=multi-user.target

When I run this manually, it works such as:

systemctl start streamer

However, when I enable the script and reboot, it does not start automatically:

systemctl enable streamer
reboot

How can I get this to work with my webcam?

1 Answers1

2

I had to add a udev rule to detect camera, /etc/udev/rules.d/webcam.rules:

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

Then I made the following changes to my service file, /lib/systemd/system/streamer.service:

[Unit]
Description=Webcam Service
BindsTo=dev-video1.device
After=dev-video1.device

[Service]
ExecStart=/usr/bin/streamer

The reason for this is in the manpage for systemd.unit:

https://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=

When used in conjunction with After= on the same unit the behaviour of BindsTo= is even stronger. In this case, the unit bound to strictly has to be in active state for this unit to also be in active state.

[Install]
WantedBy=multi-user.target
eigenein
  • 103
  • 4