![]()
About This Tutorial :
In this tutorial you will learn how to implement power saving feature for a Network File Server (NAS), SAMBA, or a Media Server.
For local and home backup solutions it is not necessary to keep the Network File Server Up and Running all the time.
Anytime you need a backup, you can remotely turn it on and server will go to sleep whenever your file transferring is finished.
Happy Energy Saving !
Part 1: Enable Wake-On-Lan (WOL) feature
It would let you turn on or awake a system from sleep state, by sending a magic packet to the network interface card.
Part 2: Enable Auto Sleep feature
Turns off a system in absent of network activity.
Part 3: Sending the Magic Packet For WOL
Turns on remotley the server by command or GUI.
1- Enable Wake-On-LAN feature in motherboard bios
2- Create a file in/sbin with name halt.local
3- copy this in /sbin/halt.local (This prevent losing WOL settings before shutdown):
#!/bin/bash
ifconfig eth0 up
ethtool -s eth0 wol g
4- Create a file with name auto_shutdown in a place: /root/power_saving/
#!/bin/bash
#
# This is scheduled in CRON. It will run every 20 minutes
# and check for inactivity. It compares the RX and TX packets
# from 20 minutes ago to detect if they significantly increased.
# If they haven't, it will force the system to sleep.
# by : vashwood ( http://ubuntuforums.org/showthread.php?t=530973 )
# Changed by CYBT for Fedora 27 July 2008
#
log=~/Scripts/idle/log
# Extract the RX/TX
rx=`/sbin/ifconfig eth0 | grep -m 1 RX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
tx=`/sbin/ifconfig eth0 | grep -m 1 TX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
#Write Date to log
date >> $log
echo "Current Values" >> $log
echo "rx: "$rx >> $log
echo "tx: "$tx >> $log
# Check if RX/TX Files Exist
if [ -f ~/Scripts/idle/rx ] || [ -f ~Scripts/idle/tx ]; then
p_rx=`cat ~/Scripts/idle/rx` ## store previous rx value in p_rx
p_tx=`cat ~/Scripts/idle/tx` ## store previous tx value in p_tx
echo "Previous Values" >> $log
echo "p_rx: "$p_rx >> $log
echo "t_rx: "$p_tx >> $log
echo $rx > ~/Scripts/idle/rx ## Write packets to RX file
echo $tx > ~/Scripts/idle/tx ## Write packets to TX file
# Calculate threshold limit
t_rx=`expr $p_rx + 1000`
t_tx=`expr $p_tx + 1000`
echo "Threshold Values" >> $log
echo "t_rx: "$t_rx >> $log
echo "t_tx: "$t_tx >> $log
echo " " >> $log
if [ $rx -le $t_rx ] || [ $tx -le $t_tx ]; then ## If network packets have not changed that much
echo "Suspend to Ram ..." >> $log
echo " " >> $log
rm ~/Scripts/idle/rx
rm ~/Scripts/idle/tx
#sudo /etc/acpi/sleep.sh force ## Force Sleep (Changed For Fedora)
sudo /sbin/shutdown -h now force ## Force Sleep
fi
#Check if RX/TX Files Doesn't Exist
else
echo $rx > ~/Scripts/idle/rx ## Write packets to file
echo $tx > ~/Scripts/idle/tx
echo " " >> $log
fi
5- Create a Cron Job by adding this to /etc/crontab (check autoshutdown script every 20 Minutes):
0,20,40 * * * * ~/power_saving/auto_shutdown #Auto shutdown system after network inactivity
Check installation:
# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000033 (51)
Link detected: yes
#crontab -l
0,20,40 * * * * ~/power_saving/auto_shutdown #Auto shutdown system after network inactivity
Linux: http://gsd.di.uminho.pt/jpo/software/wakeonlan/mini-howto/wol-mini-howto-3.html
Mac OS X: http://www.apple.com/downloads/macosx/networking_security/wakeonlan.html
Windows: http://www.depicus.com/software/remote-shutdown-daemon.aspx
Links:
http://www.chukhang.com/francis/?page=Geek/fedora_wol
http://www.nabble.com/Wake-On-LAN-on-Fedora-7--td14891614.html
http://lists.linuxcoding.com/rhl/2008q1/msg02316.html
http://ubuntuforums.org/showthread.php?t=360901
http://ubuntuforums.org/showthread.php?t=248607
http://ubuntuforums.org/showthread.php?t=530973
http://gd.tuwien.ac.at/linuxcommand.org/man_pages/ethtool8.html
http://en.wikipedia.org/wiki/Wake-on-LAN
http://fedoraproject.org/wiki/Administration_Guide_Draft/Cron