Mailing List Archive

HDHomeRun and Mythbackend starting too early
Thanks guys for all the assistance. I now have something working. For
future reference, he's what I did:

Note: applies to standard Ubuntu 17.10 install with MythTV 0.29.

1. Find the exact filename of the existing mythbackend.service in the
/etc/systemd folder for me it was:
/etc/systemd/system/mythtv-backend.service
2. copy this file to /etc/systemd/system/
3. chown / chmod correct permissions for this new file
4. edit the [Unit] section of this file to match the following:
[Unit]
After=network.target mysqld.service NetworkManager-wait-online.service
pingnetwork.service
Wants=pingnetwork.service
5. systemctl enable mythtv-backend.service


After these changes, I was hoping that the dependancy on
*NetworkManager-wait-online.service* would fix the issue. It did not.
Mythbackend still starting up just after the network card was initialised,
but before it is assigned an IP address (i think). I spent ages trying
different things without success.

What finally fixed it was adding one more line to the file above in the
*[Service]* section:
* ExecStartPre=/bin/sleep 5*

Yes - i know. This is an ugly hack. But it works, and means i can put
this behind me for now.

Cheers
Re: HDHomeRun and Mythbackend starting too early [ In reply to ]
On 04/11/17 14:11, Mark van Dijk wrote:
> ...<snip>
> After these changes, I was hoping that the dependancy on
> *NetworkManager-wait-online.service* would fix the issue.  It did
> not.  Mythbackend still starting up just after the network card was
> initialised, but before it is assigned an IP address (i think).  I
> spent ages trying different things without success.
> What finally fixed it was adding one more line to the file above in
> the *[Service]* section:
> *   ExecStartPre=/bin/sleep 5*
> Yes - i know.  This is an ugly hack.  But it works, and means i can
> put this behind me for now.

Is this a laptop that changes networks?   Or is it a fixed host that
never changes networks?

I'd recommend removing Network Manager and simply configure your network
interface permanently.  You're not using DHCP to set an IP of a server,
right ?

--
Criggie

http://criggie.org.nz/
Re: HDHomeRun and Mythbackend starting too early [ In reply to ]
On Sat, 4 Nov 2017 14:11:38 +1300, you wrote:

>Thanks guys for all the assistance. I now have something working. For
>future reference, he's what I did:
>
>Note: applies to standard Ubuntu 17.10 install with MythTV 0.29.
>
>1. Find the exact filename of the existing mythbackend.service in the
>/etc/systemd folder for me it was:
> /etc/systemd/system/mythtv-backend.service
>2. copy this file to /etc/systemd/system/
>3. chown / chmod correct permissions for this new file
>4. edit the [Unit] section of this file to match the following:
> [Unit]
> After=network.target mysqld.service NetworkManager-wait-online.service
>pingnetwork.service
> Wants=pingnetwork.service
>5. systemctl enable mythtv-backend.service

That is exactly the wrong way to go about overriding systemd units. Do
not modify anything in /lib/systemd/system - those files get
overwritten whenever a new version of the package is installed. And
it is a bad idea to just copy a /lib/systemd/system file to
/etc/systemd/system, as when a new version of a package updates the
/lib/systemd/system file, the changes will not happen in your copy.

There is a proper mechanism for overriding settings a systemd unit
file by using an override file - see the systemd documentation. Just
the settings you need get overridden, and updates to the original unit
file still work (unless your overrides override those specific
settings).

>
>After these changes, I was hoping that the dependancy on
>*NetworkManager-wait-online.service* would fix the issue. It did not.
>Mythbackend still starting up just after the network card was initialised,
>but before it is assigned an IP address (i think). I spent ages trying
>different things without success.
>
>What finally fixed it was adding one more line to the file above in the
>*[Service]* section:
>* ExecStartPre=/bin/sleep 5*
>
>Yes - i know. This is an ugly hack. But it works, and means i can put
>this behind me for now.
>
>Cheers

Yes, indeed it is an ugly hack that will bite you the first time fsck
runs on boot and changes all the timings. If not sooner if you
install some new software that changes the timings. It is likely that
NetworkManager-wait-online.service is not enabled (it is not enabled
by default in Mythbuntu 16.04) and that is the reason it did not work
- see below.

Here is a cut and paste of one of my posts on the mythtv-users mailing
list that tells you how to do it properly:

======================================================================
I have just been helping someone else who had exactly this problem -
he upgraded to 16.04 and installed an SSD at the same time, and
mythbackend was starting before his tuners were ready (both HDHR and
internal HVR-2200 tuners). The use of systemd in 16.04 speeds up the
startup of quite a few things, including mythbackend, and an SSD
speeds everything up. The package file for mythbackend installs a
systemd /lib/systemd/system/mythtv-backend.service file that does not
take into account HDHR tuners at all - it has nothing in it to make
mythbackend wait until external networking is up and an IP address has
been assigned. This is the line it does have:

After=mysqld.service network.target

So it only waits for MySQL to be up and minimal networking. When
mythbackend starts, it immediately checks all the tuners by trying to
tune each one for a short time. Any tuner that does not respond is
marked as unavailable. And it never later checks to see if a tuner
has subsequently become available. So if mythbackend comes up before
an external IP address is assigned, it will try to talk to the HDHR
tuners before any packets can be sent to them, will get no response,
and will never try to talk to them again.

The solution is to add a new After condition that makes systemd wait
for full networking with an external IP address to be up before it
starts mythbackend.

There is a page here:

https://www.mythtv.org/wiki/Systemd_mythbackend_Configuration

that explains how to set up systemd to work with MythTV, but it is
generic rather than directly applying to Mythbuntu 16.04. The
following is what you need to do in 16.04.

First create a new directory:

sudo mkdir /etc/systemd/system/mythtv-backend.service.d

Then in that directory, create a new file mythtv-backend-override.conf
(the name does not matter but the .conf does). In that file,
put the following two lines:

[Unit]
After=NetworkManager-wait-online.service

What that does is to tell systemd to wait until the
NetworkManager-wait-online service is running. I believe that file
needs to be owned by root and have restrictive access rights, so you
may need to run these two commands to ensure that it is set up
correctly after you create it:

sudo chown root:root
/etc/systemd/system/mythtv-backend.service.d/mythtv-backend-override.conf
sudo chmod u=rw,g=r,o=r
/etc/systemd/system/mythtv-backend.service.d/mythtv-backend-override.conf

Those two lines are long enough that they may be wrapped by the email
processing. Make sure they are one long line each when you paste
them.

Next, run this command:

sudo systemctl status NetworkManager-wait-online.service

If the output of that command says that NetworkManager-wait-online is
not running, then it is likely disabled and needs to be enabled (I
believe it is disabled by default in Ubuntu 16.04). So enable it:

sudo systemctl enable NetworkManager-wait-online.service

Then you should be able to reboot and mythbackend will be started much
later after the external IP address is available.
======================================================================

_______________________________________________
mythtvnz mailing list
mythtvnz@lists.ourshack.com
https://lists.ourshack.com/mailman/listinfo/mythtvnz
Archives http://www.gossamer-threads.com/lists/mythtv/mythtvnz/
Re: HDHomeRun and Mythbackend starting too early [ In reply to ]
On Sat, 4 Nov 2017 14:27:23 +1300, you wrote:

>On 04/11/17 14:11, Mark van Dijk wrote:
>> ...<snip>
>> After these changes, I was hoping that the dependancy on
>> *NetworkManager-wait-online.service* would fix the issue.  It did
>> not.  Mythbackend still starting up just after the network card was
>> initialised, but before it is assigned an IP address (i think).  I
>> spent ages trying different things without success.
>> What finally fixed it was adding one more line to the file above in
>> the *[Service]* section:
>> *   ExecStartPre=/bin/sleep 5*
>> Yes - i know.  This is an ugly hack.  But it works, and means i can
>> put this behind me for now.
>
>Is this a laptop that changes networks?   Or is it a fixed host that
>never changes networks?
>
>I'd recommend removing Network Manager and simply configure your network
>interface permanently.  You're not using DHCP to set an IP of a server,
>right ?

It is not a good idea to remove Network Manager if you are trying to
get things to wait for an Ethernet interface to be up. With Network
Manager installed, you can wait on it being up in your systemd unit
files. Without Network Manager, you will have to write yourself a
special unit file that does something like pinging an external
address, and wait on that to succeed.

If you want to avoid the time taken to do DHCP (recommended for any
server box such as a MythTV backend), just use the Network Manager
settings for the Ethernet interface and set a "manual" IP address
there.

_______________________________________________
mythtvnz mailing list
mythtvnz@lists.ourshack.com
https://lists.ourshack.com/mailman/listinfo/mythtvnz
Archives http://www.gossamer-threads.com/lists/mythtv/mythtvnz/