Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mythshutdown control #266

Open
ikke-t opened this issue Nov 30, 2014 · 13 comments
Open

mythshutdown control #266

ikke-t opened this issue Nov 30, 2014 · 13 comments

Comments

@ikke-t
Copy link

ikke-t commented Nov 30, 2014

Please add button or menu to control mythshutdown lock.

I often use some dlna player, and it's inconvenient to ssh to mythbackend to do:
mythshutdown --lock or -u

MAF could have a control button for it.

@dmfrey
Copy link
Contributor

dmfrey commented Dec 4, 2014

Can you provide more details on what specifically would be required?

@ikke-t
Copy link
Author

ikke-t commented Dec 4, 2014

I don't know exactly how shutdown prevention happens in code. Perhaps the backend idle time counter is periodicly zeroed or smth. The shutdown feature is somehow explained here: https://www.mythtv.org/wiki/Mythshutdown

I would like MAF to provide me a way to forcefully keep mythbackend turned on. E.g.to have a button with functionality: "keep mythtv turned on"/ "let mythtv automatically shutdown". Otherwise backend shuts down after idle timeout. Sometimes I want to force it being running.

@tafypz
Copy link
Member

tafypz commented Dec 4, 2014

This process is controlled by the mythtv protocol and registering a front
end or process as a front end process. MAF uses the service API which
doesn't provide this facility

On Thu, Dec 4, 2014, 3:51 PM Ilkka Tengvall notifications@github.com
wrote:

I don't know exactly how shutdown prevention happens in code. Perhaps the
backend idle time counter is periodicly zeroed or smth. The shutdown
feature is somehow explained here:
https://www.mythtv.org/wiki/Mythshutdown

I would like MAF to provide me a way to forcefully keep mythbackend turned
on. E.g.to have a button with functionality: "keep mythtv turned on"/
"let mythtv automatically shutdown". Otherwise backend shuts down after
idle timeout. Sometimes I want to force it being running.


Reply to this email directly or view it on GitHub
#266 (comment)
.

@ikke-t
Copy link
Author

ikke-t commented Dec 4, 2014

This is a ticket which describes the mythtv problem: https://code.mythtv.org/trac/ticket/12089

@tafypz
Copy link
Member

tafypz commented Dec 4, 2014

UPnP works exactly the same way as it does not to use the mythtv protocol.

On Thu, Dec 4, 2014, 3:57 PM Ilkka Tengvall notifications@github.com
wrote:

This is a ticket which describes the mythtv problem:
https://code.mythtv.org/trac/ticket/12089


Reply to this email directly or view it on GitHub
#266 (comment)
.

@ikke-t
Copy link
Author

ikke-t commented Dec 4, 2014

Ah, too bad then...

@billmeek
Copy link
Contributor

billmeek commented Dec 4, 2014

mythshutdown --lock increments a variable in the settings table. If you're able to write
a webpage, then you can accomplish the task. But tafypz's correct, the proper way to
do this would be with a new API endpoint, or whatever happens with ticket 12089.

Note that the following is just an example, it has very little error handling and only
increments the counter, a similar version would decrement it.

HOSTNAME=yourBackendHostNameOrIp

SD_LOCK_COUNT=$(curl --silent \
    $HOSTNAME:6544/Myth/GetSetting?Key=MythShutdownLock | \
        sed -e "s/^.*<Value>//" -e "s/<\/Value>.*$//")

SD_LOCK_COUNT=$(($SD_LOCK_COUNT+1))

SET_RESULT=$(curl --silent \
    --data Key=MythShutdownLock \
    --data Value=$SD_LOCK_COUNT \
    $HOSTNAME:6544/Myth/PutSetting | \
        sed -e "s/^.*<bool>//" -e "s/<\/bool>.*$//")

if [ "$SET_RESULT" != "true" ]; then
    echo 'Unable to set the lock.'
    exit 1
fi

SD_LOCK_COUNT=$(curl --silent \
    $HOSTNAME:6544/Myth/GetSetting?Key=MythShutdownLock | \
        sed -e "s/^.*<Value>//" -e "s/<\/Value>.*$//")

echo "Lock counter = $SD_LOCK_COUNT"

@billmeek
Copy link
Contributor

billmeek commented Dec 5, 2014

Added PHP version of the above.

<!-- Install this on the Master Backend.  Save as: shutdownlock.php.
     Put it in the same directory as mythweb, for example: /var/www
     (NOT under mythweb.) --> 

<html>
<header>
<title>Control Shutdown Lock</title>
<?php

$hostname="localhost";

function http_request($method, $endpoint, $rest) {

    global $hostname;
    $params = array("http" => array(
        "method" => $method,
        "content" => $rest
    ));

    $context = stream_context_create($params);

    $fp = @fopen("http://$hostname:6544/$endpoint", "rb", false, $context);

    if (!$fp) {
        echo "fopen() failed\n";
        throw new Exception("fopen() error: $endpoint, $php_errormsg");
    }

    $xml_response = @stream_get_contents($fp);

    if ($xml_response === false) {
        echo("xml_response failed");
        throw new Exception("Read Error: $endpoint, $php_errormsg");
    }

    return $xml_response;
}

function parse_xml_response($xml_response, $pattern) {
    $value = "none";
    $xml = new XmlReader();
    $xml->xml($xml_response);
    while($xml->read()) {
        if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == $pattern) {
            $value = new SimpleXMLElement($xml->readOuterXML());
            break;
        }
    }
    return $value;
}

function adjust_lock($increment) {
    $xml_response = http_request("GET" ,"Myth/GetSetting",
                                 "Key=MythShutdownLock");
    $sd_lock_value = parse_xml_response($xml_response, "Value");
    if ($sd_lock_value == "none") {
        echo "Error: Unable to get the shutdown lock count.";
        return;
    }

    $sd_lock_value = $sd_lock_value + $increment;
    if($sd_lock_value < 0) {
        $sd_lock_value = 0;
    }
    $xml_response = http_request("POST", "Myth/PutSetting",
                                 "Key=MythShutdownLock&Value=$sd_lock_value");
    $sd_lock_bool = parse_xml_response($xml_response, "bool");

    if ($sd_lock_bool == "true") {
        echo "Current value: $sd_lock_value (non 0 blocks shutdown.)";
    }
    else {
        echo "Error: Unable to set the shutdown lock count.";
    }
}
?>
</header>

<body>
MythTV Master Backend Shutdown Controler.<br><br>
<?php
    echo "<form method='post' action='shutdownlock.php'>";
    echo "    <input type='submit' name='increment_lock' value='Increment'/>";
    echo "</form>";
    echo "<form method='post' action='shutdownlock.php'>";
    echo "    <input type='submit' name='decrement_lock' value='Decrement'/>";
    echo "</form>";

    if($_POST["increment_lock"]) {
        adjust_lock(1);
    }
    if($_POST["decrement_lock"]) {
        adjust_lock(-1);
    }
?>
</body>
</html>

@ikke-t
Copy link
Author

ikke-t commented Dec 7, 2014

Thanks billmeek for the code sample! I confirm it works, I added some lines to beginning to show the current value always:

<?php
    $xml_response = http_request("GET" ,"Myth/GetSetting",
                                 "Key=MythShutdownLock");
    $sd_lock_value = parse_xml_response($xml_response, "Value");
    if ($sd_lock_value == "none") {
        echo "Error: Unable to get the shutdown lock count.";
    }
    echo "current lock counter value: [$sd_lock_value]";
    ...

Do you think this could be added somewhere into mythweb as a feature?

I suppose the way ahead would be to wait for a day that someone would patch the API to include such entry for shutdownlock. Then it could be added to feature suggestion list of different clients. It would be great to have that on mythweb, xbmc cmyth plugin, and on andoid client.

@ikke-t
Copy link
Author

ikke-t commented Dec 7, 2014

hmmm, I don't know much about java, but I quickly looking at the java API, it has api calls for get/put settings at:

https://github.com/MythTV-Clients/MythTV-Service-API/blob/master/src/main/java/org/mythtv/services/api/v028/MythService.java#L564

But as said, I have no glue if those could be used.

@billmeek
Copy link
Contributor

billmeek commented Dec 7, 2014

Hi,
It may be possible to add to mythweb, however, mythweb is likely to
go away. WebFrontend is available in MythTV version 0.28-pre. It is
built in and required no setup (one of the major problems for mythweb
users that aren't familiar with configuring such animals.)

Also, it was interesting to note that the mythweb developer closed ALL
of his open issues in Trac citing WebFrontend as the reason for closing.
That's MY opinion, nothing official from the MythTV developers.

FYI (and Dan and Sebastien), I wrote a patch for ticket 12089 that adds the
Myth/UpdateScheduleLock endpoint. That would allow a proper client interface
to the settings table. E.g. it includes locking of the table so multiple attempts
would block until earlier attempts completed. This is now tagged as 'upstream'
til the MythTV solution is implemented.

@ikke-t
Copy link
Author

ikke-t commented Dec 8, 2014

billmeek, I briefly checked your patch, and comment on it here, as I've unfortunately lost my password to trac. There might be locking problem in error case, since the if (error) statements return without releasing the db lock. Perhaps unlock calls prior returning in error cases?

@billmeek
Copy link
Contributor

billmeek commented Dec 8, 2014

@ikke-t, thanks, fixed. I'll add the new version when mythtv.org is back on-line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants