Looking for better ideas how how to sleep/suspend my unraid box


Recommended Posts

* If you have only PATA devices, do "for d in /dev/hd?".

* If you have both SATA and PATA, do "for d in /dev/sd? /dev/hd?".

...or, just do:  for d in /dev/[hs]d?

 

----

Now, something else to think about.... I have one other working setup, on which the UNRAID label is on a real internal hard disk, not a flash drive.

 

Link to comment

Now, something else to think about.... I have a working setup on which the UNRAID label is on a real internal hard disk, not a flash drive.

Start a new thread for this please. I'm very interested. It's one of my pet peeves with unRAID.

Nothing to it, really. Just prepare the hard disk as you would prepare a flash key, and label it UNRAID. Works the same.

 

Link to comment

Adding the same command  'ethtool -s eth0 speed 1000' to the post-sleep section of the script seems to be working for me also.  I've only done a handful of wake-ups since yesterday, but previously the reduced network speed happened 100% of the time after the first boot.  So it seems to be a good fix.  Good idea Fibblebot.

 

I've been running 4.5beta7 - it did not fix the s3 problem for me.

 

I found another variable that may affect some network controllers' ability to negotiate 1000Mbps speed.

 

My setup had been consistently negotiating a Gbit connection without any problem until the other day. Then, apparently out of the blue, it became sporadic - settling for 100Mbps much of the time. I tried various things and nothing seemed to help. Then looking at my motherboard's manual I noticed that the PCIe network controller shared an interrupt with one of my 4 USB controllers and not with the other 3. It was then that I realized that the problem  with negotiating 1000Mbps began when I moved my USB flash drive to a different USB port. Sure enough that port was on the USB controller that shared the interrupt with the network controller.

 

Once I moved the flash drive back to a port on a controller that did not share the interrupt with the network controller, all was well again!

Link to comment

The point of this modification is to prevent S3 sleep while there is traffic on the ethernet controller. This addresses a problem I was having with my unRAID box going to sleep while I was using it to play music via my WDTV media player. I believe this occurred because the RAM buffer was large enough to offload and store all of the music remaining in the playlist thus allowing a time interval sufficient for the drives to spin down and for the S3.SH script to initiate sleep, even though the box was still serving music to the client.

 

Another practical benefit would be to prevent sleep while connected to unRAID for maintenance with telnet or web interface (Menu or unMenu).

 

I have been testing this script and it appears to work as intended. i.e., My unRAID box has not gone to sleep in the middle of music playlists which were previously problematic, though it does sleep as intended after drives spin down and network traffic ceases.

 

This version of the s3.sh script is based on the most recent enhancement by ReneV and its predecessors. It requires the installation of the bwm-ng bandwidth monitor package. bwm-ng can be installed via unMenu or the go script.

 

#!/bin/bash
flash=/dev/`ls -l /dev/disk/by-label| grep UNRAID | cut -d"/" -f3 | cut -c 1-3`
timeout=5
count=5
while [ 1 ]
do
awake=$((for d in $(ls /dev/sd? | grep -v $flash); do hdparm -C $d | grep active ; done) | wc -l)
if [ $awake -eq 0 ]
then
  count=$[$count-1]
else
  count=$timeout
fi
#Check traffic on eth0 using bwm-ng
traffic=$(bwm-ng -o csv -c 1 -d 0 -T avg | grep eth0 | cut -d";" -f5)
if [ $count -le 0 -a $traffic = '0.00' ]
then
  # Do pre-sleep activities
  sleep 5
  # Go to sleep
  echo 3 > /proc/acpi/sleep
  # Do post-sleep activities
  # Force NIC to use gigabit networking
  ethtool -s eth0 speed 1000
  # Force a DHCP renewal (shouldn't be used for static-ip boxes)
  # /sbin/dhcpcd -n
  sleep 5
  count=$timeout
fi
# Wait a minute
# echo COUNT $count
sleep 60
done

 

 

 

 

 

Link to comment

For completeness, here's <s3_notHddHrsNet.sh>; it does not need adjustment to work, but it is [CUSTOMIZABLE] in two places.

 

The script

 

0) sends the machine to s3 sleep

 

1) 30 mins [CUSTOMIZABLE @ "timeout=30"] after

 

2) the last HDD (not counting the flash drive) spins down

 

unless

 

3) there's network activity.

 

Additionally,

 

4) the countdown is suspended between 7:00am and 8:59am, and between 5:00pm and 9:59pm [CUSTOMIZABLE @ "'7' | '8' | '17' | '18' | '19' | '20' | '21'"].

(NB! The countdown will never suspend if you only write, say, '25'.)

 

 

<deleted>

 

superseded by http://lime-technology.com/forum/index.php?topic=3657.msg41767#msg41767

Link to comment

For completeness, here's <s3_notHddHrsNet.sh>; it does not need adjustment to work, but it is [CUSTOMIZABLE] in two places.

 

Been running the s3 script for several days and these new changes look great.  What would make this perfect for me was if, as its final check, it pinged a list of IPs and if it couldn't reach any of them, then it would go to sleep.  I don't know enough to do it myself and am looking for a bit of help on this.  I believe someone else mentioned this earlier in the thread, but I don't think it got fleshed out far enough.

Link to comment

For completeness, here's <s3_notHddHrsNet.sh>; it does not need adjustment to work, but it is [CUSTOMIZABLE] in two places.

 

Been running the s3 script for several days and these new changes look great.  What would make this perfect for me was if, as its final check, it pinged a list of IPs and if it couldn't reach any of them, then it would go to sleep.  I don't know enough to do it myself and am looking for a bit of help on this.  I believe someone else mentioned this earlier in the thread, but I don't think it got fleshed out far enough.

It's just adding another section after the check of the timeframe. But I better do not post it - I can only do "if-then-else" - those guys here knowing better can easily set a vaiable containing the IP-adresses and have them processed. It should be very easy.

So long you can do something like

ping 1.2.3.4 -c 1 | grep -q "ttl="

    if [ $? -eq 0 ]

    then ...

so you can set a variable that prohibits (or allows) the machine to fall asleep...

Link to comment

For completeness, here's <s3_notHddHrsNet.sh>; it does not need adjustment to work, but it is [CUSTOMIZABLE] in two places.

 

Been running the s3 script for several days and these new changes look great.  What would make this perfect for me was if, as its final check, it pinged a list of IPs and if it couldn't reach any of them, then it would go to sleep.  I don't know enough to do it myself and am looking for a bit of help on this.  I believe someone else mentioned this earlier in the thread, but I don't think it got fleshed out far enough.

It's just adding another section after the check of the timeframe. But I better do not post it - I can only do "if-then-else" - those guys here knowing better can easily set a vaiable containing the IP-adresses and have them processed. It should be very easy.

So long you can do something like

ping 1.2.3.4 -c 1 | grep -q "ttl="

    if [ $? -eq 0 ]

    then ...

so you can set a variable that prohibits (or allows) the machine to fall asleep...

 

Put a section like this near the top of the script (before the "while" loop) , editing the IP addresses to be those of your media players.  Just separate the addresses with spaces as in the example below.

mp_ip="192.168.2.221 192.168.2.200 192.168.2.201"

 

check_mp_status() {

        mp_online="no"  # initialize to "no" until we learn otherwise

        # ping each of the media servers to determine if online

        for i in $mp_ip

        do

            # ping the media server, if it answers, it is online

            out=`ping -q -c 1 $i 2>/dev/null`

            rec_count=`echo "$out" | grep "received" | cut -d " " -f4`

            if [ "$rec_count" = "1" ]

            then

                mp_online="yes"

                # if one is online, we do not need to ping

                # any others, break out of the "for" loop.

                break;

            fi

        done

        echo $mp_online

}

 

Then, down in the body of the script, add a few lines like this (lines in blue are existing, lines in RED are added):

 

if [ $hddAct -eq 0 ]

then

  count=$[$count-1]

else

  count=$timeout

fi

     online=`check_mp_status`

     if [ "$online" = "yes" ]

     then

       count=$timeout

     fi

netAct=$(bwm-ng -o csv -c 1 -d 0 -T avg | grep eth0 | cut -d";" -f5)

if [ $count -le 0 -a $netAct = '0.00' ]

then

Link to comment

Can someone show me how to load bwm-ng from the go script?  I don't use unmenu...

 

I suppose I create a new /boot/applications/ or /boot/packages

Drop the files for bwm-ng in there (where do you get them?)

and then start via go script

 

But if anyone has done this and could post specifics it would be much appreciated.

Link to comment

Can someone show me how to load bwm-ng from the go script?  I don't use unmenu...

 

I suppose I create a new /boot/applications/ or /boot/packages

Drop the files for bwm-ng in there (where do you get them?)

and then start via go script

 

But if anyone has done this and could post specifics it would be much appreciated.

 

See this post by WeeboTech. (Search  :) )

 

[edit] Deleted download link. One already in WeeboTech post.  ;) [/edit]

Link to comment

Can someone show me how to load bwm-ng from the go script?  I don't use unmenu...

 

I suppose I create a new /boot/applications/ or /boot/packages

Drop the files for bwm-ng in there (where do you get them?)

and then start via go script

 

