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


Recommended Posts

OK,

I tried to implement the lockfile check but it throws some errors.

 

./auto_s3_sleep.sh: line 233: [: : integer expression expected

./auto_s3_sleep.sh: line 314: [: -eq: unary operator expected

 

Can someone check where I messed it up?

 

TRY ADD [[    ]]  instead of  [ ..... ]

 

so these 2 line looks like this.

 

 

if  [[ "$hourMatch" -eq 0 -a "$LockFile" -eq 0]]

 

if  [[$LockFile -eq 1  ]]

 

 

Why do you need a lock file? I have not follow all discussions ....

 

 

//Peter

Link to comment

New result:

./auto_s3_sleep.sh: line 233: syntax error in conditional expression
./auto_s3_sleep.sh: line 233: syntax error near `-a'
./auto_s3_sleep.sh: line 233: ` if [[ "$hourMatch" -eq 0 -a "$LockFile" -eq 0 ]] 

 

I wonder why it's ok in line 272?

if [ "$TCPact" -lt "$noTCP" -a "$SSHact" -eq 0 -a "$SHELLact" -eq 0 -a "$IPping" = $no ]

 

Why a lock file:

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.

Link to comment

 

Why a lock file:

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.

 

I have drives outside the array, if they are spinning , the server wont sleep. maybe THIS scrip ignore those drives ??? I have a older S3 script than this you are working with (it's from the SF)

 

and I also have worked on the server on a telnet session, and my server suddenly go to sleep  ;) therefore I need a telnet check  8) to avoid sleeping when I log on to my server.

 

 

Link to comment
  • 2 weeks later...

please try this version, telnet added, and your error is gone, BUT I maybe done something wrong ;-) please check the code.

 

i also think I made some changing on below line , see the red marking

 

 

  Lockfile='check_LockFile'

 

  if [ "$hourMatch" == 0 -a "$Lockfile" == 0 ]

  then

//Peter

 

Finally had some time to check your implementation but unfortunately...

 

./auto_s3_sleep.sh: line 247: syntax error in conditional expression
./auto_s3_sleep.sh: line 247: syntax error near `-a'
./auto_s3_sleep.sh: line 247: ` if [[ "$hourMatch" -eq 0 -a "$LockFile" -eq 0 ]]'

Link to comment
  • 2 weeks later...

Just upgraded from UnRAID v4.7 to v5.0.4 and so far had positive experience with this modified sleep script, which I used in v4.7:

 

#!/bin/bash
# Table of all possible drives when all drive slots are fully populated, with usb boot flash "/dev/sda" excluded
drives="/dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn /dev/sdo"
# Timeout in minutes
timeout=60
count=$timeout
while [ 1 ]
do
hdparm -C $drives | grep -q active
if [ $? -eq 1 ]
then
  count=$[$count-1]
else
  count=$timeout
fi
if [ $count -le 0 ]
then
  # Do pre-sleep activities
  sleep 5
  # Flush hdd filebuffers
  sync
  # Go to sleep
  echo -n mem > /sys/power/state
  # Do post-sleep activities
  # Flush hdd filebuffers
  sync
  # Force NIC into gigabit mode
  # (might be needed forgets about gigabit when it wakes up)
  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
  • 2 weeks later...
  • 3 months later...

What exactly does Carabolic's script do?

 

I'm able to sleep the server with the "echo -n mem > /sys/power/state" command and wake via magic packet, but I don't like putting the server to sleep without first making sure nothing is running or being accessed, and I'd like the drives to be spun down before the server goes to sleep. Is this possible? I'm on 5.0 Final.

Link to comment
  • 1 month later...

OK,

with extensive help from WeeboTech I finally managed to get the auto_s3_sleep script working.

 

Possible settings/checks:

# check for TCP activity

# check for any SSH connections

# check for any TELNET connections

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

# check for tmp/nos3sleep.lock (if this file exists, no sleep will be performed)

# do not sleep if dedicated clients are pingable

# only countdown outside specified hours

# call smarthistory script to log SMART values before powerdown (not tested & not confirmed working)

# choose between s3 sleep or powerdown (make sure you have installed the clean powerdown script)

 

Rename the file to .sh

 

Edit: attachment temporarily removed due to a reported minor bug (bug has been found, removed but remains to be confirmed)

Link to comment

Thanks for working on this Fireball. When I run the script it seems to just loop at this point. I have all checks set to "no" except for lock file and disks parked. No IP checks either.

 

Wed Jun  4 09:59:35 MDT 2014: All HDDs spun down.
Wed Jun  4 09:59:35 MDT 2014: Server is now idling. Checking for external activity.
Wed Jun  4 09:59:35 MDT 2014: Checking for network activity.
Wed Jun  4 09:59:35 MDT 2014: TCP activity (30 second average): 700
Wed Jun  4 09:59:35 MDT 2014: nobody online
Wed Jun  4 09:59:35 MDT 2014: Active SSH connections: 0
Wed Jun  4 09:59:35 MDT 2014: Active TELNET connections: 0
Wed Jun  4 09:59:35 MDT 2014: Active console logins: 0

