When I sleep, the MacBook sleeps so keeping this backup server running all night or during office hours does not make sense. Luckily, it runs Linux so anything should be possible. And yes, someone did the actual thinking for me! And in case, that page ever goes down, the script is attached below. I made a small modification: I am letting it go to hibernate instead of sleeping. A cronjob runs this script every hour, so within an hour after I go to bed, the server hibernates. This runs perfectly well. The machine is up and running in 10 or 20 seconds. How to wake it up? WakeOnLan. In the BIOS, I had to enable that option and that was it.
On the Mac, I installed the program wakeonlan via Darwinports. And also the Dashboard widget WakeOnLan version 0.89 for testing. The server wakes up using the widget! And also from the command line: `/opt/local/bin/wakeonlan "xx:xx:xx:xx:xx:xx"' (xx'es denote the MAC address of the server). Next is setting up a cronjob on the Mac to wake up the server every 15 minutes. Using Cronnix, setting this up was easy. I added a new line, "*/15 * * * *" executing `/opt/local/bin/wakeonlan "xx:xx:xx:xx:xx:xx"' every 15 minutes. It's that easy. The cronjob is automatically executing tasks; every 15 minutes a wakeonlan signal is sent to the server. If it is asleep, it wakes up. If it is alive or out of reach, the command dies.
Conclusion: an energy efficient server can be made even more efficient by shutting it down when not in use and waking it up when needen.
Attachment: hibernate script on server.
#!/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=/root/power/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 /root/power/rx ] || [ -f /root/power/tx ]; then
p_rx=`cat /root/power/rx` ## store previous rx value in p_rx
p_tx=`cat /root/power/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 > /root/power/rx ## Write packets to RX file
echo $tx > /root/power/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 "t_rx: "$t_rx
#echo "t_tx: "$t_tx
#echo "rx: "$rx
#echo "tx: "$tx
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 /root/power/rx
rm /root/power/tx
sudo /usr/sbin/hibernate ## Force Sleep
fi
#Check if RX/TX Files Doesn't Exist
else
echo $rx > /root/power/rx ## Write packets to file
echo $tx > /root/power/tx
echo " " >> $log
fi
No comments:
Post a Comment