But if anyone has done this and could post specifics it would be much appreciated.

 

To create the folder and get the file you need (these two commands only need be done once)  The second line starts with "wget" and ends with ".tgz" It should all be on one line, even if it wraps on your browser.

mkdir /boot/packages

wget  http://repository.slacky.eu/slackware-12.1/utilities/bwm-ng/0.6/bwm-ng-0.6-i486-2bj.tgz -O /boot/packages/bwm-ng-0.6-i486-2bj.tgz

The "wget" command will download the file from the slackware repository.  (It needs you to have a DNS nameserver entry and gateway defined on your unRAID server.  You can confirm it is configured by typing

ping -c 1 google.com

 

If you can successfully ping google, the "wget" should work.   The file you download should then exist in /boot/packages.

Look for it there with

ls -l /boot/packages

Then, to install it manually type

installpkg /boot/packages/bwm-ng-0.6-i486-2bj.tgz

To install it every time you reboot, add a similar line in the "go script."  You can easily do that by pasting this line at a command prompt:

echo "installpkg /boot/packages/bwm-ng-0.6-i486-2bj.tgz" >> /boot/config/go

It will append the "installpkg" line at the end of the "go" script.

 

Joe L.

Link to comment

 

I think that we don't really need bwm-ng to determine if there has been some network activity.

 

An simpler way would be to just read /proc/net/dev and assign it to a variable:

 

  NetSnapshot=$(cat /proc/net/dev)

 

Then some time later you just take a new snapshot the same way, and compare the two.

If $NetSnapshot = $NetNewSnapshot  then no network activity had occured in between.

 

Purko

 

Link to comment

 

I think that we don't really need bwm-ng to determine if there has been some network activity.

 

An simpler way would be to just read /proc/net/dev and assign it to a variable:

 

   NetSnapshot=$(cat /proc/net/dev)

 

Then some time later you just take a new snapshot the same way, and compare the two.

If $NetSnapshot = $NetNewSnapshot  then no network activity had occured in between.

 

Purko

 

True, but I think he was taking advantage of the 30 second average bwm-ng was performing... In any case, it is not a huge issue either way... It is why shell scripts are so powerful, you can modify as needed and quickly test different ideas.
Link to comment

That includes information for loopback, which isn't purely network activity. Standard unRAID tends to only support a single NIC so it would be:

NetSnapshot=$(cat /proc/net/dev | egrep eth0 | cut -d: -f2)
NetBytesRecv=$(echo $NetSnapshot | cut -d\  -f1)
NetBytesTran=$(echo $NetSnapshot | cut -d\  -f9)

 

The last two lines are 'cut -d\[space][space]-f#'

Link to comment

I think you at least want to grep for the actual network interface. If you don't, you may never go to sleep because of non-network traffic on the loopback device.

 

The cut may not be needed, but I wanted to show some advanced possibilities for determining bytes send and received.

Link to comment
True, but I think he was taking advantage of the 30 second average bwm-ng was performing... In any case, it is not a huge issue either way...

 

Actually, with no one offering any other solution when I asked, I (knowing next to nothing about linux) just did the best I could on my own. Though I did intentionally set the bwm-ng parameter to avg, because I do think it makes more sense than taking just one momentary reading.  :)

Link to comment
Though I did intentionally set the bwm-ng parameter to avg, because I do think it makes more sense than taking just one momentary reading.

 

There either was some network activity in the past 30 minutes, or there was no network activity in the past 30 minutes.

These are the only two things you care about, aren't they?

 

Link to comment

Though I did intentionally set the bwm-ng parameter to avg, because I do think it makes more sense than taking just one momentary reading.

 

There either was some network activity in the past 30 minutes, or there was no network activity in the past 30 minutes.

These are the only two things you care about, aren't they?

 

You might need to check for I/O OVER some minimal amount...  For example, the SMB Master controller on the LAN probably polls for shares every 15 minutes or so, and the NIST time daemon checks the system time on occasion, the "pings" used to detect if a media player is online would count as I/O.

 

Joe L.

Link to comment

Though I did intentionally set the bwm-ng parameter to avg, because I do think it makes more sense than taking just one momentary reading.

 

There either was some network activity in the past 30 minutes, or there was no network activity in the past 30 minutes.

These are the only two things you care about, aren't they?

 

Actually, I just care about whether there is network activity at the time I check. bwm-ng is supposed to average over 30 seconds, not thirty minutes. I am not knowledgeable enough about networking to be certain this is necessary. But it seemed to me that it would be possible to check at one moment and get "0.00" when there was actually still ongoing activity, while averaging, if only for a few seconds would greatly reduce the possibility of a false reading.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.