View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 37 posts ] 
Go to page Previous  1, 2, 3  Next

Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject:
PostPosted: Sun May 04, 2008 12:50 am 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 320
Location: Melbourne, Australia
Marc,

I was definitely running the script from command line as user "mythtv". My initial attempts denied me permission to run shutdown as mythtv so I added /sbin/shutdown to the mythtv list in visudo and then I had success. (I should have mentioned that in my previous post.) I don't think it is a permissions problem anymore but I may be wrong.

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS version=latest


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 12:53 am 
Offline
Joined: Sat May 12, 2007 2:41 am
Posts: 51
Location: Southern Germany
I have the same problem nicom has.

My script looks like this:

Code:
#!/usr/bin/perl
#
# This script is invoked by mythshutdown to set the wakeup time.
# mythshutdown thinks it's calling nvram-wakeup, and it passes
# "--settime" and a single integer on the command line, which is the
# startup UTC time in seconds since the epoch. We convert it to the form
# understood by the system wakeup script.
#

#
# additionally, it will enforce a reboot if it is time to fsck the /myth
# partition. Thus a "normal" boot should never be interrupted by an fsck.
# To prevent mythwelcome from launching mythfrontend, we set the next scheduled
# wakeup time in mythshutdown to now + $XTIME minutes.

# Defintions:
$MOUNTPOINT = "myth";   # Name of mountpoint hosting the partition (here: /myth)
$XTIME = 17;            # time in minutes from now which we will tell mythshutdown to be the next wakeup time

# Step 1: Find the device name of the intended partition
$mythdevice = qx{ df| grep '$MOUNTPOINT\$' | cut -f 1 -d ' ' };

# Step 2: Find the number of reboots and boots until forced fsck
@temp = qx{tune2fs -l $mythdevice};
$numreboots = ((grep (/^Mount count:/,@temp))[0] =~ m/(\d+)/)[0];
$numrebootsfsck = ((grep (/^Maximum mount count:/,@temp))[0] =~ m/(\d+)/)[0];

# Step 3: Determine if next reboot will force an fsck
if ($numreboots - $numrebootsfsck >= 0)
{
  # on the next reboot, mythwelcome will ask mythshutdown --startup if this
  # was a manual or a scheduled boot. mythshutdown contains this comment:
  # // if we started within 15mins of the saved wakeup time assume we started
  # // automatically to record or for a daily wakeup/shutdown period
  # Note: it is actually +/- 15 minutes, according to the code.
  # so: Set a wakeuptime of now + $XTIME minutes. For $XTIME = 15 we have
  # about 30 minutes time for an fsck. This *should* be enough...
  # print "next boot will be a forced fsck!\n";
  ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  localtime (time() + ($XTIME * 60));
  $year += 1900;
  $mon += 1;
  $wakeup_time = sprintf "%4.4u-%2.2u-%2.2uT%2.2u:%2.2u:%2.2u", $year,
  $mon, $mday, $hour, $min, $sec;
  `mythshutdown --setwakeup $wakeup_time`;
  `echo mythshutdown --setwakeup $wakeup_time >/home/mythtv/myerrlog.txt`;
 
  # HACK: We reboot the system from here. It would probably be better if
  # mythwelcome did that. Have no idea how, though.
  exec ("reboot");
}
else
{
  # set alarm time of acpi to the time we get from the commandline. Convert from
  # local time to GMT, because this is what the BIOS expects
  ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  gmtime ($ARGV[1]);
  $year += 1900;
  $mon += 1;
  $wakeup_time = sprintf "%4.4u-%2.2u-%2.2u %2.2u:%2.2u:%2.2u", $year,
  $mon, $mday, $hour, $min, $sec;
  `echo "$wakeup_time" >/proc/acpi/alarm`;
}



When run from the commandline as user mythtv it reboots, when run from mythwelcome it runs all the way through (verified with print to file), but does not reboot. I think this script runs as root when called from mythwelcome.

I suspect that the reboot command is cancelled by a subsequent shutdown command from mythwelcome.

The other problem is that after a reboot mythwelcome always starts mythfrontend. And all the tricks I tried in the above code do not prevent that. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 4:18 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
nicom: cron has a limited path. You might have to call shutdown with /usr/bin/shutdown as it may not be in the default path. Alternatively, you can change the default path (man 5 crontab), but it is probably better to call it explicitly.

heilig: Nice addition with the mythshutdown --setwakeup. I have had a couple of times where the fsck didn't finish in time and it didn't shut down again. I'll be adding this to my script.

Allen

_________________
ASUS AT3N7A-I (Atom 330)
TBS 8922 PCI (DVB-S2)


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 9:32 am 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
alien wrote:
nicom: cron has a limited path


