[mythtv-users] MythTV backend starts before HDHR tuners are available
Stephen Worthington
stephen_agent at jsw.gen.nz
Fri Nov 17 03:31:21 UTC 2023
On Thu, 16 Nov 2023 18:29:38 +0000, you wrote:
>The "cheap" way would be something like a
>ExecStartPre=-/usr/bin/sleep 10
Please never recommend using a delay to fix a race condition. It
almost always fails to fix the problem properly - something else
happens that changes the timing of the race condition and you will get
a failure again. The proper fix for any race condition is to wait for
the thing that is slow to come up to actually be up. So in this case,
for HDHR tuners, you make it wait for the tuners to actually be
available and responding.
In the more general case of the network being up so mythbackend will
bind to the IP address of the backend box, and then will be available
for external frontends to connect to, you need to ping something
outside the backend box and only allow mythbackend to be started after
you get a ping reply. Waiting for an HDHR tuner to be available meets
that condition, but you can just ping a router or switch or something
on your network that responds to ping requests. That is what I do on
Ubuntu 22.04, and I have a systemd unit that does the pings and then
can be used by any other systemd unit to check if the network is fully
up:
root at mypvr:~# systemctl cat local-network-pingable.service
# /etc/systemd/system/local-network-pingable.service
[Unit]
Description=Wait for the local network to be pingable
After=network.target
[Service]
Type=simple
ExecStartPre=/bin/bash -c "/usr/local/bin/wait-until-pingable.py
switch.jsw.gen.nz 30"
ExecStart=/bin/true
[Install]
WantedBy=multi-user.target
(Sorry for the line wrap - my email client has no way turn of line
wrapping. So the ExecStartPre= line is actually one line, not two.)
You can get a copy of my wait-until-pingable.py program from my web
server:
http://www.jsw.gen.nz/mythtv/wait-until-pingable.py
Then you create an override file for mythtv-backend.service:
sudo systemctl edit mythtv-backend.service
and put this in it:
[Unit]
Wants=local-network-pingable.service
After=local-network-pingable.service
Or add that to an existing override file. Then do:
sudo systemctl daemon-reload
I have other things that also need to wait for the network to be up,
so I use a separate systemd unit. If you only have mythbackend
needing that, you can just put an appropriate ping command into the
mythtv-backend.service config in an override file.
More information about the mythtv-users
mailing list