Link to comment
  • 3 weeks later...

Here is the version 1.1 of the auto_s3_sleep script.

 

Thanks to Superorb who helped to get rid of some bugs.

In the process I also made the logging more detailed. If the script runs for your satisfaction you may want to set the debug variable to 0 (no logging) to keep writes to the log (flash drive) as low as possible.

 

Some answers to questions that arose:

This script is only checking certain conditions and either shuts down the server or sends it to S3 sleep.

Powerdown is done by invoking the

/sbin/powerdown

You should ensure that the clean powerdown script is installed, it is not part of this script!

 

S3 sleep is done by

echo -n mem > /sys/power/state

It seems that sending the server to S3 sleep is not trivial though.

unRAID will return many errors when waking up again. The whole extent is not clear since I don't use it.

There should probably be some kind of routine to, at least, unmount the array before sleeping.

More work and testing is needed so watch out when using S3!

 

Possible settings/checks:

# check for TCP activity

# check for SSH connections

# check for TELNET connections

# check for locally logged in sessions

# check for tmp/nos3sleep.lock (if this file exists, no sleep will be performed)

# do not sleep if dedicated clients are pingable

# only countdown outside specified hours

# call smarthistory script to log SMART values before powerdown (not tested & not confirmed working)

# choose between s3 sleep or powerdown (make sure you have installed the clean powerdown script)

 

Rename the file to .sh

Edit with a unix-like editor (e.g. notepad++) and configure to your needs.

 

Update:

Version 1.2 of this script is here

It adds the possibility to exclude drives. Thanks go 2 maspiter.

Link to comment
  • 2 weeks later...
  • 2 weeks later...

Hi all,

 

I have the following question :

 

I'm looking for the best way to run the following command each time my system runs : "ethtool -s eth wol g". If I run this manually I can perfectly WOL the next time but the time after that it has reset to "d".

 

I've looked around the forums and tried several things :

 

- added the command to my go script

