Mailing List Archive

Autostart frontend ONLY on manual startup?
Has anyone figured out an elegant way to do the following:

- Have Myth frontend start up automatically if and only if the machine
was started manually


Specifically, the frontend should autostart if I walk up to the
computer and press the power button on the machine. The frontend
should not start if nvram-wakeup set the BIOS start time and the
machine started up by itself.

I have a combo frontend/backend box. I use nvram-wakeup, so once I
exit the frontend, the machine shuts down after 5 mins if it's not
recording anything. It wakes itself up 5 mins before it needs to
record the next show.

Right now the frontend does not start automatically; I have to press
the power button on my remote to start the frontend. This is so that
the machine can start up automatically, record something, then shut
down automatically.

It would be nice to have the frontend start automatically when I
manually start the box, but not start when the box autostarted.

Any tips would be greatly appreciated!

Cheers,
Lane

--
Meetup with other Myth users!
http://mythtv.info/moin.cgi/MUG
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
Lane wrote:

>Has anyone figured out an elegant way to do the following:

>- Have Myth frontend start up automatically if and only if the machine
>was started manually

Yes, PoP and something that I was planning to do this weekend.

Basicly I am planning to change the shutdown command to run a script
which would set a value (probably write it to the mythconverg database
but it could be as simple as putting the wakeup time in a file) then
shutdown.
The script that starts the frontend then would look at this value and
if the current time was within a specified amount of that time then don't
start the frontend, if it's way out then start the frontend.

I'll post the scripts when I've finished if anyone's interested.

HTH

Druid
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
Lane,

I have something similar to that, on boot I startx
then using .xinitrc I display a xmessage box asking
Start Myth. When you want to use myth, press enter on
the remote to start it up.

To do this I replaced the startup of X in the init.d
scripts with this

#! /bin/sh

su mythtv -c "startx > /var/tmp/startx.log &" &

This starts X with a window manager, as userid mythtv

Then in the mythtv home directory created this
.xinitrc file to do the other steps required

xset -dpms s off &
# xclock
mwm &
irxevent &
irexec &
nvidia-settings -l
while :;
do
xmessage -font 12x24romankana -buttons "Start Myth
TV:1" -center -default "Start Myth TV" MythTV
mythfrontend -l /var/tmp/mythfrontend.log

done

This starts the mwm window manager, lirc programs,
settings from my nvidia card, then the xmessage /
mythfrontend loop.

To shutdown the machine, just exit mythfrontend, then
when the backend is idle, it will autoshutdown.

Sean


--- Druid <mythtv-users@fastdruid.co.uk> wrote:
> Lane wrote:
>
> >Has anyone figured out an elegant way to do the
> following:
>
> >- Have Myth frontend start up automatically if and
> only if the machine
> >was started manually
>
> Yes, PoP and something that I was planning to do
> this weekend.
>
> Basicly I am planning to change the shutdown
> command to run a script
> which would set a value (probably write it to the
> mythconverg database
> but it could be as simple as putting the wakeup time
> in a file) then
> shutdown.
> The script that starts the frontend then would look
> at this value and
> if the current time was within a specified amount of
> that time then don't
> start the frontend, if it's way out then start the
> frontend.
>
> I'll post the scripts when I've finished if anyone's
> interested.
>
> HTH
>
> Druid
> > _______________________________________________
> mythtv-users mailing list
> mythtv-users@mythtv.org
>
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
>
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
On Thu, 3 Mar 2005 20:03:37 -0500 (EST), Sean G <sg_m_dev@rogers.com> wrote:
> Lane,
>
> I have something similar to that, on boot I startx
> then using .xinitrc I display a xmessage box asking
> Start Myth. When you want to use myth, press enter on
> the remote to start it up.
>
> To do this I replaced the startup of X in the init.d
> scripts with this
>
> #! /bin/sh
>
> su mythtv -c "startx > /var/tmp/startx.log &" &
>
> This starts X with a window manager, as userid mythtv
>
> Then in the mythtv home directory created this
> .xinitrc file to do the other steps required
>
> xset -dpms s off &
> # xclock
> mwm &
> irxevent &
> irexec &
> nvidia-settings -l
> while :;
> do
> xmessage -font 12x24romankana -buttons "Start Myth
> TV:1" -center -default "Start Myth TV" MythTV
> mythfrontend -l /var/tmp/mythfrontend.log
>
> done
>
> This starts the mwm window manager, lirc programs,
> settings from my nvidia card, then the xmessage /
> mythfrontend loop.
>
> To shutdown the machine, just exit mythfrontend, then
> when the backend is idle, it will autoshutdown.

