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


Recommended Posts

Hi there,

 

im although looking for a way to set the server to sleep.

 

Im running a Plex server and thats the problem i think. the library of the plex server is on the cache drive. i think thats the only solution.

The plex process makes the cache drive always to be spun up. and ten the server does not go to sleep. im using the Sleep Mode of SF.

 

Is there a way to ignore the cache drive or better to look for network traffic but not have the quest to have exactly 0 bytes of traffic. That will never be. Everytime the ethernet card will have some bytes of traffic.

If i am using the server with streaming to a plex client or copying some files oder reading some files, there are always some megabytes in a minute. Not only some kb. That  must be enough to know if the server can go to sleep oder not.

 

Does the SF Cache Dir plugin make some drive activity? Does the "Wait for array inactivity" option looks for the cache drive?

 

Sorry about the questions, but there are no infos about the Sleep Mode used in SF and how to use it right.

Link to comment
  • 4 months later...

Hi there,

 

im although looking for a way to set the server to sleep.

 

Im running a Plex server and thats the problem i think. the library of the plex server is on the cache drive. i think thats the only solution.

The plex process makes the cache drive always to be spun up. and ten the server does not go to sleep. im using the Sleep Mode of SF.

 

Is there a way to ignore the cache drive or better to look for network traffic but not have the quest to have exactly 0 bytes of traffic. That will never be. Everytime the ethernet card will have some bytes of traffic.

If i am using the server with streaming to a plex client or copying some files oder reading some files, there are always some megabytes in a minute. Not only some kb. That  must be enough to know if the server can go to sleep oder not.

 

Does the SF Cache Dir plugin make some drive activity? Does the "Wait for array inactivity" option looks for the cache drive?

 

Sorry about the questions, but there are no infos about the Sleep Mode used in SF and how to use it right.

 

Hi Julian,

 

I've spotted the same problems with this script on my unRAID box.

I've attached a fixed version, which ignores activity on the cache drive. I've not noticed any side effects of this on my machine, and I've been running the script for 3 months now.

 

Also, the checking for idle network activity is broken, and has been from the start.

 

The current test for idle network is:

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

 

However, this fails to take into account that the avg function in bwm-ng needs sample data over multiple seconds to calculate an average.

When you repeatedly run this command in a shell, you will find that 7 times out of 10, it returns 0.00, even when the network is very busy.

 

I was finding that my server was going to sleep at really odd times, when I knew that downloading/uploading was in full flow.

 

Expecting 0.00 for average network activity is unrealistic, unless the machine is unplugged from the network. There is always some kind of network housekeeping going on, even in a very small network.

 

To fix the problem, I've changed the test to this:

                TCP=$(bwm-ng -o csv -c 30 -d 0 -t 1000 -T avg | grep eth0 | cut -d";" -f5 | tail -1 | sed 's/.\{3\}$//')

 

This does two things. Firstly, we move to a 1 second sample interval, and take 30 samples to calculate our average.

Secondly, I've moved to integers for reporting the network activity. The fractions were not significant in determining activity, so it seemed pointless to test them.

 

The complete new function is as follows:

 

check_TCP_activity() {
        if [ "$checkTCP" = $yes ]
        then
                # Previous test for this failed to acknowledge that first value from bwm-ng is nearly always 0
                # when using -c 1. A true average is only calculated if you let bwm-ng run multiple times.
                # New test sets sample interval to 1 second and takes 30 samples, returning the last one for testing.
                # On my system, even when completely idle, you still see approx 5-6KB/s total network activity.
                # Expectng 0.00 activity is unrealistic, unless machine is unplugged from the network.
                # Have also moved to integers, as the fractions are unimportant in this test.

                TCP=$(bwm-ng -o csv -c 30 -d 0 -t 1000 -T avg | grep eth0 | cut -d";" -f5 | tail -1 | sed 's/.\{3\}$//')
        else
                TCP="$noTCP"
        fi
        echo $TCP
}

 

In addition, I've also added a couple of other features:

 

1) Debug logging

 