A general bit of Unix wisdom... ANY time you are writing a script to be run remotely, by cron, in the background, ... you need to remember not to depend on having the same setup as in an ordinary interactive session.

    1) You should either set and export your own PATH at the start of the script or use full paths for all the commands that aren't shell built-ins.
    2) You should make sure that when the script itself is invoked it is invoked using the full path.
    3) You should redirect your output to a logfile using exec so you can tell why it has problems. A common debugging trick is to put calls to env and set -vx right after that so you can tell what settings you _do_ have and trace what it's doing. (You can comment these out once it's working.)


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 10:00 am 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
nicom wrote:
I was definitely running the script from command line as user "mythtv". My initial attempts denied me permission to run shutdown as mythtv so I added /sbin/shutdown to the mythtv list in visudo and then I had success. (I should have mentioned that in my previous post.) I don't think it is a permissions problem anymore but I may be wrong.


alien wrote:
nicom: cron has a limited path. You might have to call shutdown with /usr/bin/shutdown as it may not be in the default path. Alternatively, you can change the default path (man 5 crontab), but it is probably better to call it explicitly.


Alien's comment about cronjobs is correct, but I don't think you're running this from cron. Based on one of your previous posts, it sounds like you are running this from mythwelcome. Having said this, it could still be a path issue. Trying changing the "shutdown -r now" to "/sbin/shutdown -r now". A bit more info:

1. I found shutdown in in "/sbin", not "/usr/bin" in my R5F27 install.

2. You can verify where shutdown is for you by logging in as root and typing "which shutdown".

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 4:13 pm 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 320
Location: Melbourne, Australia
The script I am running this the setwakeup.sh script from Mythwelcome which sets the next wakeup time for the machine based on the recording schedule. As I understand it, it is invoked when mythwelcome shuts down when idle. I added Marc's code to trigger a reboot to this file because I thought it would be executed at the right time. It is not a cron job.

This morning I tried adding the path to the script "/sbin/shutdown -r now" but again the machine did not reboot. Mount count was well above max. I am fairly sure shutdown is in /sbin because that's where Mythwelcome has it listed in setup. I am not at my machine now so I cannot check.

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS version=latest


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 4:47 pm 
Offline
Joined: Sat May 12, 2007 2:41 am
Posts: 51
Location: Southern Germany
What happens if shutdown -r now is called, and a few moments later shutdown -h now is called? Will the second command override the first? I suppose this is what happens. Try adding a sleep command after your sudo /sbin/shutdown -r now.

Just tested this in my script above, and now it reboots! Yay!

Now on to my second problem: Stay in mythwelcome after the reboot.


Last edited by heilig on Sun May 04, 2008 4:54 pm, edited 1 time in total.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 4:53 pm 
Offline
Joined: Sat May 12, 2007 2:41 am
Posts: 51
Location: Southern Germany
Problem 2: Now that rebooting the system in case of a forced fsck works, I want it to stay in mythwelcome and not start mythfrontend (not starting mythfrontend automatically is not an option, since we usually switch the box on, walk away, and come back a few minutes later. It would shut down again if we stayed in mythwelcome)

As you can see in my script above, I call mythshutdown -w (time in 15 minutes). Unfortunately, this does not what I expected it to. The reason seems to be that the above command sets the "MythShutdownNextSchedule" time, and not "MythShutdownWakeupTime" in the settings table in mythconverg. I guess the latter is used by mythshutdown --startup.

Any hints how we can set the "MythShutdownWakeupTime" to the desired value? I think this is the last blocking stone for a working solution.

jens


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 5:32 pm 
Offline
Joined: Sat May 12, 2007 2:41 am
Posts: 51
Location: Southern Germany
I can report a partial success: Replacing the "mythshutdown" line in my above script with:


Code:
  ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  localtime (time() + ($XTIME * 60));
  $year += 1900;
  $mon += 1;
  $wakeup_time = sprintf "%4.4u-%2.2u-%2.2uT%2.2u:%2.2u:%2.2u", $year,
  $mon, $mday, $hour, $min, $secs;
#  `mythshutdown --setwakeup $wakeup_time`;
  `mysql -u mythtv --password=mythtv mythconverg <<EOF
  update settings set data="$wakeup_time" where value="MythShutdownWakeupTime";
  EOF`;



brings up mythwelcome after a reboot!

BUT:
1) only if the wakeup time is really *BEFORE* the current time
2) mythwelcome will not shut down after the idle period. It just sits there reporting "MythTV is idle".

Maybe these bits of information will help somebody find a working solution. I will not be able to add much in the next few days. Work starts in 5 hours and I need to get some sleep...

