[mythtv-users] Remotely monitor Backend is running
James
jam at tigger.ws
Sat Oct 9 05:28:21 UTC 2021
> On 9 Oct 2021, at 1:09 pm, Stephen Worthington <stephen_agent at jsw.gen.nz> wrote:
>
> On Fri, 8 Oct 2021 18:54:04 -0500, you wrote:
>
>>
>> Hi Folks!
>>
>>
>> Trying to create a script to let me know when my MythTV Backend is not
>> running. What I have works, but apparently only if totally off-line (as
>> in off). This morning not quite sure what happened but the Frontend
>> could not find the Backend (glanced at the screen, knew it was a BE
>> issue). Accessing the webpage (Firefox to 192.168.4.3:6544) the last
>> 10 rotating display was not present, fairly certain the Current Tuner
>> Activity listing was present; Frontend Status was definitely present.
>> (Probably unnecessary information, but in case help
> .)
>>
>>
>> What I current have follows; cron on the computer my rump is usually in
>> front of has a script which inquires the Backend every 15 minutes during
>> the day. If no problem no notification; if there is a problem a popup
>> appears on my screen. Works if the MythTV is totally off, but did not
>> notify with the above situation. I also prefer the pop-up over an e-mail
>> notification.
>>
>>
>> The nitty-grity so far:
>>
>>
>> The Backend is at 192.168.4.3.
>>
>>
>> crontab on my computer:
>>
>>
>> # Test Backend 3 (BE3) is on-line every 15 minutes from 6:00 a.m. to
>> 7:45 p.m.
>>
>> # The script does not display except with a problem
>>
>> */15 07-19 * * * export DISPLAY=:0 && /bin/sh '/home/barry/MythTV
>> Backend Scripts/Test_BE3.sh'
>>
>>
>> ==> barry at NZXT:~$ cat '/home/barry/MythTV Backend Scripts/Test_BE3.sh'
>>
>> #!/bin/sh
>>
>>
>> # Test Backend 3 (BE3) 192.168.4.3
>>
>> #
>>
>> # Test cmd line for make appear off-line: search for " nc -z "
>>
>> #
>>
>> #####################################################################
>>
>> # Create variables
>>
>> current_date_time=$(date)
>>
>>
>> #####################################################################
>>
>> # Test connection -- port 6544 is default -- use 8080 for off-line test
>>
>> nc -z 192.168.4.3 6544
>>
>> if [ $? -eq 0 ]
>>
>> then
>>
>> echo "BE3 is up."
>>
>> else
>>
>> echo "exit status is $?."
>>
>> echo "BE3 192.168.4.3:6544 down."
>>
>> Err_BE3_1="Oh-oh!! MythTV Backend 3 (BE3 - 192.168.4.3) is down! "
>>
>> # XMsg_Size=" -fn '-*-*-*-r-*--0-150-0-0-p-*-iso8859-1'"
>>
>> # Why this works in one script and not another -- bug
>>
>> # XMsg_Size=" -fn '-*-*-*-r-*--0-200-0-0-p-*-iso8859-1'"
>>
>> # echo "$current_date_time\n $Err_BE3_1\n" | xmessage $XMsg_Size -file -
>>
>> echo "$current_date_time\n $Err_BE3_1\n" | xmessage -fn
>> '-*-*-*-r-*--0-200-0-0-p-*-iso8859-1' -file -
>>
>>
>> fi
>>
>>
>> exit
>>
>>
>>
>> I dont know what netcats -z switch does saw it when cookbooking
>> another project and seemed to do what I needed. ..Something about not
>> sending data (which is probably good as I saw something about a lot of
>> pings could lock up MythTV).
>>
>>
>> Thanks!
>>
>> Barry
>
> The nc -z option tells nc to do a TCP connection without sending any
> data - it just disconnects again. I ran Wireshark to confirm this. So
> what it does is send a SYN, gets a SYN,ACK reply, sends an ACK, sends
> a FIN,ACK, gets an ACK reply. Just TCP setup and disconnect packets,
> with no data in them. So what is being tested is that there is a
> program that is accepting TCP connections on port 6544.
>
> It might be better to actually use the MythTV API and, for example,
> request the next recording time, as that would check that a lot more
> of mythbackend is working. It is better to use Python for that, as
> there is API support for Python. I have code to do that as part of my
> gaps program:
>
> http://www.jsw.gen.nz/mythtv/gaps
>
> which is probably a reasonable example of a real life use of that API
> call, so you could just take a copy of gaps and cut out all the extra
> code to just leave a call to Dvr/GetUpcomingList and check the results
> and then return 0 for OK or an error code from that. However, that
> requires that you know at least a bit of Python. If you would like me
> to do a cut down version like that, let me know.
It is *very* easy to do this sort of stuff with systemd.
I offer 2 examples:
[Unit]
Description=MythTV backend service
After=network.target mysql.service
Requires=mysql.service
Wants=apache2.service
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/mythbackend
User=jam
Group=video
ExecStart=/usr/local/bin/mythbackend --logpath /var/log/mythtv $MYTHBACKEND_OPTIONS
[Install]
WantedBy=multi-user.target
---------------------------------------------------
[Unit]
Description=ssh tunnel to tigger
Requires=network.service
[Service]
ExecStart=/usr/bin/ssh -p 4123 -N -R 1200:localhost:22 -R 4001:localhost:4000 me at tigger.3utilities.com
Restart=always
RestartSec=30
User=doug
[Install]
WantedBy=multi-user.target
Including time qualifications.
In all my years of using myth it has ever 'ceased working' while the myth[front][back]end process 'continues running'
Have fun!
James
More information about the mythtv-users
mailing list