]>
Commit | Line | Data |
---|---|---|
6c666a3b | 1 | #!/usr/bin/perl |
324bb888 AF |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007-2011 IPFire Team <info@ipfire.org> # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
6c666a3b | 21 | # |
51585c70 | 22 | # IPFire HDD Shutdown state reader |
6c666a3b | 23 | # |
6c666a3b | 24 | |
269e21c6 AF |
25 | # Also devices that cannot shutdown must be here for mediagraphs. |
26 | my @devices = `ls -1 /sys/block | grep -E '^sd|^xvd|^vd|^md' | sort | uniq`; | |
56b7a3e2 CS |
27 | my $diskstats = ""; |
28 | my $newdiskstats = ""; | |
51585c70 | 29 | my $debug = 1; |
471a46f7 | 30 | my $status = ""; |
6c666a3b | 31 | |
51585c70 | 32 | if ($debug){print "### Searching for available Disks ###\n";} |
6c666a3b | 33 | |
51585c70 | 34 | foreach (@devices){ |
471a46f7 | 35 | chomp $_; |
5384809b | 36 | my @array = split(/\//,$_); |
324bb888 | 37 | $diskstats = `cat /var/run/hddstats-$array[$#array] 2>/dev/null`; |
471a46f7 CS |
38 | chomp $diskstats; |
39 | $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`; | |
40 | chomp $newdiskstats; | |
41 | $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`; | |
42 | chomp $status; | |
43 | ||
44 | if ($debug){print "Device ".$_." IDE Power status:".$status."\n";} | |
965f4547 | 45 | if (-e "/var/run/hddshutdown-$array[$#array]" && $status !~/standby/) |
471a46f7 CS |
46 | { |
47 | if ($debug){print "Remove wrong standby marking\n";} | |
965f4547 | 48 | if ( -e "/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); } |
471a46f7 CS |
49 | } |
50 | ||
51 | if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";} | |
965f4547 | 52 | if ($diskstats eq $newdiskstats && (! -e "/var/run/hddshutdown-$array[$#array]") ) |
471a46f7 CS |
53 | { |
54 | if ($debug){print "Setting Device ".$_." to standby ... ";} | |
55 | $status = `hdparm -y /dev/$_ 2>&1`; | |
56 | chomp $status; | |
5384809b | 57 | if ($status !~/Invalid/) |
471a46f7 CS |
58 | { |
59 | if ($debug){print "OK\n";} | |
965f4547 | 60 | system("touch /var/run/hddshutdown-$array[$#array]"); |
471a46f7 CS |
61 | } |
62 | else | |
63 | { | |
5384809b | 64 | if ($debug){print "FAIL\n";} |
471a46f7 CS |
65 | } |
66 | } | |
67 | if ($diskstats ne $newdiskstats) | |
68 | { | |
69 | if ($debug){print "Device ".$_." is active.\n";} | |
965f4547 | 70 | if ( -e "/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); } |
471a46f7 | 71 | } |
965f4547 | 72 | system("echo $newdiskstats > /var/run/hddstats-$array[$#array]"); |
6c666a3b | 73 | } |
3bc32eab | 74 | |
6c666a3b | 75 | # end |