Possible options are:

 

# Enable debug logging

# debug=0 - no logging

# debug=1 - logs to syslog and auto_s3_sleep.log

# debug=2 - logs to syslog

# debug=3 - logs to auto_s3_sleep.log

# debug=4 - log to console

 

Simply edit the script, and change the debug= line to one of the values above (depending on what you want).

The default is 'debug=1'.

 

2) Shell activity checking.

 

Options are set in these lines:

checkSSH=$yes # check for any SSH connections

checkSHELL=$no # check for any locally logged in sessions (if "no" allows console debugging)

 

This allows you to prevent the machine from sleeping if someone is logged in over ssh, at the console, or both.

The default is to prevent sleep if someone is logged in over SSH, but allow it if they are logged in at the console.

 

I've not had a single 'false' sleep, since making these changes.

 

I've also attached a simple script which runs the 'sleep' checks, and reports on whether the system will go to sleep when the countdown timer expires.

I keep meaning to add a 'test' option to the main script, but I've never got around to it.

 

Hope this is useful for you.

 

Andy.

auto_s3_sleep.sh.zip

test_sleep_conditions.sh.zip

Link to comment
  • 4 weeks later...

:) Thanks to Bagpuss for cleaning up my original amateur code for checking network activity. Now I know why it occasionally failed for me too!

 

I've been away from unRAID for awhile but am now getting back into into things as I see version 5 is nearly ready for release. I have set up a test server to try it out.

 

The Bagpuss auto_s3_sleep script works fine for me with my production server running release 4.6rc3, but it has not been working on my release 5rc11 test server, and I've been pulling my hair out trying to figure out why.

 

Here is one issue that I've addressed. The sleep command from the original script

echo 3 > /proc/acpi/sleep/

does not work with release 5. After reading around here I understand this

echo -n mem > /sys/power/state

is the answer.  I manually confirmed it works via the terminal.

 

But fixing this alone did not result in success.

 

I also noticed that to conform with the logging conventions for release 5 and make the debugging log easily readable via Simple Features, it's best if the log is echoed to

/var/log/scripts/auto_s3_sleep.log

 

So I've made this change as well.

 

Reviewing the log reveals that the script appears  to not properly handle the network activity check on my release 5rc11 test server, and consequently the server never sleeps.

 

The debug log always shows TCP Activity as null (no value):

 

Wed Jan 30 15:59:51 EST 2013: TCP actvity (30 second average): {nothing} 

 

If I repeatedly check from the console at the same time the script is reporting nothing to the log, I will always see some activity. (And even if there actually were no activity I would expect the log to report 0, which it never does.)

 

So the server never sleeps, apparently because the script never returns any value for $TCPact.

 

The same script running on the release 4 server works fine, regularly logging values for $TCPact, and executing the sleep command when the value is appropriate.

 

Unfortunately this never happens with the same script running on the release 5.

 

Any help would be appreciated.

unRAID5rc11_autoS3_sleep_validation.jpg.74e974a262814c0b8e0391be08da64e4.jpg

auto_s3_sleeplog.txt

Link to comment

Following up to my previous post, I've spent a ton more time on this and determined definitively that the bwm-ng test for TCP activity does work with 5.0rc11 from a script running in the background, though it does work from the same script in a console or telnet session. Running in a background script the

TCP=$(bwm-ng -o csv -c 30 -d 0 -t 1000 -T avg | grep eth0 | cut -d";" -f5 | tail -1 | sed 's/.\{3\}$//')

returns nil. Running on the console or telnet session it returns an actual value reflecting network activity.

 

(Hardware is FoxConn A7GM-S 2.0 with Gigabit LAN by Realtek RTL8111B / RTL8111D)

 

The background methods I tested were:

  • nohup /boot/custom/bin/auto_s3_sleep.sh &
     
  • fromdos < /boot/custom/bin/auto_s3_sleep.sh | at now + 1 minute
     

If any one understands why this is happening and how to fix it, please chime in.

 

I've attached a quick and dirty test script isolating the bwm-ng code to make sure the problem was not caused by any of the logic within Bagpuss's auto_s3_sleep.sh.

 

I also determined in my testing that the code Bagpuss is using to allow sleep even when a cache drive is active will not work properly when there is no cache drive enabled. In that case the check_HDD_activity code as written will always return HDDs=0, no active HDDs, and immediately initiate the rest of the sleep checks.

 

Here is the inelegant brute force fix.

 

##Why does original auto_s3_sleep.sh script fail with no cache drive?
##From console echo `cat /proc/mounts | grep /mnt/cache | cut -d" " -f1 | cut -c 1-8` returns nil with no cache drive installed
##Then grep -v "$cache" does not work as intended. It should report all HDDs except cache and flash.
##Instead it returns nil so no hdparm is run and HDDs=0 even when it should not be.

##cache=`cat /proc/mounts | grep /mnt/cache | cut -d" " -f1 | cut -c 1-8`

if [ $checkHDDs = $yes ]
then
	# probe the flash drive at your peril
	##HDDs=$((for d in $(ls /dev/[hs]d? | grep -v "$flash" | grep -v "$cache"); do hdparm -C $d | grep active ; done) | wc -l)
                HDDs=$((for d in $(ls /dev/[hs]d? | grep -v "$flash"); do hdparm -C $d | grep active ; done) | wc -l)
##

 

Thanks for any assistance, I'm not going anywhere with unRAID 5 until I have a reliable sleep script.

 

tcpcheck.zip

Link to comment

OK I finally got the auto_sleep_s3 to work with unRAID 5.0rc11. It appears that the installation of bwm-ng by Simple Features was the issue. Once I installed unMENU and loaded the bwm-ng package from there, the sleep script was able to function correctly while running in the background.

 

So the issue probably has nothing to do with release 5. The script worked with my release 4 machine because it had unMENU's bwm-ng installation. It failed to work with my release 5 test machine only because I did not have the same bwm-ng installed.

Link to comment
  • 7 months later...

I've received pms and seen multiple new threads with questions about S3 sleep with version 5. So bringing this thread back up to post a revised version of Bagpuss's comprehensive S3 script with the changes for unRAID v5 mentioned in my post above: Changed sleep command to echo -n mem > /sys/power/state and logs to v5 directory structure.

 

Also note that, as I reported above, for this to work the bwm-ng version included with unMenu must be running. It would not work for me earlier with SimpleFeatures bwm-ng.

 

Script has been working OK for me on my v5 test rig, but my v4 production server still is occasionally falling asleep when it should be serving music. I have the noTCP variable set all the way down to '1024' and it still is happening. If it continues now that I've recently upgraded that rig to unRAIDServer-5.0-i386, I guess I'll have to get around to some serious trouble-shooting. Interested in hearing if anyone else is having this problem.

auto_s3_sleep.zip

Link to comment
  • 1 month later...

I've received pms and seen multiple new threads with questions about S3 sleep with version 5. So bringing this thread back up to post a revised version of Bagpuss's comprehensive S3 script with the changes for unRAID v5 mentioned in my post above: Changed sleep command to echo -n mem > /sys/power/state and logs to v5 directory structure.

 

Thanks for this.  I too need a sleep script for version 5.0 final since it disappeared from the main page in the new interface.  I was using SF prior to upgrading to v5.0 final, but, SF has display problems with this release.  I know some just leave their serving running 24x7; I do not want to do that as it is lightly used right now.

 

I have modified the unmenu sleep script on the user scripts page such that it now works properly with v5.0 final and I now have a manual sleep button that works great.

 

With your modified Bagpuss auto sleep script, do you put it in your go file so it is active on boot up or do you run it elsewhere?  Just curious as to how you are invoking it.

 

I am a total Linux script noob so, I am trying to wrap my head around what the the script is actually doing as far as checking NIC activity and the amount of inactive time before sleep is invoked, but, I very much appreciate the work you and Bagpuss have done on this.

Link to comment

 

Thanks for this.  I too need a sleep script for version 5.0 final since it disappeared from the main page in the new interface.  I was using SF prior to upgrading to v5.0 final, but, SF has display problems with this release.  I know some just leave their serving running 24x7; I do not want to do that as it is lightly used right now.

 

I have modified the unmenu sleep script on the user scripts page such that it now works properly with v5.0 final and I now have a manual sleep button that works great.

 

With your modified Bagpuss auto sleep script, do you put it in your go file so it is active on boot up or do you run it elsewhere?  Just curious as to how you are invoking it.

 

Here is the code I use in "go" to run the script in the background.  (It's been a long time but I believe this is per the original wiki article).

 

# Execute auto_s3_sleep.sh sleep script
fromdos < /boot/custom/bin/auto_s3_sleep.sh | at now + 1 minute

 

Note that the script needs to be located in the sub-directory it is being executed from, in this case /custom/bin/.

Link to comment

Can this script be altered to check if there are certain computers online in the LAN?

In my case it is not sufficient to ensure that there is no traffic.

I often power up my server and will access it only later on, be it from my PC or from my media player.

During that time there might be no traffic.

So I would need to check if the PC or the media player are online and if true not to sleep the unRAID.

 

 

Link to comment

Can this script be altered to check if there are certain computers online in the LAN?

In my case it is not sufficient to ensure that there is no traffic.

I often power up my server and will access it only later on, be it from my PC or from my media player.

During that time there might be no traffic.

So I would need to check if the PC or the media player are online and if true not to sleep the unRAID.

There is a provision in the script to ping the ip(s) of computer(s) on the LAN and not sleep if any of those ips are pingable.

For this to work you would need to assign a fixed ip to the computer(s) you want the script to check for.

For a media player this won't work properly if the media player maintains it's network connection even while "sleeping". This is the case with my WDTV Live. It that situation the media player is always ping-able, so the script would never find a condition that would allow it to sleep.

Link to comment
  • 4 weeks later...

Hi all,

 

First of all, thanks to everyone for their work in putting all of this together. I've recently started using unRAID, and just got S3 sleep working fine and waking up no with no problem using Bagpuss's auto_s3_sleep.sh script.

 

I would like to extend the amount of time before my system goes to sleep. I've edited the entry in the GO script from the value posted earlier "at now + 1 minute" to "at now + 10 minutes" but the system still seems to be sleeping after a minute. Is that the proper syntax, or do I need to edit the "auto_s3_sleep.sh" script?

Link to comment

I would like to extend the amount of time before my system goes to sleep. I've edited the entry in the GO script from the value posted earlier "at now + 1 minute" to "at now + 10 minutes" but the system still seems to be sleeping after a minute. Is that the proper syntax, or do I need to edit the "auto_s3_sleep.sh" script?

 

No, the line in the GO script is simply telling the auto_s3_sleep script to run in the background (not visible in the console). Changing the + value there only delays when the script begins to execute.

 

You want to edit this portion in the configuration section of the auto_s3 script.

 

# before going to sleep
intrnlTimeoutTicks=5	# ticks after HDD spindown before checking for external activity
extrnlTimeoutTicks=1	# ticks of no external activity before sleep; only after spindown+internal countdown

 

e.g., change to extrnlTimeoutTicks=10 for a ten minute delay instead of one.

Link to comment
  • 2 weeks later...

Last night I have been streaming a movie from my server.

After that I had to power up my desktop, log into unRAID and shut down the server.  :(

Well, I was too lazy go walk into the basement to the server and push the button.

This means to me, I finally have to get this script running.

 

Now I just had a look at the code of this script.

Although I'm not able to write such on my own I still understand the most of it.

Nice work  - and all commented!

Here my questions:

 

1. Can I use this value for noCountdownHours="7-23" or do I have to put all 16 numbers in here?

 

2. Why is the script invoked with "fromdos"? I assume the script is already in proper linux format...

 

3. Why are some lines commented with double #?

##cache=`cat /proc/mo...

 

4. In main you have this line

log_message "Not sleeping due to time of day."

I imagine this will spam the logfile since it's called every 60s.

Perhaps it would make sense to extend the $ticklengthSecs during the noCountdownHours?

Or even better, calculate the expiration time of noCountdownHours and use this for ticklength.

 

 

 

Link to comment

 

Here my questions:

 

1. Can I use this value for noCountdownHours="7-23" or do I have to put all 16 numbers in here?

 

2. Why is the script invoked with "fromdos"? I assume the script is already in proper linux format...

 

3. Why are some lines commented with double #?

##cache=`cat /proc/mo...

 

4. In main you have this line

log_message "Not sleeping due to time of day."

I imagine this will spam the logfile since it's called every 60s.

Perhaps it would make sense to extend the $ticklengthSecs during the noCountdownHours?

Or even better, calculate the expiration time of noCountdownHours and use this for ticklength.

 

1. You need to put each hour there, as per bagpuss's comment.

 

2. Just a fail safe convention in case someone edits the script with a DOS type editor. Not needed otherwise.

 

3. Those are edits I made to bagpuss's script. Attached is a cleaned up version from which I've removed the stuff I added for testing when it wouldn't work for me due to the issue I encountered with bwmonitor loaded by Simple Features. Use bwm included with unMENU.

 

4. Just turn off logging. It's only needed for debugging. Attached version has logging disabled.

 

The attached version also includes this change, which appears to finally have cured my issue with the server occasionally sleeping while I was playing music.

 

noTCP=700			##what constitutes absence of TCP activity (1024 equals 1KB/s) #- bagpuss default 9000. On my LAN requires 700 to not sleep prematurely.

 

I hope that's got you covered now. :)

auto_s3_sleep.zip

Link to comment
1. You need to put each hour there, as per bagpuss's comment.

OK,

I've been thinking further on this.

I will call the script with a cron job. I expect to need it only during night times from 1 to 7.

 

4. Just turn off logging. It's only needed for debugging. Attached version has logging disabled.

Some logging is useful.

The cron job will save me from getting the log spammed.

 

While I was thinking of my habits I came across another possible issue.

I tend to preclear drives in my server. This may get a bit tricky because this script won't

consider other drives that are not part of unraid.

Also for any other eventualities I didn't think of until now I would suggest to include one more constraint.

Please introduce a line like

if exist /tmp/noautos3sleep.lock
then
no standby

This will give us a possiblity to temporarily disable the service simply by creating this file instead of messing with the go file or alike.

Thank you!

 

Edit:

You should add a revision history.

Link to comment

No individual owns the right or duty to maintain this script or the earlier versions it is based on. These scripts have gradually been built upon with contributions by various users.  Bagpuss's version is, imo, by far the clearest and most comprehensive. However he appears to have other demands on his time lately, not having posted on the forum since September.

 

I've made a few changes to his script to suit my needs and shared them because it appeared there were other users who could benefit. Similarly there is no reason for you not to feel free to make any improvements you wish and also share those with the community.

Link to comment

OK, no changlog, no duties...

 

But can you help me to add the check for that lockfile I suggested?

 

Believe me, I probably know no more about linux scripting than you, and very likely would not figure it out any more quickly.  Maybe if you give it a shot yourself then someone more competent will step up and answer specific questions if you get stuck.

Link to comment

can this script get a function to avoid sleeping when a telnet / ssh session is established?

As written, it checks for ssh sessions but not telnet. But it can also check if a specific ip is pingable and then not sleep in that case, which would be another way to prevent sleep while you have a telnet session open - or, for that matter; ftp, or html (unMENU, SimpleFeatures, etc.).

Link to comment

can this script get a function to avoid sleeping when a telnet / ssh session is established?

As written, it checks for ssh sessions not but not telnet. But it can also check if a specific ip is pingable and then not sleep in that case, which would be another way to prevent sleep while you have a telnet session open - or, for that matter; ftp, or html (unMENU, SimpleFeatures, etc.).

 

It looks easy to add telnet check as well, maybe I do ir by my self, or you guys add it ?

 

//Peter

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.