- tried to add it to the powerdown script (but possible didn't do it in the right place?)

- added it to the sleep settings in Dynamix ("to Set WOL options before sleep:" ,  to "Custom commands before sleep:" and to "Custom commands after wake-up:"

 

 

Can anyone point me to the best way to go to make sure "g" is activated before every shutdown or can this really only be done by running the command myself manually?

 

Thanks in advance and sorry if I overlooked this somewhere on the forum but there is so much information here (spread over different versions of unRaid / scripts from the past) that I'm having a hard time finding the right solution.

 

 

Link to comment
  • 1 month later...

@Fireball3

 

Thanks for your script, I'm currently using it because the Dynamix script doesn't seem to take network activity into account. I have a suggestion though. Since I'm still using the free version and use a drive outside the array to host some apps, it might be a good idea to add in support to exclude a drive. I added a $nonArrayDisk variable myself and added an extra "| grep -v $nonArrayDisk" to filter it out the check_HDD_activity() but there is probably a more elegant way to do this. I also noticed a comment regarding checking for a cache drive but no commands are actually in place I think?

 

@dopray

 

You can try adding it to the section pre_sleep_activity or post_sleep_activity in the script on the previous page.

 

If it is working with that script, the Dynamix script might not execute your settings in the webGUI. Have you checked this with a trivial command like creating a file i.e. and after wake-up check whether it is actually created?

 

Hi all,

 

I cant seam to get S3 2 work properly .... i can  invoke it ok but upon Wol wakeup all i get is a black screen nothing, no tel, webgui, avery , nada ?

 

Any ideas ?

 

I had the same problem. Tested a full Slackware install on the same system and sleep worked fine so it was not a hardware problem. Tried many different things but in the end compiled my own custom kernel with added drivers for my AMD GPU. Since then, it sleeps and wakes just fine. It's a lot of work, certainly since you have to redo it each time you want to upgrade but IMO it's worth it. There's a guide in the wiki on compiling a custom kernel, one of my earlier posts also links to references I used. Hope this helps.

Link to comment

@Fireball3

 

Thanks for your script, I'm currently using it because the Dynamix script doesn't seem to take network activity into account. I have a suggestion though. Since I'm still using the free version and use a drive outside the array to host some apps, it might be a good idea to add in support to exclude a drive. I added a $nonArrayDisk variable myself and added an extra "| grep -v $nonArrayDisk" to filter it out the check_HDD_activity() but there is probably a more elegant way to do this. I also noticed a comment regarding checking for a cache drive but no commands are actually in place I think?

 

Thanks for improving!

Please document/comment the changes inside the script, raise the version number and then post it here.

I'm far from being that experienced to tell if there are better ways of scripting - if it works it's OK.

Maybe others, with the same use case, will want to test and comment on it?

 

Link to comment

Ok, I added in my changes.

 

I also took the liberty to move the configuration section to the top and moved the $noTCP and $debug variables to the configuration section for ease of use and added a few comments about determining which value to use for $noTCP for your specific system/use case. They might be obvious but thought I'd add them anyway.

 

Hallo,

 

sound promising. Are you willing to share your binaries?

 

8) You talking to me?  :D

 

If you're asking about the custom kernel, then sure, I am willing to share. Except I doubt it will do you any good because I only added in the firmware for my specific GPU (HD6310). I guess it should work for HD6250, HD7310 and HD7340 too (according to the method I used, https://wiki.gentoo.org/wiki/Radeon#External_resources) but these are all notebook GPUs.

 

But, I am by no means an unRAID nor linux expert. I just happen to have just enough knowledge to follow a few guides here and there. On top of that, my bzroot is smaller than the stock one because I stripped out some stuff I don't need, mostly drivers for ethernet cards I am not using I believe. That means your ethernet will probably only work when using a Realtek (I know) card.

 

So, as a disclaimer, using my files is at your own risk. I cannot be held responsible for data loss or any other unfortunate events that may or may not be tied to using them. etc etc ... That said, I've had no issues so far and recently even replaced a disk with a larger one flawlessly.

 

If you're still interested send me a PM with your email or something because one file is too big to post on the forum.

 

EDIT 1: I might have another version with all the drivers included. It is twice the size of the stock version though. You can add them to the syslinux.cfg file but better keep the stock as default. This way you can reboot and test it out without committing. Used this one for a bit but compiled another one afterwards apparently.

When I have some time I'm going to redo the whole process and maybe put a more descriptive guide online if there is some interest. The wiki article is a bit basic I think.

 

EDIT 2: I uploaded the files so others might benefit without having to contact me, don't know how long these will be available though.

 

Unraid 5.0.5 with radeon HD6310 and some drivers removed (what I'm using now):

http://www.files.com/set/53fcda459510f

 

Unraid 5.0.5 with radeon HD6310 and stock drivers:

http://www.files.com/set/53fcddb19096c

 

I'm using an E35M1-I BTW.

auto_s3_sleep.txt

Link to comment
  • 1 month later...

I'm trying to send my Test&Backup unRAID Server to sleep so that I can easily wake it up once a day when a backup is needed. Luckily I can send the system to sleep:

echo -n mem > /sys/power/state

and everything's running fine again when I'm sending a wol package.

 

However the script (thanks to those who developed this) doesn't send the server to sleep:

Sun Oct 12 18:41:21 CEST 2014: HDD activity detected. Active HDDs: 1
Sun Oct 12 18:42:21 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:42:21 CEST 2014: HDD activity detected. Active HDDs: 1
Sun Oct 12 18:46:29 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:46:29 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:47:29 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:47:29 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:48:29 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:48:29 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:49:29 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:49:29 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:50:29 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:50:29 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:51:29 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:51:30 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:52:30 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:52:30 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:53:30 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:53:30 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:53:55 CEST 2014: 
Sun Oct 12 18:53:55 CEST 2014: Start checking conditions for standby...
Sun Oct 12 18:53:55 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:53:55 CEST 2014: HDD activity detected. Active HDDs: 5
Sun Oct 12 18:54:30 CEST 2014: No lock file detected and time of day allows countdown for S3/powerdown.
Sun Oct 12 18:54:30 CEST 2014: HDD activity detected. Active HDDs: 5

 

...and some more information:

Oct 12 18:53:55 Tower2 auto_s3_sleep: ----------- auto_s3_sleep version 1.2 ---------------------
Oct 12 18:53:55 Tower2 auto_s3_sleep: Configuration settings:
Oct 12 18:53:55 Tower2 auto_s3_sleep: Power down instead of sleep: no
Oct 12 18:53:55 Tower2 auto_s3_sleep: Check HDD activity: yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: Check TCP activity: yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: Check SSH connections: yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: Check TELNET connections: yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: Check for online clients: 
Oct 12 18:53:55 Tower2 auto_s3_sleep: Check local logins: yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: Check for lock file (tmp/nos3sleep.lock): yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: No sleep/powerdown during hours: 
Oct 12 18:53:55 Tower2 auto_s3_sleep: Save SMART values before powerdown: no
Oct 12 18:53:55 Tower2 auto_s3_sleep: Log message destination: /boot/logs/auto_s3_sleep.log
Oct 12 18:53:55 Tower2 auto_s3_sleep: --- After wake up from sleep: ----
Oct 12 18:53:55 Tower2 auto_s3_sleep: Renew DHCP: yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: Force GB LAN: yes
Oct 12 18:53:55 Tower2 auto_s3_sleep: ------------------------------------------------------------

 

Even if all HDDs are spun down the server is still active. There is no VM & any Docker active. The only change I made in the script is the following (I thought that the SSD cache drive should be excluded from the HDD activity check:

# uncomment the following variable to ignore one or more disks in check_HDD_activity()                                      
        singular example: nonArrayDisk="/dev/sdb" 

 

Any ideas where to look at? Thanks a lot in advance.

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.