Green-Power (scheduled Power-off)

Status
Not open for further replies.
Joined
Jun 7, 2011
Messages
4
Hello all.
I'k looking for a auto-power-off functionality. My (old) Computer can scheduled power ON. I think FREENAS needs a setup for AUTO-POWER-OFF.

Hope u can add it to 8.1 for a green world :o
 
Joined
May 27, 2011
Messages
566
you want it to shutoff at a certain time? You could always add an entry to /conf/base/etc/crontab to shut it down yourself at a given time

if you add:

1<tab>2<tab>*<tab>* <tab>*<tab>root<tab>shutdown -p now

to /conf/base/etc/crontab, it should shut the system off at 2:01 am. here is a quick reference for crontab: http://adminschoice.com/crontab-quick-reference

you'll need to mount the file system as writable first, to do this type

mount -uw /



make a backup of your crontab first.

cp /conf/base/etc/crontab /conf/base/etc/crontab.bak

you can then append onto crontab by typing

printf "1\t2\t\*\t\*\t\*\troot\tshutdown -p now" >> /conf/base/etc/crontab

let me know if i need to go into more details for you.
 
Joined
Jun 7, 2011
Messages
4
Dear Matt

Many thanks. I have updated to 8.0.1 witch comes with the CRONE-EDITOR and have add your lines. Thanks a lot.
 
Joined
Jun 7, 2011
Messages
4
Shutdown
reboot Reboot immediately
halt Shutdown immediately
halt -p Shutdown immediately and turn off power if possible
shutdown -h 5 "Sys maintenance" Halt in 5 minutes, send warning message to logged- in users
 

numbnuts AU

Cadet
Joined
Sep 4, 2011
Messages
3
having this feature included in the GUI like previous version would be good. I schedule a shutdown on week nights at a certain time but leave the NAS running over the weekend, from friday afternoon to midnight on Sunday because thats when we use it the most.
 
P

philip

Guest
Wouldn't it be even better if we could schedule some type of sleep, or suspend-to-ram mode like "acpiconf -s 3" to power-down the NAS when idle, yet still have it available on demand with WOL ? I imagine most home users could use some form of sleep mode, my NAS just sits idle over 95% of the time burning CPU cycles and heating up the room.
 

tsatchell

Dabbler
Joined
Oct 9, 2011
Messages
11
Wouldn't it be even better if we could schedule some type of sleep, or suspend-to-ram mode like "acpiconf -s 3" to power-down the NAS when idle, yet still have it available on demand with WOL ? I imagine most home users could use some form of sleep mode, my NAS just sits idle over 95% of the time burning CPU cycles and heating up the room.

Would be a great feature :)
 

SoftDux-Rudi

Contributor
Joined
Jun 2, 2011
Messages
108
Would be a great feature :)

I agree, and would like to vote for this feature as well. Having a standby mode, with instant (or at least near-instant) wake-up would be awesome. It would help a great deal with my backup NAS to save some electricity
 

sac0dan

Cadet
Joined
Sep 8, 2011
Messages
3
That's exactly what I'm looking for for ages now. Until now I started a shutdown after no client host could be pinged. I found such a script in the freenas7-forum and adapted it. Unfortunatly with FN8 it doesn't work properly anymore and I have no clue why not.
So +1 for e "green solution"
 

Dutchy

Cadet
Joined
Sep 4, 2011
Messages
7

sac0dan

Cadet
Joined
Sep 8, 2011
Messages
3
What is the script that you're using? Maybe we can fix it?

Here is my script. I got it from the FN7 forum a while ago and adapted it to my needs. Basically it pings a specific range of IPs and shuts down when no host is reachable anymore. It does this after the ping failed for a certain number of tries.

The problem I now have with FN8 is that after a wake on lan the pinging ALWAYS fails. Even if there are some machines active on the intranet the script doesn't 'see' them. I have absolutely no clue why.
Sometimes it completly blocks my NAS so I have to do a hard reset. I don't know exactly what's happening.

Code:
#!/bin/bash
{
lockfile=/tmp/autosuspend.lock

if [ ! -e $lockfile ]; then
   trap "rm -f $lockfile; exit" INT TERM EXIT
   touch $lockfile

	echo "autosuspend script started"
	#sleep 180     # Sleep for 3 mins to make sure the server don't shut down right away
	class=192.168.1
	myIP=192.168.1.10   #$(/sbin/ifconfig | egrep -o "192.168.1.[0-9]{1,3}")
	failcount=0
	maxfail=3       # Set the number of failure count before we do a shutdown
	SLEEP=600       # Numbers of seconds between each check/loop

	LOGFILE=/tmp/autosuspend.log

	# Don't suspend if one of the following processes is active (separate by space):
	STOPPROCS='storeBackup wget'

	echo Logfile=$LOGFILE

	unset known_host

	_ping_last_host() {
	  # try to ping the last known active host
	  # return 0 on success, otherwise 1
	  echo "pinging last host $known_host" >> $LOGFILE
	  if [ $known_host ]; then
		echo -n "`date` - pinging last host $known_host - " >> $LOGFILE
		ping -c 1 $known_host >/dev/null;
		if [ $? -eq 0 ]; then 
		  echo "host is active" >> $LOGFILE
		  # Jepp! We're done
		  return 0
		else
		  echo "fail" >> $LOGFILE
		  unset known_host
		  return 1
		fi;
	  else
		return 1
	  fi
	  
	}

	_ping_range() {
	  # Ping an IP-range and look for a responding host.
	  # If there is one store it's IP in $known_host and return 0
	  # return 0 on success, otherwise 1
	  cnt=0
	  echo "`date` - pinging range...  " >> $LOGFILE
	  for i in {2..14}; # Set the range
	  do
		# Ignore my own ip
		if [ ${class}.${i} != $myIP ]; then
		  echo "pinging ${class}.${i}" >> $LOGFILE
		  ping -c 1 ${class}.${i} >/dev/null
		  if [ $? -eq 0 ]; then 
			echo -n "${class}.${i} - " >> $LOGFILE
			known_host=${class}.${i}
			return 0;
		  fi
		fi
	  done
	  return 1
	}

	_shutdown() {  
	  # Do a shutdown if we failed for $failcount rounds
	  # We need a script suspend.sh in the current directory
	  echo "deciding doing shutdown or not. failcount = $failcount" >> $LOGFILE
	  if [ $failcount -eq $maxfail ];then 
		echo "`date` - doing a shutdown" >> $LOGFILE
		more $LOGFILE | grep -F --line-buffered ''  # clear buffer
                rm $lockfile
                trap - INT TERM EXIT
		shutdown -p now >>$LOGFILE
		more $LOGFILE | grep -F --line-buffered ''  # clear buffer
		#we will never arrive here with a shutdown...
		echo "`date` - back from suspend" >> $LOGFILE
		failcount=0;
	  fi
	}

	while [ 1 ];
	do
	  proc_found=0
	  # look if uniterruptable jobs are running
	  for proc in $STOPPROCS
	  do
		if [ "`pgrep $proc`" != "" ];then 
		  echo "`date` - $proc is running." >> $LOGFILE
		  proc_found=1
		  break
		fi
	  done 
	  echo procfound=$proc_found 

	  if [ $proc_found -eq 0 ]; then
		# look for other hosts, that are alive in our subnet
		_ping_last_host
		if [ $? -ne 0 ];then
		  _ping_range
		  if [ $? -ne 0 ];then
			let failcount++;
			echo "failure No. $failcount" >> $LOGFILE
			_shutdown;
		  else
			echo "good." >> $LOGFILE
			failcount=0;
		  fi
		  else
			echo "good." >> $LOGFILE
			failcount=0;
		fi
	  fi
	  sleep $SLEEP;
	done
	
   rm $lockfile
   trap - INT TERM EXIT
else
   echo "autosuspend is already running. Exiting."
fi
} &


EDIT: Found the problem, corrected the script. Please read the following articles. And make sure your Windows firewall isn't blocking ping requests (that's what Windows 7 by default does...).
 

sac0dan

Cadet
Joined
Sep 8, 2011
Messages
3
After months I finally found the culprit. Perhaps someone can benefit of my field report.
To be exactly there were two reasons why my script didn't work anymore:

First Windows 7 firewall does BLOCK ping requests by default. So my script couldn't reach my main computer in the intranet and tried to shutdown too early.

Second: I always thought FN would crash or block while trying to shutdown as the vents were blowing louder than in idle mode while the host wasn't reachable over the intranet anymore. Last week I once again checked the manpage of "shutdown" and found that on some hardware you need the option "-p" instead of "-h" to get a power off. Then I remembered to have also changed the hardware while going from FN7 to FN8. After I exchanged the -h with a -p it works.

So the script I posted here several days ago works.
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Don't feel bad Sac0dan, I've been accustomed to using -h also and was caught off guard with -p :)

Thanks for the update!
 
Status
Not open for further replies.
Top