<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <blockquote type="cite"
      cite="mid:mailman.1.1565092803.14573.mythtv-users@mythtv.org">
      <pre class="moz-quote-pre" wrap="">Date: Tue, 06 Aug 2019 19:25:33 +1200
From: Stephen Worthington <a class="moz-txt-link-rfc2396E" href="mailto:stephen_agent@jsw.gen.nz" moz-do-not-send="true"><stephen_agent@jsw.gen.nz></a>
To: Discussion about MythTV <a class="moz-txt-link-rfc2396E" href="mailto:mythtv-users@mythtv.org" moz-do-not-send="true"><mythtv-users@mythtv.org></a>
Subject: Re: [mythtv-users] Fwd: MythTV backend service started before
        network is functional
Message-ID: <a class="moz-txt-link-rfc2396E" href="mailto:kp8ikepn33al4k9d59ia57075c4u3mgv9i@4ax.com" moz-do-not-send="true"><kp8ikepn33al4k9d59ia57075c4u3mgv9i@4ax.com></a>
Content-Type: text/plain; charset=us-ascii

On Mon, 5 Aug 2019 15:09:22 -0400, you wrote:

</pre>
      <blockquote type="cite" style="color: #000000;">
        <pre class="moz-quote-pre" wrap="">Stephen,

A few questions.

1) Why doesn't stopping and stopping mythtv-backend' service fix this 
issue? Is the tuner permanently marked as 'bad' barring a reboot. Note 
that the reboot runs into the same issue.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">If stopping and restarting mythbackend does not fix the problem, then
it is not the race condition.  But you do need to be sure that you
have actually stopped and restarted mythbackend.  In 14.04, how you do
that is rather different as it does not use systemd, and also not init
scripts except as a fallback option, but instead a different system
again, called Upstart.

So to do the check that restarting mythbackend fixes the problem and
hence you are getting the race condition, this is what you need to do:

Check that mythbackend is running now:

  ps -e | grep mythbackend

Then stop mythbackend:

  sudo stop mythtv-backend

and verify that it has stopped:

  ps -e | grep mythbackend

and start mythbackend again:

  start mythtv-backend

and verify that mythbackend is running again:

  ps -e | grep mythbackend

Note that the "service xxxxx start" commands also work, but only
indirectly.  The correct commands to use with Upstart are "start",
"stop", "status" and "restart".</pre>
    </blockquote>
    You can see from my question below that I have tried stopping and
    restarting the backend. I did it with 'service' and 'update-rc.d'
    but that did not seem to help for some reason. <br>
    <blockquote type="cite"
      cite="mid:mailman.1.1565092803.14573.mythtv-users@mythtv.org">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite" style="color: #000000;">
        <pre class="moz-quote-pre" wrap="">2) I have ubuntu 14.04 (upgraded from 12.04) and it seems to be half way 
into systemd and so 'systemctl' is unavailable. The backend seems to ave 
been stopped and started with 'service mythtv-backend start'. 
'NetworkManager-wait-online.service' you refer to in your solution seems 
to be unavailable as well. I see that the 
'/etc/init/mythtv-backend.conf' has the following line....

start on (local-filesystems and *net-device-up IFACE!=lo *and started 
udev-finish)

Doesn't this ensure that network access to all non-loopback devices are 
up before mythtv-backend is started? Why is there a need for the 
additional checks in your solution. Am I missing something?
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">I theory it should work, but when I checked my old 14.04.5 partition,
I can see that this is what I had:

#start on (local-filesystems and net-device-up IFACE!=lo and started
udev-finish)
start on (local-filesystems and net-device-up IFACE=eth0 and
net-device-up IFACE=br0 and net-device-up IFACE=eth1 and started
udev-finish)
stop on runlevel [016]

So I have commented out the default "start on" line and replaced it
with one that specifically specifies all the network devices to wait
on.  In my case that is eth0, eth1 and tap0, due to how that PC does
other networking and routing functions (it is my OpenVPN server).  In
your case, you would probably only want to make it wait on eth0 (or
whatever the name of your Ethernet interface is).  I am pretty sure
that I had to do that as the default "start on" line did not work
properly.

How many network interfaces does your MythTV box have?  If it only has
localhost and one Ethernet interface, then the default "start on" line
should work.  If it has more than one Ethernet interface, or also has
other interfaces such as WiFi or virtual ones such as my tap0
interface for OpenVPN, then the default "start on" line will allow
mythbackend to start when any of the other interfaces is up, not only
after the Ethernet interface used to talk to the tuners is up.
</pre>
    </blockquote>
    I have both ethernet and wireless network interface on this desktop
    but both connect the same router where my network tuner (HDHR) is
    connected. If wireless is connected, the backend should be able to
    see the HDHR through the wireless connection.<br>
    <blockquote type="cite"
      cite="mid:mailman.1.1565092803.14573.mythtv-users@mythtv.org">
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite" style="color: #000000;">
        <pre class="moz-quote-pre" wrap="">Thanks again for your help
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">Have you upgraded the PC to boot from an SSD?  That causes all sorts
of changes to the timing of things, and Upstart was never optimised
for that.
</pre>
    </blockquote>
    <p>No I did not. I have the plain old spinning disk.  For now I
      added a sleep line to "/etc/init/mythtv-backend.conf"  at the
      pre-start section as below:</p>
    <p><tt>pre-start script</tt><tt><br>
      </tt><tt>    sleep 10 # Added sleep to allow for network to be
        operational during reboot before backend</tt><br>
    </p>
    <p>and this seems to work. I tried multiple reboots to test it.<br>
    </p>
    <p>Thanks<br>
    </p>
  </body>
</html>