Service to get SHUTDOWN_COUNTDOWN?

Post Reply
wmorrison
Senior
Posts: 122
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Service to get SHUTDOWN_COUNTDOWN?

Post by wmorrison » Tue Jan 28, 2020 8:59 pm

Is there a programatic way for a script to get myth's shutdown countdown? (The value you see at the top of mythwelcome when the system is idle and it's going to shut down when the countdown reaches zero.)

User avatar
bill6502
Developer
Posts: 1688
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Service to get SHUTDOWN_COUNTDOWN?

Post by bill6502 » Sun Feb 02, 2020 6:28 pm

No (that was easy.) You might mention your use case and see if anyone has another
solution. This could be of interest: https://www.mythtv.org/wiki/Myth_Service#DelayShutdown

wmorrison
Senior
Posts: 122
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Service to get SHUTDOWN_COUNTDOWN?

Post by wmorrison » Mon Feb 03, 2020 11:41 pm

Use case:

I want to run a background queue processor (not mythtv jobs, completely external) that will process jobs whenever the system is on, and either the backend is busy or the frontend is being actively used.

If backend is not busy, mythshutdown -c still returns "OK to shutdown" even if the frontend is still being used. I want to continue processing jobs in this state.

But I can't just check for the existence of a mythfrontend process, as there is an idle timeout setting. (I know this can be disabled.) So I need to find a way to know when frontend enters standby to stop processing jobs.

I would still lock before and unlock after a job, and if necessary wait some period between jobs to allow checking for "true idle" (both backend and frontend.)

I basically want to put jobs in a queue that may take several wakeup/shutdown cycles to complete, without forcing the system to stay on until my queue is empty.

Specifically, this is a transcoding queue using HandBrakeCLI. I have all the parts working and have been running it for small batches of jobs when I know the machine is going to be on for a while.

So I need a way to detect either:

- shutdown timer in progress
- frontend entered standby

or anything that would serve the same function.

wmorrison
Senior
Posts: 122
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Service to get SHUTDOWN_COUNTDOWN?

Post by wmorrison » Tue Feb 04, 2020 12:36 am

I just did some testing and noted that mythfrontend logs a message when it enters standby mode, and another when it leaves. So if nothing else, I can monitor the log.

User avatar
pgbennett
Developer
Posts: 352
Joined: Mon Apr 27, 2015 5:41 pm
United States of America

Re: Service to get SHUTDOWN_COUNTDOWN?

Post by pgbennett » Tue Feb 04, 2020 1:36 pm

You can easily check if the frontend is idle by using the network control port. Enable network control in the frontend setup. Send a message to port 6546 "query location" and if it returns "standbymode" it is in standby mode. For example:

Code: Select all

    if  pidof mythfrontend ; then
        fstate=`( sleep 1 ; echo query location ; sleep 1 ; echo quit ) \
                | nc localhost 6546 | grep "#" | head -1 | sed  "s/# //" \
                | dos2unix`
        if [[ "$fstate" != standbymode ]] ; then
...
        fi
    fi
You can test the network control port using telnet to see what it sends.

However I would recommend rather handle this by adding some checks to the mythtv pre-shutdown-check command to prevent shutdown while HandBrakeCLI is running. For example:

Code: Select all

    encoders='HandBrakeCLI|ffmpeg|avidemux3_cli'
    if ps -ef|egrep "$encoders"|egrep -v "grep " ; then
        echo $DATE "encoders are running, don't shut down for 5 min."
        rc=1
    fi
    exit $rc

wmorrison
Senior
Posts: 122
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Service to get SHUTDOWN_COUNTDOWN?

Post by wmorrison » Tue Feb 04, 2020 2:55 pm

pgbennett wrote:
Tue Feb 04, 2020 1:36 pm
You can easily check if the frontend is idle by using the network control port.
Thanks! I'll check that out.

However, I'm also going to check if the Frontend service call GetStatus will tell when frontend is in standby mode.
pgbennett wrote:
Tue Feb 04, 2020 1:36 pm
However I would recommend rather handle this by adding some checks to the mythtv pre-shutdown-check command to prevent shutdown while HandBrakeCLI is running.
At first glance, that appears to be the opposite of what I want to do. I don't want to keep myth on while I have jobs, I want jobs to pause when myth wants to shut down.

However, what you suggest could still be added as a "safety," for transcoding jobs and any other non-mythtv process I don't want to be interrupted by shutdown. I'll check it out.

wmorrison
Senior
Posts: 122
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Service to get SHUTDOWN_COUNTDOWN?

Post by wmorrison » Wed Feb 05, 2020 12:32 am

http://localhost:6547/Frontend/GetStatus returns "standbymode" for "currentlocation" when in standby mode.

Post Reply