custom sleep script


Recommended Posts

Hey there.

 

regarding speeding_ants sleep script

http://lime-technology.com/forum/index.php?topic=13063.msg123929#msg123929

 

i placed it under /boot/sleep/s3.sh

in /boot/config/go I added the line:

 

nohup /boot/sleep/s3.sh &

 

everything as described in the topic.

I also slightly changed the tick timeouts for testing purpose:

 

intrnlTimeoutTicks=1

extrnlTimeoutTicks=1

 

afterwards I rebooted the server but it never goes to sleep automatically.

how can i check, if its even running?

 

s3 worked fine under unraid 5.0-rc8a  (simpleFeatures) and also the unMenu default "sleep" script instantly puts the server to s3.

 

#ethtool eth0 also brings up

WAKE-ON: g

Link to comment
  • 2 weeks later...

push*

 

Any idea?

You haven't specified what settings you are using within the script itself, chances are the conditions are not met to start the sleep condition.

 

I would advice to use the sleep plugin which comes with SimpleFeatures. It allows easy configuration of the conditions when sleep needs to kick in.

 

Link to comment
  • 2 weeks later...

push*

 

Any idea?

You haven't specified what settings you are using within the script itself, chances are the conditions are not met to start the sleep condition.

 

I would advice to use the sleep plugin which comes with SimpleFeatures. It allows easy configuration of the conditions when sleep needs to kick in.

 

Yes probably.

I would love to use simple features again (here the s3 sleep script worked perfectly!), but I cant use unraid 5.0 rc8a for other reasons (http://lime-technology.com/forum/index.php?topic=23669.0)

 

 

My sleep script looks like this (and its taken 1:1 from the forum post, with a small change in the ticks timeout i think-> for testing)

#!/bin/bash
# constants
yes="yes"
no="no"
DATE=$(date)

# [CONFIGURATION]

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

# control of internal timeout
checkHDDs=$yes		# check if all HDDs are parked before counting down towards sleep
noCountdownHours=""	# only countdown towards sleep outside these hours
			# example: <noCountdownHours="07 08 19 20">
			# always countdown: <noCountdownHours="">

# control of external timeout 
checkTCP=$no		# check for TCP activity

pingIPs="$no" 		# do not sleep if <$pingsIPs> are pingable
			# example: <pingIPs="192.168.1.4 192.168.1.5">
			# no ping-check: <pingIPs="">

# after waking up from sleep
doDhcpRenewal=$no	# <$no> for servers w/static IP address
forceGb=$yes		# might not be needed; probably always safe

# [/CONFIGURATION]


# implementation stuff
ticklengthSecs=60		# probe hardware + count down every minute/60secs, aka a tick
noTCP='0.00'			# what constitutes absence of TCP activity
flash=/dev/`ls -l /dev/disk/by-label| grep UNRAID | cut -d"/" -f3 | cut -c 1-3` # automatic id of flash drive
check_hour() {
echo $(date +%H)
}
check_HDD_activity() {
if [ $checkHDDs = $yes ]
then
	# probe the flash drive at your peril
	HDDs=$((for d in $(ls /dev/[hs]d? | grep -v "$flash"); do hdparm -C $d | grep active ; done) | wc -l)
else
	HDDs=0
fi
echo $HDDs
}
check_TCP_activity() {
if [ "$checkTCP" = $yes ]
then 
	TCP=$(bwm-ng -o csv -c 1 -d 0 -T avg | grep eth0 | cut -d";" -f5)
else
	TCP="$noTCP"
fi
echo "$TCP"
}
check_IP_status() {
mp_online=$no  # initialize to "no" until we learn otherwise
        # ping each of the media servers to determine if online
if [ ! "$checkIPs" = $no ]; then
        for i in "$pingIPs"
        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" -eq 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
fi
        echo $mp_online
}
pre_sleep_activity() {

			echo "$DATE - Stopping services and sleeping"
			# Stop SMB
			/etc/rc.d/rc.samba stop 

			# Stop NFS
			/etc/rc.d/rc.nfsd stop

			# Stop AFP
			/etc/rc.d/rc.atalk stop

			# Stop AVAHI
			/etc/rc.d/rc.avahidaemon stop
			/etc/rc.d/rc.avahidnsconfd stop

			# Syncing Filesystems
			sync
}
post_sleep_activity() {

echo "$DATE - Starting services and waking"

# Force NIC to use gigabit networking
if [ "$forceGb" = $yes ]
then 
	ethtool -s eth0 speed 1000
fi

# Force a DHCP renewal (shouldn't be used for static-ip boxes)
if [ "$doDhcpRenewal" = $yes ]
then 
	/sbin/dhcpcd -n
fi

# Start SMB
/etc/rc.d/rc.samba start 

# Start NFS
/etc/rc.d/rc.nfsd start

# Start AFP
/etc/rc.d/rc.atalk start

# Start AVAHI
/etc/rc.d/rc.avahidaemon start
/etc/rc.d/rc.avahidnsconfd start

beep -f660 -l 100ms -D 100ms
beep -f660 -l 100ms -D 140ms
beep -f660 -l 120ms -D 150ms
beep -f510 -l 100ms -D 100ms
beep -f660 -l 120ms -D 160ms
beep -f770 -l 100ms -D 575ms
beep -f380 -l 150ms -D 575ms

}


# main
intrnlCountdown=$intrnlTimeoutTicks
extrnlCountdown=$extrnlTimeoutTicks
while [ 1 ]
do
# do not countdown during certain hours
	hour=`check_hour`
hourMatch=$(echo "$noCountdownHours" | grep "$hour" | wc -l)
if [ $hourMatch -eq 0 ]
then
	# count number of HDDs that are not parked
	HDDact=`check_HDD_activity`
 	if [ "$HDDact" -eq 0 ]
 	then
		# tick-tock for time since last spindown
		if [ $intrnlCountdown -gt 0 ]
  		then
  			intrnlCountdown=$[$intrnlCountdown-1]
		fi
 	else
		# reset countdown, following HDD activity
  		intrnlCountdown=$intrnlTimeoutTicks
  			extrnlCountdown=$extrnlTimeoutTicks
		echo "$DATE - Hard Drives active, resetting counter" | logger
 	fi

	if [ $intrnlCountdown -le 0 ]
 	then
		# check for persistent external activity
 		TCPact=`check_TCP_activity`
 		IPping=`check_IP_status`
 		if [ "$TCPact" = $noTCP -a "$IPping" = $no ]
		then
			if [ $extrnlCountdown -le 0 ]
 			then
	  		# Do pre-sleep activities
				pre_sleep_activity
	  			sleep 5
	  		
			# Go to sleep
	  			echo -n mem >/sys/power/state

	  		# Do post-sleep activities
				post_sleep_activity
	  			sleep 5
	  			intrnlCountdown=$intrnlTimeoutTicks
	  			extrnlCountdown=$extrnlTimeoutTicks
			else
				# tick-tock for persistent external activity
				if [ $extrnlCountdown -gt 0 ]
		  		then
		  			extrnlCountdown=$[$extrnlCountdown-1]
				fi
			fi
		else
			# reset countdown, following external activity
			extrnlCountdown=$extrnlTimeoutTicks
		fi
 	fi
fi

 # Wait a tick
	sleep $ticklengthSecs
done

 

It never goes to sleep automatically. I have to fire the sleep script from the unMenu scripts page manually

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.