jens


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 6:11 pm 
Offline
Joined: Wed Apr 28, 2004 10:42 pm
Posts: 405
Location: Bendigo, Victoria, Australia
heilig wrote:
Problem 2: Now that rebooting the system in case of a forced fsck works, I want it to stay in mythwelcome and not start mythfrontend (not starting mythfrontend automatically is not an option, since we usually switch the box on, walk away, and come back a few minutes later. It would shut down again if we stayed in mythwelcome)

On my system if I manually start the machine it will just sit at Mythwelcome and wait forever until someone enters and exits the frontend. It somehow recognizes that the machine wasn't automatically woken up.

_________________
Paul Turpie
-------------
<--Is your location in your profile? Why not?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 1:47 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
To help see what is going on, you can use "mythshutdown --status --verbose 1" (I'm going from memory, check the mythshutdown --help if that doesn't work). This will print out a lot of info about why a shutdown is or isn't blocked.

I'll try and see if I can the setwakeup working with a Daily Wakeup to increase the window a fsck has to complete.

_________________
ASUS AT3N7A-I (Atom 330)
TBS 8922 PCI (DVB-S2)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 3:50 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
turpie/heilig: This may be a dumb question, but have you both unchecked "wait for frontend to connect" in the mythtv setup?

I have managed to get the box to reboot without starting the frontend and after idle timeout shutdown with the following code:
Code:
#!/usr/bin/perl

$wakeup=`date '+%Y-%m-%dT%H:%M:%S' -d '+ 15 minutes'`;
system("/usr/bin/mysql -u root mythconverg -e \"update settings set data ='$wakeup' where value='MythShutdownWakeupTime'\"");
system("/sbin/reboot");
exit;


I've just added it into my cron job and I will see if it works tomorrow morning.

Note: I peeked at the code and MythShutdownWakeupTime is only set when mythshutdown --shutdown is called. However, since mythshutdown --shutdown won't shutdown when we are within 15mins of a wakeup, this can't be used to set MythShutdownWakeupTime in our case.

_________________
ASUS AT3N7A-I (Atom 330)
TBS 8922 PCI (DVB-S2)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 4:57 am 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 320
Location: Melbourne, Australia
Jens,

Your suggestion of adding sleep to the script worked. I have "sleep 20" after the shutdown command (5 seconds did not seem to be enough). Thanks for the tip.

Unfortunately my reboot also gets me back to the Mythtv menu not Mythwelcome. I will watch the forum with interest.

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS version=latest


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 5:51 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
If you are doing this in the mythshutdown scripts, I think you might have more luck modifying the "Command to shutdown" instead of "Command to Set Wakeup Time". Otherwise, the box is shutdown before mythshutdown is finished. The sequence of events is:
Code:
Mythbackend
   |
   +--> mythshutdown --setwakeup
   |           |
   |           +---> "Command to Set Wakeup Time"
   |
   |
   +--> mythshutdown --shutdown
               |
               +---> Sets MythShutdownWakeupTime
               |         (Used on wakeup to determine manual/auto wake)
               |
               +---> "Command to shutdown"
From a high level, the code would be:
Code:
IF <need to fsck> THEN
     $wakeup=`date '+%Y-%m-%dT%H:%M:%S' -d '+ 15 minutes'`
     /usr/bin/mysql -u root mythconverg -e "update settings set data ='$wakeup' where value='MythShutdownWakeupTime'"
     /sbin/reboot
ELSE
     /sbin/poweroff
ENDIF

Note: You will need to replace the IF/THEN/ELSE/ENDIF with the appropriate commands for whatever scripting language you are using.

_________________
ASUS AT3N7A-I (Atom 330)
TBS 8922 PCI (DVB-S2)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 9:50 am 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
nicom wrote:
Jens,
Your suggestion of adding sleep to the script worked. I have "sleep 20" after the shutdown command (5 seconds did not seem to be enough). Thanks for the tip.

Unfortunately my reboot also gets me back to the Mythtv menu not Mythwelcome. I will watch the forum with interest.


alien wrote:
If you are doing this in the mythshutdown scripts, I think you might have more luck modifying the "Command to shutdown" instead of "Command to Set Wakeup Time". Otherwise, the box is shutdown before mythshutdown is finished.


Alien is correct -- the "shutdown -r now" should be done in the shutdown script, not the setwakeup script. I'm not sure how the system decides weather to run "mythwelcome" or the myth front end at reboot, as I don't use mythwelcome. Perhaps someone else can shed some light on this.

Marc


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ] 
Go to page Previous  1, 2, 3  Next



All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu