]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/hddshutdown
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 # IPFire HDD Shutdown state reader
25 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
27 my $newdiskstats = "";
31 if ($debug){print "### Searching for available Disks ###\n";}
35 my @array = split(/\//,$_);
36 $diskstats = `cat /var/run/hddstats-$array[$#array] 2>/dev/null`;
38 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
40 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
43 if ($debug){print "Device ".$_." IDE Power status:".$status."\n";}
44 if (-e
"/var/run/hddshutdown-$array[$#array]" && $status !~/standby
/)
46 if ($debug){print "Remove wrong standby marking\n";}
47 if ( -e
"/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
50 if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";}
51 if ($diskstats eq $newdiskstats && (! -e
"/var/run/hddshutdown-$array[$#array]") )
53 if ($debug){print "Setting Device ".$_." to standby ... ";}
54 $status = `hdparm -y /dev/$_ 2>&1`;
56 if ($status !~/Invalid/)
58 if ($debug){print "OK\n";}
59 system("touch /var/run/hddshutdown-$array[$#array]");
63 if ($debug){print "FAIL\n";}
66 if ($diskstats ne $newdiskstats)
68 if ($debug){print "Device ".$_." is active.\n";}
69 if ( -e
"/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
71 system("echo $newdiskstats > /var/run/hddstats-$array[$#array]");