<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 11/12/2018 13:24, Stephen
      Worthington wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:cbev0et58fe1vgdjtt71m2gighp3red1si@4ax.com">
      <pre class="moz-quote-pre" wrap="">On Tue, 11 Dec 2018 08:17:33 -0500, you wrote:

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">
On 12/11/18 2:04 AM, Stephen Worthington wrote:
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">On Mon, 10 Dec 2018 17:03:02 -0500, you wrote:

</pre>
          <blockquote type="cite">
            <pre class="moz-quote-pre" wrap="">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
</pre>
          </blockquote>
          <pre class="moz-quote-pre" wrap="">Looking at the source code for mythhdhrrecorder, I can see that as it
starts up, it tries to access <a class="moz-txt-link-freetext" href="https://my.hdhomerun.com/discover">https://my.hdhomerun.com/discover</a> 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.

</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">---------------------

</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">>from time import sleep
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">
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?
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
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
<a class="moz-txt-link-abbreviated" href="mailto:mythtv-users@mythtv.org">mythtv-users@mythtv.org</a>
<a class="moz-txt-link-freetext" href="http://lists.mythtv.org/mailman/listinfo/mythtv-users">http://lists.mythtv.org/mailman/listinfo/mythtv-users</a>
<a class="moz-txt-link-freetext" href="http://wiki.mythtv.org/Mailing_List_etiquette">http://wiki.mythtv.org/Mailing_List_etiquette</a>
MythTV Forums: <a class="moz-txt-link-freetext" href="https://forum.mythtv.org">https://forum.mythtv.org</a>
</pre>
    </blockquote>
    <pre class="moz-quote-pre" wrap="">
</pre>
    <p>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.
      <style type="text/css">p { margin-bottom: 0.21cm; }a:link { }</style></p>
  </body>
</html>