Sean,

I appreciate the feedback. Not quite what I'm looking for, though.

Right now I start up KDE, and then start myth frontend by pressing the
Power button on my remote, which lircd catches and then uses to start
Myth. I'm using the method described in the Tips 'n' Tricks section of
Jarod's guide.

What I'd like is for the frontend to start, without me having to press
any buttons on the remote, iff I started the Myth box manually. I know
it seems a bit lazy, but it makes sense to me that if I started the
box manually, the frontend should start.

Lane

--
Meetup with other Myth users!
http://mythtv.info/moin.cgi/MUG
RE: Autostart frontend ONLY on manual startup? [ In reply to ]
Lane wrote:

<snip>

> Right now I start up KDE, and then start myth frontend by
> pressing the Power button on my remote, which lircd catches
> and then uses to start Myth. I'm using the method described
> in the Tips 'n' Tricks section of Jarod's guide.
>
> What I'd like is for the frontend to start, without me having
> to press any buttons on the remote, iff I started the Myth
> box manually. I know it seems a bit lazy, but it makes sense
> to me that if I started the box manually, the frontend should start.

Like I said before, something that I'd be planning on doing for a bit
and was planning on doing this weekend, I had a rather quiet night at
work so inspired by the demand I had a bit of a scripting session. :-)

A little bit of sql and ksh[1] later and I have a beta that works and
is undergoing testing now...

Need to do a little bit more work to make it easier and to schedule restarts

for cron jobs and it'll be perfect.

Got to do some phoning round for my bike insurance now
(*mutter*grumble*money*grabbing*lazy*bunch*of*gits*ahem)
but should have something later today (well today for me anyway ;-) )

Regards

Druid

[1] Written on SINIX-Y[1] ksh at work then ported to bash at home ;-)
[2] Proper unix :-)
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
HI,

I think I understand what you want. Here is what I did:

I created a startup script which sets lockfile only if the sciript is
supplied with the argument "auto":
mythtv@mythtv mythtv $ cat /usr/local/bin/mythguictrl
#!/usr/bin/perl

use warnings;
use strict;

package main;

my $lockfile = '/var/run/mythtv/mythguilockfile';

my $who = $ARGV[0];

system "rm $lockfile" if -e $lockfile;

if($who eq "auto"){

system "echo 1 > $lockfile";
}

exit 1;

#---------------------------

Next, I created .xinitrc and .xsession files looking like this:
mythtv@mythtv mythtv $ cat .xinitrc
# Merge X resources from ~/.Xdefaults
[ -f $HOME/.Xdefaults ] && xrdb $HOME/.Xdefaults

# Set the background and root cursor shape
xsetroot -solid \#400040
xsetroot -cursor_name top_left_arrow

# Start evilwm - snap to borders within 10 pixels
/usr/bin/evilwm -snap 6 -bw 0 &

/usr/X11R6/bin/xset s noblank &
/usr/X11R6/bin/xset s off &
/usr/X11R6/bin/xset -dpms &
#/usr/bin/xsetbg /home/mythtv/.mythtv/silent-800x600.xpm
/usr/X11R6/bin/xsetroot -solid black

[ -f /var/run/mythtv/mythguilockfile ] || mythfrontend &



# sleep makes it so irxevent works
# uncomment these if you don't compile lirc into mythtv (set the lirc
USE variable to compile lirc support into mythtv)
sleep 3
irxevent &

# Transfer control to xclock - killing xclock (with Ctrl+Alt+Escape, say)
# will exit our session
exec xclock -digital -padding 2 -g -0+0
#----------------------------

So, the frontend is ONLY started when the lockfile does not exist.
Finally, I set the startup command (in mythsetup) to
/usr/local/bin/mythguictrl $status
I dont have X access to the box right now, so I cannot ell you exactly
what the section in mythsetup is, but it is 'startupCommand' in the
'settings' table of the database...
The wakeup command I use is
/usr/local/sbin/nvram-wakeup -A -C /etc/nvram-wakeup.conf -s
$(($time + 300 ))


/Fredrik
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
Fredrik Karlsson wrote:

>HI,
>
>I think I understand what you want. Here is what I did:
>
>I created a startup script which sets lockfile only if the sciript is
>supplied with the argument "auto":
>mythtv@mythtv mythtv $ cat /usr/local/bin/mythguictrl
>#!/usr/bin/perl
>
>use warnings;
>use strict;
>
>package main;
>
>my $lockfile = '/var/run/mythtv/mythguilockfile';
>
>my $who = $ARGV[0];
>
>system "rm $lockfile" if -e $lockfile;
>
>if($who eq "auto"){
>
> system "echo 1 > $lockfile";
>}
>
>exit 1;
>
>#---------------------------
>
>Next, I created .xinitrc and .xsession files looking like this:
>mythtv@mythtv mythtv $ cat .xinitrc
># Merge X resources from ~/.Xdefaults
>[ -f $HOME/.Xdefaults ] && xrdb $HOME/.Xdefaults
>
># Set the background and root cursor shape
>xsetroot -solid \#400040
>xsetroot -cursor_name top_left_arrow
>
># Start evilwm - snap to borders within 10 pixels
>/usr/bin/evilwm -snap 6 -bw 0 &
>
>/usr/X11R6/bin/xset s noblank &
>/usr/X11R6/bin/xset s off &
>/usr/X11R6/bin/xset -dpms &
>#/usr/bin/xsetbg /home/mythtv/.mythtv/silent-800x600.xpm
>/usr/X11R6/bin/xsetroot -solid black
>
>[ -f /var/run/mythtv/mythguilockfile ] || mythfrontend &
>
>
>
># sleep makes it so irxevent works
># uncomment these if you don't compile lirc into mythtv (set the lirc
>USE variable to compile lirc support into mythtv)
>sleep 3
>irxevent &
>
># Transfer control to xclock - killing xclock (with Ctrl+Alt+Escape, say)
># will exit our session
>exec xclock -digital -padding 2 -g -0+0
>#----------------------------
>
>So, the frontend is ONLY started when the lockfile does not exist.
>Finally, I set the startup command (in mythsetup) to
>/usr/local/bin/mythguictrl $status
>
>
I have a similar setup using a C++ program that I wrote called, of all
things, MythSplash. On an startup I have a small perl script (I think I
used perl, over a year now) that is called from mythbackend telling
whether or not the system was booted in automode. What the script does
is copies one of two .xinitrc files into the mythtv home directory. One
file starts mythfrontend on a manual start (no pending recordings), when
mythfronted is exited, it then calls mythsplash that gives a 'blue'
themed screen that says myth is shutting down, hit enter to restart, if
pressed mythfrontend restarts. In automatic mode the script calls
mythsplash but this time, mythsplash displays a message indicating that
mythtv is in auto mode hit enter key to start mythfrontend. Once
mythfrontend is shutdown mythsplash is displayed again. Indicating
Automode. There are a couple gotcha's. If you turn on mythtv say just
before a recording is due, it will start in automode, because it thinks
it's being started by nv-wake or something. The other is that the query
that being used internally in mythbackend to determine whether
mythbackend should be in automode doesn't handle previously recorded
programs or disabled programs. For example if you are on the 'upcoming
recordings' screen within mythfrontend, it will show the grayed out
shows (disabled or previously recorded) and actually scheduled
recordings, the grayed out shows seem to confused the the manual/auto
function in mythtv. If I turn on mythtv when one of these disabled
shows might have been recording, mythtv starts up in automode. Not a
big deal for most part, but sometimes when mythtv is awaken remotely
(via network) it starts in automode and sometimes shutdown before the
slave is fully booted to connect to the backend. Hopefully when I get
some time I'll be able to look at the code and submit a patch.
Hopefully... If anyone is interested in mythsplash let me know, I'll
clean it up a bit and perhaps make it theme-able.


Calvin....
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
mythtv-users@fastdruid.co.uk wrote:
> Lane wrote:
>
> <snip>
>
>>Right now I start up KDE, and then start myth frontend by
>>pressing the Power button on my remote, which lircd catches
>>and then uses to start Myth. I'm using the method described
>>in the Tips 'n' Tricks section of Jarod's guide.
>>
>>What I'd like is for the frontend to start, without me having
>>to press any buttons on the remote, iff I started the Myth
>>box manually. I know it seems a bit lazy, but it makes sense
>>to me that if I started the box manually, the frontend should start.
>

My nieces & nephews came over the house this past weekend & power cylced
my box multiple times (I was debating whether to remove the power header
from the motherboard that connects to my antec overture, but never got
around to it). They kept pressing all the buttons. Thankfully, I had
invested the time to get the autorestart working 100%.

I use KDE & implemented the /home/mythtv/.kde/Autostart/ ideology
effectively to automatically start mtd, mythbackend & mythfrontend at
system boot. Read on... I have a link to my myth docs/errata below
too. I tried to use the system V startup scripts & the BSD startup
script /etc/rc.local in vain. I run mythfrontend & mythbackend as user
mythtv.

I also improved on Jarod's guide's tips & tricks "Wife Button."

+----------------------------------------------------------------+
Hauppauge Grey Remote

POWER: stop/start in one fell swoop mythfrontend & mythbackend using
remote control that is linked to a user executable script. (works so
nicely when the GO button doesn't always work.)

GO: stop & separately start mythfrontend using remote control that is
linked to a user executable script
+----------------------------------------------------------------+

http://commwebworks.com/ski/mythtv.html#mythbackend_frontend_autostart

Regards,
-ski

>
> Like I said before, something that I'd be planning on doing for a bit
> and was planning on doing this weekend, I had a rather quiet night at
> work so inspired by the demand I had a bit of a scripting session. :-)
>
> A little bit of sql and ksh[1] later and I have a beta that works and
> is undergoing testing now...
>
> Need to do a little bit more work to make it easier and to schedule restarts
>
> for cron jobs and it'll be perfect.
>
> Got to do some phoning round for my bike insurance now
> (*mutter*grumble*money*grabbing*lazy*bunch*of*gits*ahem)
> but should have something later today (well today for me anyway ;-) )
>
> Regards
>
> Druid
>
> [1] Written on SINIX-Y[1] ksh at work then ported to bash at home ;-)
> [2] Proper unix :-)
>
>
>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mythtv-users mailing list
> mythtv-users@mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
> Has anyone figured out an elegant way to do the following:
>
> - Have Myth frontend start up automatically if and only if the machine
> was started manually
>
> Specifically, the frontend should autostart if I walk up to the
> computer and press the power button on the machine. The frontend
> should not start if nvram-wakeup set the BIOS start time and the
> machine started up by itself.
>
> I have a combo frontend/backend box. I use nvram-wakeup, so once I
> exit the frontend, the machine shuts down after 5 mins if it's not
> recording anything. It wakes itself up 5 mins before it needs to
> record the next show.
>
> Right now the frontend does not start automatically; I have to press
> the power button on my remote to start the frontend. This is so that
> the machine can start up automatically, record something, then shut
> down automatically.
>
> It would be nice to have the frontend start automatically when I
> manually start the box, but not start when the box autostarted.
>
> Any tips would be greatly appreciated!

Someone gave me their script which uses the following logic.

- Start mythfront/back ends every time the box boots up.
- At the same time as mythfrontend starts, start up irw in a script
which redirects its stdout to a log file and waits for 10 minutes
- When 10 minutes is up, check to see if the irw log file is empty.
- If its not empty exit the script and do nothing
- If it is empty then assume that there is nobody using mythtv
(otherwise they would have pressed at least 1 button on the remote),
kill mythfrontend and exit the script.
- Now that mythfrontend is shut down the machine can go into its
auto-shutdown routine whenever it's ready.

I can send you the script if you want it.

Regards,
Phill
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
On Sat, 5 Mar 2005 13:56:36 +1100, Phill Edwards <philledwards@gmail.com> wrote:
> Someone gave me their script which uses the following logic.
>
> - Start mythfront/back ends every time the box boots up.
> - At the same time as mythfrontend starts, start up irw in a script
> which redirects its stdout to a log file and waits for 10 minutes
> - When 10 minutes is up, check to see if the irw log file is empty.
> - If its not empty exit the script and do nothing
> - If it is empty then assume that there is nobody using mythtv
> (otherwise they would have pressed at least 1 button on the remote),
> kill mythfrontend and exit the script.
> - Now that mythfrontend is shut down the machine can go into its
> auto-shutdown routine whenever it's ready.
>
> I can send you the script if you want it.

Sure, that'd be great. Please post to the whole list for posterity. :)

Lane

--
Meetup with other Myth users!
http://mythtv.info/moin.cgi/MUG
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
Here it is:

