Announcement

Collapse
No announcement yet.

[SOLVED] Hard drive spindown: root drive wakes frequently

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Re: Hard drive spindown: root drive wakes frequently

    Originally posted by jankushka
    could you please run the script again and see what it says?
    Here it is:
    Code:
    cristian@server:/etc/init.d$ sudo ./foobar start
    + PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    + HOME_DIR=/home/cristian
    + LOG_DIR=/var/log
    + BACKUP_DIR=/home/cristian/logs
    + . /lib/lsb/init-functions
    + FANCYTTY=
    + [ -e /etc/lsb-base-logging.sh ]
    + . /etc/lsb-base-logging.sh
    + log_action_begin_msg Configuring my stuff
    + log_daemon_msg Configuring my stuff...
    + [ -z Configuring my stuff... ]
    + log_use_usplash
    + [ n = y ]
    + type usplash_write
    + usplash_write TEXT Configuring my stuff...
    + log_to_console log_daemon_msg Configuring my stuff...
    + [ n != y ]
    + [ no != yes ]
    + readlink /proc/self/fd/0
    + stdin=/dev/pts/0
    + [ /dev/pts/0 != /dev/pts/0 ]
    + return 0
    + log_use_fancy_output
    + TPUT=/usr/bin/tput
    + EXPR=/usr/bin/expr
    + [ xxterm != xdumb ]
    + [ -x /usr/bin/tput ]
    + [ -x /usr/bin/expr ]
    + /usr/bin/tput hpa 60
    + /usr/bin/tput setaf 1
    + [ -z ]
    + FANCYTTY=1
    + true
    + /usr/bin/tput xenl
    + /usr/bin/tput cols
    + COLS=74
    + [ 74 ]
    + [ 74 -gt 6 ]
    + /usr/bin/expr 74 - 7
    + COL=67
    + printf * Configuring my stuff...
     * Configuring my stuff...    + /usr/bin/expr 74 - 1
    + /usr/bin/tput hpa 73
                                         + printf
     + echo 5
    + [ mke2fs /dev/ram0 ]
    + log_action_end_msg 2
    + log_end_msg 2
    + [ -z 2 ]
    + log_use_usplash
    + [ n = y ]
    + type usplash_write
    + [ 2 -eq 0 ]
    + usplash_write FAILURE failed
    + log_to_console log_end_msg 2
    + [ n != y ]
    + [ no != yes ]
    + readlink /proc/self/fd/0
    + stdin=/dev/pts/0
    + [ /dev/pts/0 != /dev/pts/0 ]
    + return 0
    + [ 67 ]
    + [ -x /usr/bin/tput ]
    + printf \r
    + /usr/bin/tput hpa 67
                                      + [ 2 -eq 0 ]
    + printf [
    [+ /usr/bin/tput setaf 1
    + printf fail
    fail+ /usr/bin/tput op
    + echo ]
    ]
    + return 2
    + true
    + exit 1
    cristian@server:/etc/init.d$
    Originally posted by jankushka
    though, you new drive should be sdb and the usb pen should now be sdc...
    Yes - actually, as there are 2 data disc (one main and one backup) sda is the system, sdb is the data, sdc is the backup, sdd is the pendrive. But I configured fstab so that they are mounted by UUID.
    I wanted to mount them by label, but it doesn't work. I ls'd /dev/disk/ and there's no "by-label" subfolder. That subfolder is there in my desktop pc though. Why isn't it there on the server?

    Originally posted by jankushka
    it has to do with acpi and kernel.
    I have this:
    Code:
    cristian@server:/dev/disk$ find /lib/modules/2.6.24-17-generic/ -name \*cpufreq\*
    /lib/modules/2.6.24-17-generic/kernel/arch/x86/kernel/cpu/cpufreq
    /lib/modules/2.6.24-17-generic/kernel/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.ko
    /lib/modules/2.6.24-17-generic/kernel/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.ko
    /lib/modules/2.6.24-17-generic/kernel/drivers/cpufreq
    /lib/modules/2.6.24-17-generic/kernel/drivers/cpufreq/cpufreq_conservative.ko
    /lib/modules/2.6.24-17-generic/kernel/drivers/cpufreq/cpufreq_ondemand.ko
    /lib/modules/2.6.24-17-generic/kernel/drivers/cpufreq/cpufreq_powersave.ko
    /lib/modules/2.6.24-17-generic/kernel/drivers/cpufreq/cpufreq_stats.ko
    /lib/modules/2.6.24-17-generic/kernel/drivers/cpufreq/cpufreq_userspace.ko
    and
    Code:
    cristian@server:/dev/disk$ lsmod|grep cpufreq
    cpufreq_userspace    5284 0
    cpufreq_stats      7104 0
    cpufreq_powersave    2688 0
    cpufreq_ondemand    9740 0
    freq_table       5536 2 cpufreq_stats,cpufreq_ondemand
    cpufreq_conservative   8712 0
    Looks quite similar to yours, but there's no ACPI... Hmmm. Now that I think about it, that box also has a problem when shutting down - I have to give the shutdown command with the "-hP" option or it will start a recovery console, or halt without powering down. Maybe it's because I didn't wipe the system after changing hardware - I wanted to avoid a reinstall and reconfigure, and the system seemed to work fine. I guess I'll have to do that tomorrow anyway...

    Cristian

    Comment


      #32
      Re: Hard drive spindown: root drive wakes frequently

      guess that no acpi -> no cpu freq scaling.
      attached new script source.
      my previous script was actually rubbish...
      this one should work.
      Attached Files
      gnu/linux is not windoze

      Comment


        #33
        Re: Hard drive spindown: root drive wakes frequently

        Sorry for the late reply. "Real life" kicked in.
        An update to the situation. Things more or less work now.
        I got the disks to spindown (even though the spindown time is never exactly what I set), and the script works (but I had to modify it a little). It sometimes fails when "deconfiguring my stuff" but I don't know what exactly fails there yet.
        Now the problem I'm currently researching into is that I've set a cron job to rsync the main storage disk to the backup storage disk, but that script is run twice a day! I have set it to run at 4:30 am but it runs both about midnight and about 5am.

        Here's my edited "configuration" script, mainly edited to print out what it's doing:

        Code:
        <...snip...>
        
        case "$1" in
        start)
        #    log_action_begin_msg "Configuring my stuff"
            log_action_begin_msg "Making RAM DISK FS"
            # ram disk fs for var logs
            mke2fs ${RAMDISK_DEV} > /dev/null 2>&1
            if [ $? -ne 0 ]
            then
                log_action_end_msg 1
        #        exit 1
            else
                log_action_end_msg 0
            fi
        
            # mount ram disk
            log_action_begin_msg "Mounting RAM DISK"
            mount ${RAMDISK_DEV} ${LOG_DIR} > /dev/null 2>&1
            if [ $? -ne 0 ]
            then
                log_action_end_msg 1
        #        exit 1
            else
                log_action_end_msg 0
            fi
        
            # var logs backup
            log_action_begin_msg "Deleting logs dir"
            rm -rf ${BACKUP_DIR}
            log_action_begin_msg "Creating logs dir"
            mkdir -p ${BACKUP_DIR}
        
            # mount usb pen
            log_action_begin_msg "Mounting pen drive"
            mount ${USBPEN_DEV} ${BACKUP_DIR} > /dev/null 2>&1
            if [ $? -ne 0 ]
            then
                log_action_end_msg 1
        #        exit 1
            else
                log_action_end_msg 0
            fi
        
            # start backup
            log_action_begin_msg "Syncing backups"
            rsync -r ${BACKUP_DIR}/ ${LOG_DIR}
        
            # hd spin down parameters
            log_action_begin_msg "Setting HDD parameters"
            hdparm -S48 /dev/sda
            hdparm -S235 /dev/sdb
            hdparm -S48 /dev/sdc
            if [ $? -ne 0 ]
            then
                log_action_end_msg 1
        #        exit 1
            else
                log_action_end_msg 0
            fi
        
            # laptop mode
            log_action_begin_msg "Entering laptop mode"
            echo 5 > /proc/sys/vm/laptop_mode
        
            # virtual memory sync tweak
            log_action_begin_msg "Setting pdflush expiry"
            echo 8640000 > /proc/sys/vm/dirty_expire_centisecs
        
            # all ok
        #    log_action_end_msg 0
            ;;
        
        stop)
            log_action_begin_msg "Deconfiguring my stuff"
            rsync -r ${LOG_DIR}/ ${BACKUP_DIR}
            # unmount ram disk log file system
            umount ${LOG_DIR} > /dev/null 2>&1
            if [ $? -ne 0 ]
            then
                log_action_end_msg 1
        #        exit 1
            fi
        
            # unmount logs backup file system
            umount ${BACKUP_DIR} > /dev/null 2>&1
            if [ $? -ne 0 ]
            then
                log_action_end_msg 1
        #        exit 1
            fi
        
            # all ok
            log_action_end_msg 0
            ;;
        
        *)
            echo "Usage: /etc/init.d/foobar {start|stop}"
            exit 1
            ;;
        esac
        
        exit 0
        Thanks for all your help,

        Cristian

        Comment


          #34
          Re: Hard drive spindown: root drive wakes frequently

          good.
          no problems.
          it's actually fun.

          stopping failure issue:
          it's either rsync or unmount, right?
          could be that something's keeping the directory you want to unmount busy.
          use lsof to check that.

          crontab:
          you should have a crontab file with an entry like so:
          # [min 0-59] [hour 0-23] [day of month 1-31] [month 1-12] [day of week 0-6] command
          #
          30 4 * * * your_command
          in /var/spool/cron/crontabs/<username>
          if you post your crontab file, i could try and take a look at it...

          cheers
          gnu/linux is not windoze

          Comment


            #35
            Re: Hard drive spindown: root drive wakes frequently

            Here's my crontab:

            Code:
            SHELL=/bin/sh
            PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
            
            # m h dom mon dow user command
            43 4  * * *  root  cd / && run-parts --report /etc/cron.hourly
            45 4  * * *  root  cd / && run-parts --report /etc/cron.daily
            47 4  * * 7  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
            52 6  1 * *  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
            #
            And in cron.daily I added this script:

            Code:
            #!/bin/sh
            # Syncs every night
            
            mount -o noatime /dev/sdc1 /BackStorage
            rsync -rtlpgovv --inplace --delete --log-file=/synclogs/log /MainStorage/ /BackStorage
            sleep 5
            umount /dev/sdc1
            hdparm -Y /dev/sdc
            It actually works without problems. If I check the logfile, everything's OK - except that it's also run at around midnight.

            In /var/spool/cron/crontabs there's only one user: "root". And I don't feel like messing with that!

            Cristian

            Comment


              #36
              Re: Hard drive spindown: root drive wakes frequently

              oops...
              i'm not 100% sure, but it seems your mixing cron and anacron.
              and you shouldn't do that.
              see what i mean?
              anacron is not for telling the system to run something at a precise given time.
              anacron is for telling the system to make sure something is run every so often.
              daily anacron jobs are normally run around midnight.
              by having a cron job to start anacron daily at 4 something am, you'll get those run twice.
              hope i got this right.
              looks like this is what's happening...
              gnu/linux is not windoze

              Comment


                #37
                Re: Hard drive spindown: root drive wakes frequently

                What do you mean that I'm mixing anacron and cron? I don't even know what anacron is! The only thing I did, was to add the syncing script in cron.daily, and modify the daily run time in crontab... oh yes, and removing the "test -x /usr/sbin/anacron" part in the crontab entry. Could it be that? But I don't see where I told the system to run that script with anacron too!

                Cristian

                Comment


                  #38
                  Re: Hard drive spindown: root drive wakes frequently

                  for anacron, read the man page.
                  it's a bit confusing how cron and anacron work together.
                  but there's not much we can do about it.

                  now...
                  i thought you enabled the root user's crontab and put the anacron stuff in it.
                  so, i thought you were posting /var/spool/cron/crontabs/root.
                  i now see you simply changed /etc/crontab.

                  then i don't know.
                  check /etc/cron.d/anacron and see at what time anacron is actually started.

                  then look at your /var/log/syslog files for clues on what goes on around midnight...

                  hth
                  gnu/linux is not windoze

                  Comment


                    #39
                    Re: Hard drive spindown: root drive wakes frequently

                    This is my anacron file:

                    Code:
                    # /etc/cron.d/anacron: crontab entries for the anacron package
                    
                    SHELL=/bin/sh
                    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
                    
                    30 7  * * *  root  test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null
                    Looks like it's run at 7:30.

                    This happens at 7:30 in /var/log/syslog:
                    Code:
                    May 29 07:30:01 server /USR/SBIN/CRON[7963]: (root) CMD (test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null)
                    May 29 07:30:01 server anacron[7987]: Anacron 2.3 started on 2008-05-29
                    May 29 07:30:01 server anacron[7987]: Normal exit (0 jobs run)
                    So anacron runs 0 jobs.

                    This is what happens around midnight:

                    Code:
                    May 28 23:52:01 server /USR/SBIN/CRON[7642]: (root) CMD (root^Itest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
                    May 28 23:52:01 server anacron[7646]: Updated timestamp for job `cron.daily' to 2008-05-28
                    May 28 23:54:34 server kernel: [391548.391963] ata4.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x2
                    May 28 23:54:34 server kernel: [391548.391972] ata4.00: waking up from sleep
                    May 28 23:54:34 server kernel: [391548.700298] ata4: soft resetting link
                    May 28 23:54:35 server kernel: [391548.856269] ata4: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
                    May 28 23:54:41 server kernel: [391555.318592] ata4.00: configured for UDMA/133
                    May 28 23:54:41 server kernel: [391555.318609] ata4: EH complete
                    May 28 23:54:41 server kernel: [391555.345993] sd 3:0:0:0: [sdc] 976773168 512-byte hardware sectors (500108 MB)
                    May 28 23:54:41 server kernel: [391555.346165] sd 3:0:0:0: [sdc] Write Protect is off
                    May 28 23:54:41 server kernel: [391555.346171] sd 3:0:0:0: [sdc] Mode Sense: 00 3a 00 00
                    May 28 23:54:41 server kernel: [391555.347301] sd 3:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
                    May 28 23:54:41 server kernel: [391555.387509] EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended
                    I noticed that the first two lines always happen exactly at 23:52, while the other block (concerning the sleeping HD) happen after a "pause" ranging from a few minutes to about 40 minutes... Why?

                    This runs around 4:30:
                    Code:
                    May 29 04:43:01 server /USR/SBIN/CRON[7760]: (root) CMD (  cd / && run-parts --report /etc/cron.hourly)
                    May 29 04:43:01 server /USR/SBIN/CRON[7763]: (root) CMD (root  cd / && run-parts --report /etc/cron.hourly)
                    May 29 04:45:01 server /USR/SBIN/CRON[7766]: (root) CMD (cd / && run-parts --report /etc/cron.daily)
                    May 29 04:45:01 server anacron[7770]: Updated timestamp for job `cron.daily' to 2008-05-29
                    May 29 04:55:06 server kernel: [409572.983370] ata4.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x2
                    May 29 04:55:06 server kernel: [409572.983379] ata4.00: waking up from sleep
                    May 29 04:55:06 server kernel: [409573.293817] ata4: soft resetting link
                    May 29 04:55:06 server kernel: [409573.449784] ata4: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
                    May 29 04:55:13 server kernel: [409579.927538] ata4.00: configured for UDMA/133
                    May 29 04:55:13 server kernel: [409579.927555] ata4: EH complete
                    May 29 04:55:13 server kernel: [409579.955324] sd 3:0:0:0: [sdc] 976773168 512-byte hardware sectors (500108 MB)
                    May 29 04:55:13 server kernel: [409579.955496] sd 3:0:0:0: [sdc] Write Protect is off
                    May 29 04:55:13 server kernel: [409579.955501] sd 3:0:0:0: [sdc] Mode Sense: 00 3a 00 00
                    May 29 04:55:13 server kernel: [409579.956630] sd 3:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
                    May 29 04:55:13 server kernel: [409579.996842] EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended
                    I should see something about "23:52" in crontab, but I see nothing...?!?

                    I've noticed the warning about the "unchecked" filesystem. I'll add an e2fsck command right before the rsync. Is it possible to set the script up so that it emails me if the e2fsck finds any error on the backup drive? Or even, set up a "SMART" check on the HD and have it email me if there is any problem?

                    Cristian

                    Comment


                      #40
                      Re: Hard drive spindown: root drive wakes frequently

                      3 things.

                      a) obviously, daily jobs should only run once a day
                      i still don't know exactly what's going on, but...

                      b) your /etc/crontab has wrong settings for cron.hourly (hour spec should be *)
                      that needs fixing

                      c) from you syslog, i see there's a special ^I character in the command line (...root^Itest...)
                      that also needs fixing

                      now then...
                      i would do the following:
                      a) restore /etc/crontab to the default
                      b) move your maintenance script to /usr/local/bin
                      c) add an entry to /etc/crontab to run the script at the desired time
                      end of story

                      as for emailing...
                      whatever a cron job outputs, cron emails to the crontab owner (root, in this case) by default.
                      so, in principles, there's nothing you need to add.

                      if that doesn't work for any reasons, you can always redirect the output of e2fsck.
                      i normally redirect stderr (fd 2) to stdout (fd 1) and then both to a log file.
                      like so:
                      Code:
                      e2fsck whatever >> /var/log/mye2fsck.log 2>&1
                      remember to run e2fsck so that i doesn't ask for user input (see man page).
                      otherwise it gets stuck waiting and nothing gets run afterwards.
                      gnu/linux is not windoze

                      Comment


                        #41
                        Re: Hard drive spindown: root drive wakes frequently

                        Originally posted by jankushka

                        b) your /etc/crontab has wrong settings for cron.hourly (hour spec should be *)
                        that needs fixing
                        I changed that because I noticed that, even though the cron.hourly has no script in it, it would wake the hard disk anyway. That's why I set it to run once a day just before cron.daily. I figured that would do no harm, because there is no script to be executed hourly.

                        Originally posted by jankushka
                        c) from you syslog, i see there's a special ^I character in the command line (...root^Itest...)
                        that also needs fixing
                        Yes, but it's in the command that gets executed at midnight, and I don't know where it's called from! So I don't know how to fix it (well, more than fix it, I would like to *remove* it!)

                        Originally posted by jankushka
                        i would do the following:
                        a) restore /etc/crontab to the default
                        b) move your maintenance script to /usr/local/bin
                        c) add an entry to /etc/crontab to run the script at the desired time
                        I'll try that when I come back from work.

                        Originally posted by jankushka
                        as for emailing...
                        whatever a cron job outputs, cron emails to the crontab owner (root, in this case) by default.
                        so, in principles, there's nothing you need to add.
                        Well, it seems than that I've got something to configure, because I get no emails! And I wouldn't expect to, because I never entered the email address (or email provider settings) anywhere...

                        Cristian

                        Comment


                          #42
                          Re: Hard drive spindown: root drive wakes frequently

                          Grrr... After trying what you said, this morning I checked what had happened during the night...
                          Well, rsync ran THREE times: at midnight, at 4:20, and at 7:42!!!
                          This is my crontab now:

                          Code:
                          SHELL=/bin/sh
                          PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
                          
                          # m h dom mon dow user command
                          #17 * * * * root  cd / && run-parts --report /etc/cron.hourly
                          20 4  * * * root  syncstorage
                          25 6  * * * root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
                          47 6  * * 7 root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
                          52 6  1 * * root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
                          So the 4.20 occurrence is the only authorized one. Where oh where did it find commands to run rsync at midnight and at 7:42?!? *frustrated*....

                          Cristian

                          EDIT: I rebooted the server and will let it run tonight, to see if maybe last night's rsyncs had already been scheduled "before" the changes... Just a try, even though I've never heard of a Linux reboot fixing things...

                          Comment


                            #43
                            Re: Hard drive spindown: root drive wakes frequently

                            you did rm the script from cron.daily, did you?
                            i know, know...but you never know
                            gnu/linux is not windoze

                            Comment


                              #44
                              Re: Hard drive spindown: root drive wakes frequently

                              Yes, I did!
                              Anyway... After the reboot, this night rsync only ran at 4:20!!! I won't say "hurray" yet, I'll want to see what happens tonight too... but it's looking good! I still wonder though where was the midnight command issued from.

                              Do you know where could I look to find information on how to send myself a regular email? Ideally, I'd like to have a script that runs once a week, and does: 1) a fsck on the 2 storage drives; 2) a free space check; 3) a SMART check on the hard disks; and emails me the results of these tests. So that I don't have to remember to log onto the server and do these tests by hand. I would just receive this email and check that the results are OK...

                              Cristian

                              Comment


                                #45
                                Re: Hard drive spindown: root drive wakes frequently

                                Originally posted by Quaxo76
                                Yes, I did!
                                Anyway... After the reboot, this night rsync only ran at 4:20!!! I won't say "hurray" yet, I'll want to see what happens tonight too... but it's looking good! I still wonder though where was the midnight command issued from.
                                i must have been anacron.
                                it likely needs to be told explicitly to re-read its cron dot directories when you change them.

                                Originally posted by Quaxo76
                                Do you know where could I look to find information on how to send myself a regular email? Ideally, I'd like to have a script that runs once a week, and does: 1) a fsck on the 2 storage drives; 2) a free space check; 3) a SMART check on the hard disks; and emails me the results of these tests. So that I don't have to remember to log onto the server and do these tests by hand. I would just receive this email and check that the results are OK...
                                all you need is the mail command.
                                if it's not already on the system, it'll be in some package that you need to install.
                                anyway...
                                simple way is to have your script re-direct its stdout and stderr to a log file.
                                and then email yourself the log file.
                                you could set the sticky bit on the commands you use.
                                the first time you use they would be read from disk.
                                but after that, with the sticky bit, they would be left in memory.
                                so, in between reboots, one fewer things that spins the disk up.
                                gnu/linux is not windoze

                                Comment

                                Working...
                                X