Hi all…I posted this on the TVH forum about 2 weeks ago but haven’t had anything back, so trying here in the hope that someone here can provide advice.
I have a Pi running TVH, and an NFS mount to an OMV server to hold the recordings, with OSMC on another Pi as a front end.
I’ve noticed that if I restart the Pi when OMV server isn’t up, TVH will write recordings locally into the mount folder…and all the existing recordings, (on the OMV file share), get moved to ‘Removed Recordings’.
If I reboot the Pi when the OMV server is running all is well, new recordings go to the OMV share and the existing recordings are back where they belong in ‘Finished Recordings’.
I figure that my best bet is to run the wol script, which is just a simple ‘wakeonlan’ command using the MAC of the OMV server, on startup/reboot of the Pi…mostly to save me having to remember to do things in the correct order!
However, searching on how to do it gives me multiple options…rc.local, .bashrc, init.d tab, systemd, and crontab.
Far too many choices for a noob like me !
Looking for some advice on the right way to add the script…or am I missing as trick in the config of the nfs mount I have in /etc/fstab?
This is currently:
IP:/PVR mnt/PVR nfs defaults 0 0
Thanks in advance!
I’ll have a stab at this. NB This will only work if TVH runs as a systemd service. (Unfortunately, I don’t have it installed, am currently away from home and don’t have access to my home system.)
First, the /etc/fstab line needs to change to:
IP:/PVR /mnt/PVR nfs noauto,x-systemd.automount 0 0
which will bring the mount under the systemd automount system. When /mnt/PVR is mounted, this should activate a mount file
Assuming TVH is under systemd, you then need to add (or modify) one new line in the
[Unit] section of
tvheadend.service file (or whatever it’s called):
After=<whatever is already there> mnt-PVR.mount
You should find the .service file in
/etc/systemd/system. You might also find that adding/modifying the
Wants= line is necessary:
Wants=<whatever is already there> mnt-PVR.mount
Reboot and see if it works.
Edit: I forgot to add that you might need to add an
ExecStartPre=<command> line to the tvheadend.service that runs the WOL command, possibly followed by some kind of wait. Ideally, I’d put the commands in a separate shell script.
Thanks for the response dillthedog, I’ll give that a try and report back…apologies for the tardy response, been a busy week!
It’s bog standard Raspbian with TVH on top, so should be systemd.
Can you clarify the bit about ExecStartPre, I’m not sure what you mean by that?
You were talking about sending a WOL signal to the OMV server. So if the server is really in a suspended state – rather than, for example, just having the disks in a spun-down state – that’s where you’d insert the name of the WOL script that gets run before TVH starts up. You might want to include some kind of wait in the script, or a check that the machine is back online, before exiting.
This is just a proof of concept, right now. If it works, we’ll need to do a bit more configuration so that the changes to the TVH .service file aren’t lost during an update.
Thanks again for this.
I got it…so, the script I have on the file system of the Pi running TVH, as it is called as the ‘pre-processor command’ for recordings to wake up the OMV server prior to a recording starting. It currently just has the ‘wakeonlan’ command in it, no wait/checks at present.
Can I reuse that script for ExecStartPre?
Not gotten to try your suggestion yet, had to replace my switch this evening. Will hopefully get to have a go at this tomorrow night.
Ok, so I got some time to look at this just now…
It would appear that TVH is not running under systemd but rather init.d…I base this on the fact there’s nothing in /etc/systemd/system for TVH, but there is a ‘tvheadend’ script in /etc/init.d.
Assuming I’m not being a muppet, how does that change the instructions you provided above please?
Thanks in advance…
I’m back home now so can try out a few things. I’ll take a look at the Raspbian TVH package and report back.
Really appreciate that, thank you!
I’ve had only a short amount of time to look at this today, but it’s not looking very straightforward.
Yes, tvheadend is using the System V init system. [It looks like the OSMC TVH package has been moved to systemd, but unfortunately it also looks like it isn’t compatible with Raspbian.] The init file gets dynamically translated into a systemd .service file at system startup. (You can see the resulting file by running
systemctl cat tvheadend.) All in all, it’s a bit kludgy and means that we can’t modify the tvheadend.service with a “drop-in” file.
I also noticed that the TVH init file is set to start at runlevel 2, which is before networking has started! Not sure why the developer chose this but it’s not ideal in your case. This can probably be fixed by adding the word
$network to the line
# Required-Start: line of
/etc/init.d/tvheadend – but be aware that it’ll likely be overwritten during a TVH update.
Right now, I don’t have an easy answer. I would still recommend that you move your fstab line to systemd automount and perhaps the small tweak to the init file will also help delay the startup sufficiently. This won’t solve the WOL sequencing issue but you should consider reconfiguring the OMV server to allow for disk spin-down but not to shut down completely. It is a server, after all.
Edit: I was wrong. You can use a systemd drop-in to alter a generated .service unit. Here’s my proof of concept drop-in:
pi@raspberrypi:~ $ cat /etc/systemd/system/tvheadend.service.d/tvh.conf
Keep the file name as it is. Clearly, you’ll need to use
mnt-PVR instead of
mnt-test and also place your own script name in place of the sleep command.
Thanks again for all your efforts on this dill…
I’ve already made the change to fstab as you suggested previously, and with the OMV server up a reboot of TVH works fine, the mount is there…so so far so good!
So, if I’ve understood the above correctly, I have two further changes to make:
- Adding $network to /etc/init.d/tvheadend
- Creating the tvh.conf file using mnt-PVR and calling my WOL script
That about right?
The OMV server uses the Autoshutdown plugin to check for activity, and ‘shuts down’ using the Suspend option from the available list…I’ll investigate if one of the other options provides for just spinning down disks.
I’d suggest you skip change 1 ($network), since such a change might not be permanent, and modify the two lines under [Unit] to include network-online.target. So now:
It might be the case that the network-online.target isn’t required, since mnt-PVR.mount will, in your case, need the network to be up, but I don’t think its inclusion will break anything.
Right, so added the tvh.conf file and rebooted…and it worked AFAIK as the OMV server sprang into life after a while.
Logging into the TVH front end showed me exactly what I’d expect as well.
Looks like this has sorted it…thank you dill!
Out of interest, did you place a sleep or some other check after issuing the WOL?
If, after a few more days, it still seems to be 100% working, don’t forget to mark the thread as solved.
Yup, I put a sleep command in the script after the wakeonlan…just 10 seconds to start with, will keep an eye on it and maybe increase it if necessary.
Sure thing, will mark as solved once it’s been a few days.
Appreciate all you help with this!
HAppy to say that since I put this in place, there’s been no missed recordings at all…thanks to dillthedog for all the help, very much appreciated!