#!/bin/bash
#
# remote_chk.sh
# This script checks whether any keys have been pressed on the remote control
# in the TIMEOUT seconds since mythfrontend was started (this script is started
# when mythfrontend is from .ratpoisonrc). If there has been any presses then
# the frontend is assumed to be in use and so we don't want to shutdown
# mythfrontend. If there haven't been any key presses then assume that it's not
# in use so we kill mythfrontend (which is auto started on system startup) so
# that the auto shutdown processing can then go ahead.


PROG=mythfrontend
TIMEOUT=600
LOGF=/var/log/mythtv/irw.log

irw > $LOGF &
sleep $TIMEOUT

IRLOG=`cat $LOGF | wc -l | awk '{print $1}'`
#UNK=`cat $LOGF | grep unknown | grep -v grep | wc -l | awk '{print $1}'`

#if [ $IRLOG -eq 0 ] || [ $IRLOG == $UNK ]

if [ $IRLOG -eq 0 ]
then
echo "remote_chk.sh killing mythfrontend at `date`" >> /tmp/mythrestart.log
killall $PROG
fi
exit 0
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
mythtv actually did exactly this around version 0.14 when I first
started to use it. I think this automatic behaviour was then removed
in 0.15 along with the shutdown check being a mandatory field (even if
you have nothing to check????).

Any one know if the funcationality was completely removed? or was is
reimplemented in different way? I have a feeling that instead of
having to bodge together some script to guess, that you can just query
mythbackend on whether it was started automatically or not.

On Mar 3, 2005 10:39 PM, Lane Schwartz <dowobeha@gmail.com> wrote:
> Has anyone figured out an elegant way to do the following:
>
> - Have Myth frontend start up automatically if and only if the machine
> was started manually
>
> Specifically, the frontend should autostart if I walk up to the
> computer and press the power button on the machine. The frontend
> should not start if nvram-wakeup set the BIOS start time and the
> machine started up by itself.
>
> I have a combo frontend/backend box. I use nvram-wakeup, so once I
> exit the frontend, the machine shuts down after 5 mins if it's not
> recording anything. It wakes itself up 5 mins before it needs to
> record the next show.
>
> Right now the frontend does not start automatically; I have to press
> the power button on my remote to start the frontend. This is so that
> the machine can start up automatically, record something, then shut
> down automatically.
>
> It would be nice to have the frontend start automatically when I
> manually start the box, but not start when the box autostarted.
>
> Any tips would be greatly appreciated!
>
> Cheers,
> Lane
>
> --
> Meetup with other Myth users!
> http://mythtv.info/moin.cgi/MUG
>
>
> _______________________________________________
> mythtv-users mailing list
> mythtv-users@mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
>
>
>
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
Re: Autostart frontend ONLY on manual startup? [ In reply to ]
On 6-Apr-05, at 8:03 AM, Ashley Bostock wrote:
> On Mar 3, 2005 10:39 PM, Lane Schwartz <dowobeha@gmail.com> wrote:
>> Has anyone figured out an elegant way to do the following:
>> - Have Myth frontend start up automatically if and only if the machine
>> was started manually
> Any one know if the funcationality was completely removed? or was is
> reimplemented in different way? I have a feeling that instead of
> having to bodge together some script to guess, that you can just query
> mythbackend on whether it was started automatically or not.

I'm less familiar with the pre 0.16 releases but in 0.17 the frontend
checks if you're using an idle timeout on the backend (ie, anything >
0) and if you are it connects to the backend right away to prevent it
shutting down. If the idle time is off (== 0) then it waits to connect
until it needs to

To accomplish what Lane wants I started with a script that checks the
current nvram/rtc wakeup time and if it's within the last 10 minutes I
assume an automatic wakeup, anything else I figure it's a manual
startup. This is signalled through the script's exit status. The other
piece is a script that alternately shows mythfrontend and a hacky
log-fed "myth is doing XXX press OK for myth" screen. When you come out
of one you go right into the other. The autostart status decides which
part of the loop comes up first.

I find this works well with the non-technical types I've built myth
boxes for like my sisters and friends. They know if they see the myth
menus then the machine will stay up until they're done and if they're
seeing the status screen then the box will decide on its own when it's
time to shut down. Oh, I'm using a 60 second idle timeout to make the
connection/shutdown logic work the way I need.

The other observation I have is I found it more reliable to use the rtc
for autostart status. When I was going to the backend I'd run into race
conditions where the frontend was up before the backend and sometimes I
would get the status wrong in hard to understand ways.

- George

P.S. Apologies if this shows up twice, my first send was from the
address not subscribed to the list.