View unanswered posts    View active topics

All times are UTC - 6 hours





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

Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: ACPI Wake and fsck
PostPosted: Sun Apr 27, 2008 5:14 pm 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 314
Location: Melbourne, Australia
I have my machine sleeping most of the time and only waking by ACPI to record or when I switch it on to watch. One problem I have is that every 26 boots it wants to run fsck which for my 500 GB disk can take up to 15 mins. If it is waking to record it can then miss the start; if I want to watch I have to wait. I know I could fix the first problem by waking earlier before the time, but the second problem is painful. I currently have /etc/fstab modified to prevent checks but have my doubts about this long term.

Does anyone have a suggestion on what to do?
Is it important to run fsck regularly?
Does someone with more scripting skills than I (not hard) have a script that would cause a reboot with fsck when shutting down after the 25th boot?

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS R8.5.2


Top
 Profile  
 
 Post subject: Re: ACPI Wake and fsck
PostPosted: Sun Apr 27, 2008 7:40 pm 
Offline
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location: Farmington, MI USA
nicom wrote:
Is it important to run fsck regularly?
Yes. Read the man pages for tune2fs, specifically regarding the -c and -i options, for some of the reasons why.

nicom wrote:
Does someone with more scripting skills than I (not hard) have a script that would cause a reboot with fsck when shutting down after the 25th boot?
Why not just run it on every shutdown? Or every shutdown on a given day of the week? Or...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 10:14 pm 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 314
Location: Melbourne, Australia
Thanks for the advice. You confirmed my suspicions.

I also found another thread http://mysettopbox.tv/phpBB2/viewtopic.php?t=18185&start=15 where this was briefly discussed but not with any firm direction on how to do it.

Your suggestion of running fsck on shutdown once per week sounds perfect but how do I do it? As far I can work out all I can do is force a reboot with forced fsck [shutdown -rF], but this will start the machine in the in the Mythtv menu, not MythWelcome so the machine will not shutdown.

I suppose I could do the following:
1. set a manual record for say 0500 each Friday for 2 mins, the machine will start at 0455.
2. set a cron job to /forcefsck at 0458
3. The machine will shutdown when when recording is complete + aftertime (5 mins)
4. Set a manual record for 0510 for 10 mins (or enough to allow for fsck to complete)

I might try the above when I get a chance. In the meantime, does anyone have a simpler method?

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS R8.5.2


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 12:43 am 
Offline
Joined: Sat May 12, 2007 2:41 am
Posts: 49
Location: Southern Germany
Same problem here. I have not found a solution, but have thought about using the following:

mythwelcome calls a script when shutting down, IIRC (mythshutdown? I'm not near my box at the moment). This script could check the number of restarts until a forced fsck. If this number is 1, it could either:
1) set an earlier wakeup time, which would cover the problem of missed recordings
2) Set the wakeuptime to the next few minutes and force a restart with fsck

Solution 2 would have the advantage that an fsck will not happen when you switch on to watch a recording.
Setting the wakeup time to the next few minutes should start mythwelcome and not mythfrontend after the reboot, which would the shut the machine down again.

Problem is: How can we get the number of restarts since last or until next forced fsck? I read man fstune, but have not found a clear hint (and could not experiment yet, don't have a Linux box nearby).

I'm very willing to help here, if I can! This problem bites me every 3 weeks or so, and I'd really like to solve it.

jens


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 2:04 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
I do this with mythwelcome:

I have a daily wakeup period 9am-10am.

A cron job runs at 9am each day to do backups, etc.

The last thing the cron job does is check the day of the month. If it is the 1st, it sets the mountcount to 100 and does a reboot. It comes back up before 10am, so mythwelcome shuts it all down normally.

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 2:31 am 
Offline
Joined: Sat May 12, 2007 2:41 am
Posts: 49
Location: Southern Germany
some more info: It is possible to find the number of reboots until a forced check occurs with

Code:
tune2fs -l /dev/sda3 | grep -i 'mount count'


(where /dev/sda3 is my /myth partition). In my case, this yields
Mount count: 2
Maximum mount count: 29


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 5:01 pm 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 314
Location: Melbourne, Australia
Viele danke heilig and alien.

heilig,
I had originally thought about watching the mount count until it is close to max the force a reboot but did not have a clue how to do it. The code you provided will be very useful and over the weekend I plan to try it. I was thinking I would only grab the counts individually, pipe them to sed to edit out the labels then create variables.

This is going to push my non-existent scripting skills to the limit.

alien,
Your method looks much simpler.
Do you set the daily wakeup period by setting a manual record, or is there some other way?
Can it be extended to weekly?
Could you post the cron_tab file (or the script file if it calls one)?

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS R8.5.2


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 5:57 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1530
Location: California
Is anyone else running into the problem I described over here? I used tune2fs to prevent fsck's. I then decided to allow fsck's again, but they won't seem to run anymore...

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 8:36 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1530
Location: California
nicom wrote:
This is going to push my non-existent scripting skills to the limit.


Here you go
Code:
#! /bin/bash
cur_count=$(tune2fs -l /dev/hda1 | grep "Mount count:" | awk ' { print $3 } ' )
max_count=$(tune2fs -l /dev/hda1 | grep "Maximum mount count:" | \
            awk ' { print $4 } ' )
echo $cur_count $max_count
if [ $cur_count -ge $max_count ]; then
  echo It is time to check the volume.
fi

Perhaps the simplest thing to do is to do a "shutdown -r" when the condition is true. I believe this will then trigger the following sequence of events:

1. System will reboot.
2. During reboot, fsck will be run and the mount count will be reset to 0.
3. mythtv will start up.
4. After a few minutes myth will detect that it is idle and trigger a shutdown.
5. This time, when your script is run, the mount count will be less than the max-mount-count, so instead of rebooting, your system will simply shut down.

I have tested the script, but I have not verified that steps 1->5 will work exactly as I have described, so you'll need to test it. I am using a different approach. In my case, all of my large volumes are XFS, which doesn't seem to require the periodic fsck. Since the only ext3 volume I have is the root partition, running the fsck at startup time is quick, so it's not a problem.

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 9:01 pm 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 314
Location: Melbourne, Australia
Marc,

Wow. Thanks a lot. I will try it over the weekend.

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS R8.5.2


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 9:02 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
marc.aronson wrote:
Code:
cur_count=$(tune2fs -l /dev/hda1 | grep "Mount count:" | awk ' { print $3 } ' )
max_count=$(tune2fs -l /dev/hda1 | grep "Maximum mount count:" | \
            awk ' { print $4 } ' )

grep|awk always makes me shake my head a little, since awk will do that for free.
Code:
cur_count=$(tune2fs -l /dev/hda1 | awk '/Mount count:/ { print $3 }')
max_count=$(tune2fs -l /dev/hda1 | awk '/Maximum mount count:/ { print $4 }')

This would matter more in an inner loop, but it's still nice to simplify.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 9:19 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1530
Location: California
nicom wrote:
Marc,
Wow. Thanks a lot. I will try it over the weekend.

You're welcome

tjc wrote:
grep|awk always makes me shake my head a little, since awk will do that for free.

Yeah -- I always forget to use awk's pattern matching capability.

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 2:13 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
To set a daily wakeup in mythwelcome: First exit the frontend to the mythwelcome screen. Press "m" and lock the shutdown so it doesn't shutdown. Press "i" and you are in the window where you can set a daily wakeup. I set mine to 9-10am. After that, press "m" again to unlock the shutdown.

My cron code (somewhat edited):
Code:
#!/usr/bin/perl

# Optimize the DB
system("/usr/local/bin/optimize_mythdb.pl");

# Run mythbackup
$error=system("/usr/local/bin/mythbackup > /tmp/mythbackup.out 2>&1");
if($error) {
        # Add something here if you want notifications
        # system("cat /tmp/mythbackup.out | /myth/bin/mail.sh mythbackup");
}
system("/usr/bin/mythshutdown -u");

# Since the PC is usualy shutdown when cron.daily is run, run it now
system("cd /;run-parts --report /etc/cron.daily");

# If it is the 1st, run chkdsk on sda1/3.  Note that I have set the
# max mount count to 90 using "tune2fs -c 90 /dev/xxx"
$day=`date '+%d'`;
chomp($day);
if($day eq "01") {
        system("date > /tmp/tune2fs.out");
        system("/sbin/tune2fs -l /dev/sda1 | grep Mount >> /tmp/tune2fs.out");
        system("/sbin/tune2fs -l /dev/sda3 | grep Mount >> /tmp/tune2fs.out");
        # Add something here if you want notifications
        # system("cat /tmp/tune2fs.out | /myth/bin/mail.sh MountCount");
        system("/sbin/tune2fs -C 100 /dev/sda1");
        system("/sbin/tune2fs -C 100 /dev/sda3");
        $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;
}
EDIT: Added setting of MythShutdownWakeupTime (thanks to heilig for this idea). I just tested and this script works. It turns out the original was not shutting down after the reboot, but I never noticed.

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


Last edited by alien on Tue May 06, 2008 2:33 am, edited 2 times in total.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 03, 2008 7:23 pm 
Offline
Joined: Mon Aug 14, 2006 8:24 pm
Posts: 314
Location: Melbourne, Australia
I have inserted marc.aronson's code into my setwakeup.sh so that now it looks
Code:
#!/bin/bash

# Script to wakeup time using acpi alarm
# Called from Mythwelcome
# first option passed from mythwelcome is --settime, second is seconds from 1970

# Convert from stupid time in seconds from 1970
datum=$(/bin/date -d "1970-01-01 UTC $2 sec" +%F\ %T\ %z)

# Reinterpret this in utc and write to alarm
utcdatum=$(/bin/date -u -d "$datum" +%F\ %T)
#echo $utcdatum>/tmp/testutcdatum
# Sending an email - not included in my script

# Write wakeup time to acpi alarm
echo $utcdatum>/tmp/alarm   # Then, /etc/init.d/hwclock.sh is modified to read this file
#echo $utcdatum>/proc/acpi/alarm

# Check numbers of mountings and reboot to force fsck if number is at maximum
cur_count=$(tune2fs -l /dev/sda3 | awk '/Mount count:/ { print $3 }')
max_count=$(tune2fs -l /dev/sda3 | awk '/Maximum mount count:/ { print $4 }')
echo $cur_count $max_count
# Test mount count against maximum
if [ $cur_count -ge $max_count ]; then
  echo It is time to check the volume.
  sudo shutdown -r now
fi
This seems to work correctly when I run it manually from the command line. If I set the mount count to the max with
Code:
tune2fs -C 26 /dev/sda3
then run setwakeup.sh from the command line it reboots as expected.

My current problem is that it does not work from Mythwelcome. If I set the mount count at or above the max and let Mythwelcome shutdown from idle it does not reboot. I have tried inserting some debugging code (echo "2">/tmp/test) to find how far through the script it got which indicated it got all the way through. I just seems to be ignoring the sudo shutdown command.
Should this approach work?
Is there some log I can look through for any problems?

_________________
Intel DG965WH, Dvico DVB-T Lite x2, HDHR, Gigabyte GT220, KingstonSSD, WD20EARS R8.5.2


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 03, 2008 11:31 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1530
Location: California
My guess is that when you ran the script from the command line, you were logged in as root, but that when it is run by the myth backend, it is run as user "mythtv". "sudo" will only give you the outcome you are looking for it you do the following:

1. From any shell execute the command "visudo".

2. Add "/sbin/shutdown" to the line that starts with "mythtv".

The line that beings with "mythtv" is the list of commands that user "mythtv" is allowed to execute as root with the "sudo" command.

Marc


Top
 Profile  
 

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



All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 3 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:  
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu