auto start and check HDHR record service FreeBSD/FreeNAS

Help and support for HDHomeRun DVR and HDHomeRun software for Windows 10, Mac, Android, XBox, etc.
Post Reply
cdelicath
Posts: 9
Joined: Wed Oct 07, 2020 2:35 pm

auto start and check HDHR record service FreeBSD/FreeNAS

Post by cdelicath »

So I got the recording engine installed on my freeNAS box and everything is working great but it randomly stopped running last night at some point.
Is there a way to auto start the engine and have it check every 30 minutes or so to make sure it is running on the system to avoid thins in the future?
I apologize in advance but I am a noob with doing things in FreeNAS and SSH. Might need a bit of hand holding on this one.

cdelicath
Posts: 9
Joined: Wed Oct 07, 2020 2:35 pm

Re: auto start and check HDHR record service FreeBSD/FreeNAS

Post by cdelicath »

ok i found this on another post and I think it is doing what I want but I just don't have a working knowledge of the syntax and commands to make this run as a cron job in FreeNAS.
Can anyone with more knowledge help me decipher this?
I would like to understand what this is doing and how to apply it to a cron job on my system.

Here is the code from emg60060:

Code: Select all

#!/bin/sh
HDHR=$(pgrep -u root hdhomerun_record_)
HDHRENG=$(ls /mnt/data/HDHomeRun/hdhomerun_record_freebsd_*)
DIR=$(dirname "${HDHRENG}")
if [$HDHR -eq ""]
then
        sleep 5
        $HDHRENG start --conf $DIR/hdhomerun.conf
fi
My hdhomerun config file and record engine are in - root/HDHomeRun/
When the record engine stops I manually SSH in through the FreeNAS GUI and type:

Code: Select all

cd HDHomeRun 
 ./hdhomerun_record start
to restart the engine.
I'm just not sure how the command should be made to check the record engine and restart automatically if it's not running.

emg60060
Posts: 48
Joined: Sun Jan 06, 2019 2:54 pm

Re: auto start and check HDHR record service FreeBSD/FreeNAS

Post by emg60060 »

Glad to hear its working. Scripts can be scheduled under Tasks -> Cron Jobs.

If you're not familiar with scripting, I recommend reading some basic *nix shell scripting tutorial, such as https://www.tutorialspoint.com/unix/shell_scripting.htm. Essentially, the script looks for a PID of a running process name beginning with "hdhomerun_record_" and looks for the hdhomerun_record program in the specified folder. If there is no PID, the engine isn't running and the script will attempt to start it, otherwise the script just ends.

I hope that helps.

cdelicath
Posts: 9
Joined: Wed Oct 07, 2020 2:35 pm

Re: auto start and check HDHR record service FreeBSD/FreeNAS

Post by cdelicath »

Hey thanks for the reply emg.
Thanks for providing the link. I wasn't sure where to start. I'll update my progress here in a bit.

cdelicath
Posts: 9
Joined: Wed Oct 07, 2020 2:35 pm

Re: auto start and check HDHR record service FreeBSD/FreeNAS

Post by cdelicath »

Code: Select all

#!/bin/sh
HDHR=$(pgrep -u root hdhomerun_record_)
HDHRENG=$(ls ./HDHomeRun/)
DIR=$(dirname "${HDHRENG}")
if [$HDHR -eq ""]
then
        sleep 5
        $HDHRENG start --conf $DIR/hdhomerun.conf
fi
:

EMG I am having trouble understanding line 3 and the path. My record engine is under root/HDHomeRun/ in Freenas.
Is this the right way to type it?
I believe everything else is correct based on my file names.

The only other thing I am a bit confused on is "root" after the process ID and user ID check and the trailing "_" after "hdhomerun_record" line 2

emg60060
Posts: 48
Joined: Sun Jan 06, 2019 2:54 pm

Re: auto start and check HDHR record service FreeBSD/FreeNAS

Post by emg60060 »

In your script "HDHRENG=$(ls ./HDHomeRun/)" is getting all directory contents of /root/HDHomeRun. In my script I do "HDHRENG=$(ls /mnt/data/HDHomeRun/hdhomerun_record_freebsd_*)" which only returns the name of the hdhomerun_record_* engine (currently hdhomerun_record_freebsd_20200907) to the variable HDHRENG. I do that because I like to leave the full name of the record engine. When an upgrade comes out, that allows me to put the new version on the server, manually stop the running process, and start the new one to make sure there are no obvious problems, then I delete the old one. Therefore, if your line is changed to "HDHRENG=$(ls ./HDHomeRun/hdhomerun_record_freebsd_*)", you should get the results you expect.

cdelicath
Posts: 9
Joined: Wed Oct 07, 2020 2:35 pm

Re: auto start and check HDHR record service FreeBSD/FreeNAS

Post by cdelicath »

ok i see
thanks again EMG
I will switch that back and give it a try

Post Reply