![]() |
downloads | documentation | HowTo | reporting bugs | links | Recent Changes |
What is a Wiki?See WikiWikiWeb If you don't know how to use a wiki see the WikiHowto ErfurtWiki is maintained by a loosely knit group of developers. Quick LinksRelated sitesContactPlease submit website bugs in the BugReports Contribute!Please file any wishes on UserSuggestions. Hosted By |
WARNING: This page was written pre-R5.5.It still contains interesting information,but if you just want to set it up,follow the steps in MythWelcomewiki page.How to set up a Knoppmyth box to automatically boot when it needs to record a show.Before you try this, you probably want to try using acpi to wake up your system http://www.mythtv.org/wiki/index.php/ACPI_Wakeup and mythwelcome to manage setting the time http://www.knoppmythwiki.org/index.php?page=WakeupToRecordWithMythWelcome. They are much easier to use. If either of those don't work on your system, you might want to try this. Note: This has been tested on R5 Alpha, but it is also reported to work on R4V5, though possibly with problems with regard to commercial detection. Note2: For some reason, the mythfrontend in R5 versions with 0.17 does not always respond to killall. If you have this problem, try changing the kill command to killall -TERM. The scripts below have been changed accordingly (note, this should also work with 0.16). Note3: MythTV 0.19 includes a new feature called MythWelcome. This is easier to configure and shows a user friendly interface when the frontend is not active so that you can see the status of the backend and easily start the frontend. There is an edited version of this wiki for configuring with MythWelcome at http://www.knoppmythwiki.org/index.php?page=WakeupToRecordWithMythWelcome Why it isn't as easy as one would think:Note: If you just want to set it up, skip down to "How To Do It". I don't recommend that though as it helps to understand what is going on. Problem Number 1:Known as the reboot problem #1 in the nvram-wakeup man pages. It is simply not enough to write the new time into nvram on some (most) mother boards. It is often necessary to re-run the bios for it to take the time in nvram and really set the alarm. The way around this is to set the wakeuptime, reboot into a kernel set up to shut down right away. This is only necessary if the MB requires it or if the wakeup time has changed. Nvram-wakeup (once set up) takes care of this decision. Problem Number 2:Known as the reboot problem #2 in the nvram-wakeup man pages. Luckily, this isn't as common, but if you have it, the wakeup will not work if shutdown by knoppmyth's acpi, so you need to always reboot and shutdown with apm. Problem Number 3:If a normal shutdown -h is done, knoppmythbackend does not set the wakeup time. To fix this, you need to shutdown the frontend and set up the backend to shutdown when nothing is attached to it. This is how you must always shut down the computer for the wakeup to work. Problem Number 4:When the box wakes up to record, it will never shut down. A script below is used to shutdown the frontend during an automatic wakeup to allow the backend to shut down normally. Problem Number 5:Most mother boards only allow the day/hour/minute/second to be set as a wakeup. Wakeups can not be longer than 1 month. Some mother boards (like mine), only allow the hour/minute/second to be set. The wakeup must be less than one day. The script below handles this by preventing a wakeup greater than the maximum allowed to be set. The side affect is that if you have a max wakeup of 1 day and want to record a program in 3 days, the computer will wakeup each day to re-set the wakeup. (Note: It turns out that if there is nothing to record, mythbackend assumes that it was started by "user" and will not shut down. Right now, I schedule something to record once a day to get around this. When I get a chance, I'll update the scripts to be a little more smart) (maybe write a parameter to a file at shutdown, check it at wakeup and adjust accordingly. IOW, make our own $status variable for the wake-up script and save it out somewhere before shutdown and include it in the wake-up script. ) How It Works(basic steps of what myth does when using WakeToRecord?) 1. When mythbackend determines it is "idle" (no frontends attached) it checks the idle timeout value from mythtv-setup. After that time has passed, if its still idle, move on to step 2. 2. Calls "preshutdown command" and waits for the return value. An exit 0 means go ahead with shutdown (go to step 3), an exit 1 means restart the idle timeout (back to step 1). I don't remember what exit 2 means, but it really doesn't apply to what we are doing here anyway. ;) 3. Calls "set wakeup time command" which should write the startup time to nvram (or to the net resource for wake-on-lan, covered elsewhere). 4. Calls "halt command." and down she goes. 5 (or 0). Upon startup, executes the "Startup command" which in our case determines whether we need the frontend running or not. Note: I figured this out by watching about 3 different log tails on a remote machine during multiple reboots. This may not be what myth ACTUALLY does, but is close enough for our purposes. please fix it if it needs it. --andrewsw How To Do It1. apt-get install nvram-wakeup 2. Run nvram-wakeup with no parameters and see if your motherboard is supported. If it isn't (mine wasn't), look at the man pages (or just start guess-helper)... there's still hope. I recommend taking a look at the man pages anyway. HEED ALL THE WARNINGS! 2a. Add the following lines to lilo.conf (don't forget to run lilo after):
image=/boot/vmlinuz-2.6.9-3
label=PowerOff
read-only
append="0"
2b. More work than 2a, but reboot happens faster. Download the reboot package from http://sourceforge.net/projects/nvram-wakeup/ and put bzImage.2.4.20.poweroff in /boot. Add the following lines to lilo.conf (don't forget to run lilo after):
image=/boot/bzImage.2.4.20.poweroff
label=PowerOff
append="apm=off"
3. Give the mythtv user access to lilo and nvram-wakeup. Change the mythtv entry in /etc/sudoers to (as root: visudo /etc/sudoers): mythtv ALL=NOPASSWD:/sbin/halt,/sbin/reboot,/bin/mount,/bin/umount,/usr/local/b in/mythbackup,/usr/local/bin/mythrestore,/usr/sbin/nvram-wakeup,/sbin/lilo 4. Put the four scripts below somewhere and make them executable (if they are not in the regular path, remember where they are as you will have to put an explicit path into mythtv-setup. 5. Edit the top sections of the four scripts and set any variables as appropriate (there are comments to help). 5.a. as root do the following: touch /var/log/mythtv/mythevent.date touch /var/log/mythtv/mythpreshutdown.log chmod 777 /var/log/mythtv/mythevent.date chmod 777 /var/log/mythtv/mythpreshutdown.log Note that you might want to add mythpreshutdown.log to your logrotate stuff, or you can edit the echo portions of knoppmyth-preshutdown.sh once you've confirmed it all works. Personally, I like log files... 6. I recommend you test things at this point as user mythtv:
7. Run mythtv-setup. Go to general and set:
Note: at least one person has had problems with this sytem, resulting in endless reboots. You may wish to set the idle timeout to a higher number until you know everything is working, to give time to get into the machine and fix problems. If something goes wrong (ex. "block shutdown..." not checked) and you end up in a reboot loop that you can't break, you can do the following (commands are not 100% exact as I am not at my box right now to try):
Note: the knoppmyth-preshutdown.sh script will be called every "idle timeout" seconds. 10 seconds is probably unneccessary thrashing and should be increased to 60 seconds or whatever you think is appropriate. The shorter the idle time, the more often the script is called, but the quicker the machine will shutdown after going idle. Take your pick. 8. Now it should work. Note that for the time to be set correctly, you must always shut down the computer by exiting the frontend and letting the backend complete the shutdown. knoppmyth-nvram-set-time.pl:
#!/usr/bin/perl
# This script is for mythtv to set the nvram wakeup time. See
# man nvram-wakeup for more information.
# This is the command to set the wakeup time. If you have custom parameters,
# put them here. Be careful as this writes to ROM!
$nvram_cmd = "sudo nvram-wakeup";
# Some motherboards do not have a day in the wakeup time, therefore, the
# max number of days that the wakeup can be in the future is 1 day. Most
# do not have a month. In that case set this to 28.
# Note, the backend won't shutdown on a wakeup at max_wakeup_wakeup_days
# because it has nothing to record and assumes a "user" start. Right
# now I just have something recorded regularly each day. I'll post a
# fix for this when I have it.
$max_wakeup_days = 1;
# If you want a regular wakeup for cron jobs etc. Set to 0 to disable.
# Note 1: Do not use a time between 23:45 and 00:15 as there are some
# race conditions around midnight.
# Note 2: If you use $regular_wakeup_time_text to start up to handle a
# cron job, that cron job must shut the system down by killing the front
# end when it is done. That way, the next wakeup time gets set.
# Note 3: nvram wakeup sets the wakeup for 5 minutes before the actual
# request to give the computer time to boot. However, if the computer
# does a diskscan on a large disk, it may take longer than this and you
# miss the cron window. I set $regular_wakeup_time_text to be 10 mins
# before my cron job runs.
# Examples:
# For daily at 1am:
# $regular_wakeup_days = 1;
# $regular_wakeup_time_text = "01:00";
# For weekly, on Sunday at 1am:
# $regular_wakeup_days = 7;
# $regular_wakeup_time_text = "Sun 01:00";
$regular_wakeup_days = 0;
$regular_wakeup_time_text = "18:00";
# Now the real work...
$requested_wakeup_time = @ARGV[0];
$now_time = `date +%s`;
$max_wakeup_time = $now_time + $max_wakeup_days * 24 * 60 * 60;
$min_wakeup_time = $now_time + 10 * 60;
if ($requested_wakeup_time) {
if ($requested_wakeup_time < $min_wakeup_time) {
$requested_wakeup_time = $min_wakeup_time;
}
}
if ($regular_wakeup_days) {
$regular_wakeup_time = `date +%s -d "$regular_wakeup_time_text"`;
if ($regular_wakeup_time < $now_time) {
$regular_wakeup_time = $regular_wakeup_time + ($regular_wakeup_days * 24 * 60 * 60);
}
if ($regular_wakeup_time > $min_wakeup_time) {
if ($regular_wakeup_time < $requested_wakeup_time) {
$requested_wakeup_time = $regular_wakeup_time;
}
if (!$requested_wakeup_time) {
$requested_wakeup_time = $regular_wakeup_time;
}
}
}
if ($max_wakeup_time < $requested_wakeup_time) {
$requested_wakeup_time = $max_wakeup_time;
}
# write the requested_wakeup_time to nvram
system("$nvram_cmd -s $requested_wakeup_time");
# paranoia
sleep 10;
knoppmyth-wakeuptest.pl:
#!/usr/bin/perl
# This script can be called when the mythtv backend starts to
# determine whether the frontend should be shutdown.
#
# If this boot was an automatic wakeup because there is something
# to record, the frontend is shutdown to allow the backend to
# shutdown the computer when it is done recording.
#
# Imporant: In mythtv-setup, this script should be set up to
# be called in the background (with a trailing &) because of the
# sleep.
$kill_frontend = "killall mythfrontend";
$sleep_time = 30;
# Now the work starts...
if (@ARGV[0] eq "auto") {
sleep $sleep_time;
system "$kill_frontend";
}
knoppmyth-shutdown.pl:
#!/usr/bin/perl
# this script either issues a reboot into the PowerOff image
# - or -
# just halts the system.
# adjust as required for your system.
# This is the command when a reboot is required
# comment out this line and uncomment below for a regular halt.
$shutdown_cmd = "sudo lilo -R PowerOff ; sudo reboot";
# This is the command when a reboot is not required, only a halt
# uncomment this line and comment out above for a regular halt.
#$shutdown_cmd = "sudo halt";
system("$shutdown_cmd");
#so long and thanks for all the fish
knoppmyth-preshutdown.sh:
#!/bin/sh
# get some pretty date stuff
# and set the exit state to default 0, or force shutdown
mdy="`date +%Y-%m-%d`"
hm1="`date +%T`"
hm2="`date +%N | cut --bytes='1 2 3'`"
hms="$hm1.$hm2"
exstate=0
echo "$mdy $hms Preshutdown" >> /var/log/mythtv/mythpreshutdown.log
# Check for transcoding
ps_transcode=`ps cax | grep -c mythtranscode`
if [ $ps_transcode != 0 ]; then
echo "$mdy $hms Transcoding in progress..." >> /var/log/mythtv/mythpreshutdown.log
exstate=1
fi
# Check for filldatebase
ps_filldatabase=`ps cax | grep -c mythfilldatabas`
if [ $ps_filldatabase != 0 ]; then
echo "$mdy $hms Filling the database in progress..." >> /var/log/mythtv/mythpreshutdown.log
exstate=1
fi
# Check for Commercial Flagging
ps_commflag=`ps cax | grep -c mythcommflag`
if [ $ps_commflag != 0 ]; then
echo "$mdy $hms Commercial Flagging in progress..." >> /var/log/mythtv/mythpreshutdown.log
exstate=1
fi
# Check for DVD Burning
ps_dvdburn=`ps cax | grep -c mythtvburn.sh`
if [ $ps_dvdburn != 0 ]; then
echo "$mdy $hms DVD Burning in progress..." >> /var/log/mythtv/mythpreshutdown.log
exstate=1
fi
# Stuff that only needs to be ran once a day.
DATERUN=`cat /var/log/mythtv/mythevent.date`
DATE=`date +%m-%d-%Y`
if [ "$DATE" != "$DATERUN" ]; then
echo "Running once a day routines" >> /var/log/mythtv/mythpreshutdown.log
# Fill database before shutting down
echo "$mdy $hms Updating database for $DATE." >> /var/log/mythtv/mythpreshutdown.log
mythfilldatabase --refresh-today > /dev/null 2>&1
echo "$mdy $hms Updating database for 14 days worth of data." >> /var/log/mythtv/mythpreshutdown.log
mythfilldatabase > /dev/null 2>&1
echo "$DATE" > /var/log/mythtv/mythevent.date
# Rotate the Log Files
echo "$mdy $hms Rotate Log Files" >> /var/log/mythtv/mythpreshutdown.log
logrotate -fv /etc/logrotate.conf > /dev/null 2>&1
exstate=1
fi
if [ $exstate = 0 ]; then
echo "$mdy $hms Preshutdown authorized" >> /var/log/mythtv/mythpreshutdown.log
fi
exit $exstate
# End of /usr/bin/mythpreshutdown
Obvious Question of the Day:Hey, why is this a mix of Perl and bash? Well, pilgrim, I'm essentially lazy. The original version of this wiki was done using Perl by Allen (the frog below). The changes I made were based on this (whoever you are, you are now officially acknowledged and thanked!) which is all bash. A little copy/paste and a little typing and you get this monster. You are free to fix this horrible inconsistency. --andrewsw
--Allen heavily updated October 28, 2005 by andrewsw. Note:When you get the message "nvram-wakeup: ioctl RTC_ALM_READ?: Invalid argument" take a look at http://www.vdr-portal.de/board/thread.php?goto=nextoldest&threadid=31278&sid=d1c62f94409593ebc81dc1e4b5001d82 (german) Unload your genrtc module and rename/delete it. After that take a copy of rtc.ko to genrtc.ko and test your configuration with "nvram-wakeup --debug". In my case the message was gone and I saw my BIOS wake-up time. EditThisPage BackLinks PageInfo Pages like this Attachments RSS/Atom last changed on Wed Sep 17 02:59:58 2008 |
UpdatedPages· WakeOnLANRouter last changed on Sun Feb 7 05:04:09 2010· KnoppMythWiki last changed on Sat Feb 6 14:22:21 2010 · KnoppMythInstall last changed on Tue Feb 2 04:58:54 2010 · StaticIPConfig last changed on Sun Jan 24 11:02:40 2010 · LinuxTips last changed on Tue Jan 12 05:11:08 2010 · TroubleShooting last changed on Tue Jan 12 05:09:39 2010 · HowTo last changed on Tue Jan 12 05:05:53 2010 · RarFiles last changed on Sun Jan 10 06:13:35 2010 · TinnyAudioPVR150 last changed on Thu Jan 7 19:21:53 2010 · MediaMVP_LinuxHOWTO last changed on Mon Jan 4 07:23:41 2010 · StorageGroups last changed on Mon Dec 14 18:38:15 2009 · SandBox last changed on Mon Nov 30 10:04:30 2009 · NZMythConfig last changed on Fri Nov 27 01:32:05 2009 · webminhowto last changed on Wed Nov 25 16:02:59 2009 · UpgradeHowTo last changed on Tue Nov 24 00:09:52 2009 · MythVodkaHuluFixR6 last changed on Mon Nov 23 18:09:38 2009 · Change Channels with Serial Cable last changed on Sat Nov 21 06:22:23 2009 · x11vncHowTo last changed on Wed Nov 18 09:15:23 2009 · GeForce4 last changed on Sun Nov 15 06:13:50 2009 · WhatCardYouUse last changed on Thu Nov 12 22:54:17 2009 · tv_grab_au last changed on Wed Nov 11 16:58:37 2009 · kworld115HowTo last changed on Sat Nov 7 18:18:53 2009 · AutomatedBackup last changed on Mon Oct 12 11:01:34 2009 · MythBackupAndRestoreHowTo last changed on Mon Oct 12 09:59:40 2009 · HardwareAcceleratedVideo last changed on Mon Oct 5 23:03:26 2009 · RepairingMythConvergDB last changed on Thu Oct 1 18:51:12 2009 |
| sitemap | | |