[mythtv-users] delaying backend startup until the network is up

James Abernathy jfabernathy at gmail.com
Tue Dec 11 12:29:58 UTC 2018

On 12/11/18 2:04 AM, Stephen Worthington wrote:
> On Mon, 10 Dec 2018 17:03:02 -0500, you wrote:
>> on my production system I use without issue the systemd override provided by.
>> sudo systemctl edit mythtv-backend.service
>> [Unit]
>> After=NetworkManager-wait-online.service
>> When I built a test system using the same HDHR tuners but with the mythhdhrrecorder external recorder I used the same overide setup. However, if I boot my test system I get a lot of errors on 2-4 tuners and the errors are related to opening the tuner. This is solved by doing the following after boot:
>> sudo systemctl stop mythtv-backend
>> sudo systemctl start mythtv-backend
>> What is special about mythhdhrrecorder and external recorder blackbox that makes this systemd override not work???
>> Jim A
> Looking at the source code for mythhdhrrecorder, I can see that as it
> starts up, it tries to access https://my.hdhomerun.com/discover as
> part of its discovery of the HDHR devices.  So it looks like you need
> full Internet access up (including the name servers working) before
> that will work.  So I think what is needed is a systemd unit that
> first does a DNS lookup of my.hdhomerun.com (say once a second), and
> when that works, does a ping of my.hdhomerun.com and when that works,
> the unit startup succeeds.  Then you can have mythbackend wait for
> that unit to be started before it starts.  However, there should be a
> timeout (say 30 seconds) after which mythbackend gets to start anyway,
> otherwise if your Internet access is down, you will be unable to start
> mythbackend.
> I have never built a systemd unit like that, but I think it would work
> if you wrote a script (or some Python) to do the DNS lookup and ping,
> and put it in the ExecStartPre line to be run before the main
> executable of the unit gets run from the ExecStart line.  The
> ExecStart line would then need to do nothing.  I am not sure how you
> are supposed to do nothing in systemd, but running /bin/true should
> work.
> So a unit "full-internet.service" like this might work:
> [Unit]
> Description=Wait for full Internet service to be available including
> DNS.
> After=NetworkManager-wait-online.service
> [Service]
> Type=simple
> ExecStartPre=/usr/bin/python3 /usr/bin/full-internet.py
> ExecStart=/bin/true
> [Install]
> WantedBy=multi-user.target
> and in your mythtv-backend override file, use:
> After=full-internet.service
> The full-internet.py script would handle the DNS lookup, ping, and
> timeout after 30 seconds.  It might be a good idea if it took the DNS
> name and timeout values as command line parameters, to make it more
> generally useful.  I have a script I use for reloading the drivers of
> an Ethernet card when the connection drops that I could use for a
> framework to make a full-internet.py script.  It does regular pings to
> see if the connection is up so it has most of the code I would need.
> Let me know if you would like me to do this.  I think this is a
> problem that has cropped up in various forms for years, so it would be
> worth my writing this if it was going to be useful.
Thanks, I'll play around with the full-internet.py idea. Since this is a 
test build I can't screw it up.

Jim A

> If you want to restart a systemd service, there is a single command
> for that:
> sudo systemctl restart mythtv-backend
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at mythtv.org
> http://lists.mythtv.org/mailman/listinfo/mythtv-users
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org

More information about the mythtv-users mailing list