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

John jksjdevelop at gmail.com
Tue Dec 11 16:53:45 UTC 2018


On 11/12/2018 13:24, Stephen Worthington wrote:
> On Tue, 11 Dec 2018 08:17:33 -0500, you wrote:
>
>> 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.
>>>
>> ---------------------
>>
> >from time import sleep
>> import socket
>>
>> for x in range(0, 15):  # try 15 times
>>      try:
>>          print socket.gethostbyname ('my.hdhomerun.com')
>>
>>          str_error = None
>>      except Exception as str_error:
>>          pass
>>
>>      if str_error:
>>          sleep(2)  # wait for 2 seconds before trying to fetch the data
>> again
>>      else:
>>          break
>>
>> ----------------------------
>>
>> maybe something like the above for the DNS part?
> That looks like it should work, but I was thinking of something
> simpler - just use the name in the ping code, so it does an automatic
> DNS lookup with every ping attempt.  There should also be code to
> allow it to be killed by Ctrl-C without doing a stack dump.  See the
> signal handler code in my net-keepalived.py file.
> _______________________________________________
> 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

As posted recently in thread Backend Startup I experienced issues  
related to opening tuners in my case DVB-S2 & DVB-T2. One tuner would 
fail to start about once a week. A backend restart normally resolved the 
issue as observed here - so there may be an issue in the Backend at 
startup, when multiple tuners are present. I have since had 13 days 
without fault (may not be statistically significant) by extending the 
tuner timeout to 10 secs and restarting the backend  at user login. I 
don't know which change fixed it. I added '/bin/systemctl restart 
mythbackend.service' to the visudo list and run it as part of my 
frontend startup script, which is autologin.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-users/attachments/20181211/9ff4d971/attachment.html>


More information about the mythtv-users mailing list