Neue Version von hddshutdown

git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@791 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
maniacikarus
2007-08-20 15:17:03 +00:00
parent f480386fc6
commit 51585c70de
4 changed files with 96 additions and 165 deletions

View File

@@ -1,3 +1,57 @@
------------------------------------------------------------------------
r790 | ms | 2007-08-20 18:25:59 +0400 (Mon, 20 Aug 2007) | 2 lines
Netzwerkscripts: DHCP vollstaendig getestet und gefixt.
------------------------------------------------------------------------
r789 | ms | 2007-08-20 17:21:16 +0400 (Mon, 20 Aug 2007) | 3 lines
Setup weiter ausgebaut.
Initrd des Installationssystems verkleinert.
------------------------------------------------------------------------
r788 | ms | 2007-08-20 13:01:12 +0400 (Mon, 20 Aug 2007) | 2 lines
Setup SegFault-Fix.
------------------------------------------------------------------------
r787 | ms | 2007-08-20 01:55:19 +0400 (Mon, 20 Aug 2007) | 3 lines
dhcpcd.exe geschrieben.
asterisk.cgis geloescht.
------------------------------------------------------------------------
r786 | ms | 2007-08-20 01:39:43 +0400 (Mon, 20 Aug 2007) | 2 lines
Fuse bereinigt.
------------------------------------------------------------------------
r785 | ms | 2007-08-20 01:21:25 +0400 (Mon, 20 Aug 2007) | 4 lines
Rudimentaere ISDN-Erkennung erstellt.
ProbeHW optimiert weges des via-rhine-Problem.
Grubs gfx-Menue entfernt wegen der Kompatibilitaet.
------------------------------------------------------------------------
r784 | maniacikarus | 2007-08-20 00:18:59 +0400 (Mon, 20 Aug 2007) | 2 lines
Fix am Installer
------------------------------------------------------------------------
r783 | maniacikarus | 2007-08-19 23:59:53 +0400 (Sun, 19 Aug 2007) | 2 lines
Nochmal kleine Korrekturen an den Sprachdateien und der Remote CGI
------------------------------------------------------------------------
r782 | maniacikarus | 2007-08-19 23:35:46 +0400 (Sun, 19 Aug 2007) | 2 lines
Translations fuer den Installer gemacht
------------------------------------------------------------------------
r781 | maniacikarus | 2007-08-19 11:21:46 +0400 (Sun, 19 Aug 2007) | 2 lines
Buildfix
------------------------------------------------------------------------
r780 | maniacikarus | 2007-08-18 23:10:10 +0400 (Sat, 18 Aug 2007) | 4 lines

View File

@@ -181,8 +181,8 @@ sub diskbox {
print "<img alt='' src='/graphs/disk-$disk-day.png' border='0' />";
print "</a>";
print "<br />\n";
if (-e "/usr/local/bin/hddshutdown-state") {
system("/usr/local/bin/hddshutdown-state $disk");
if (-e "/usr/local/bin/hddshutdown") {
system("/usr/local/bin/hddshutdown state $disk");
}
my $smart = `/usr/local/bin/smartctrl $disk`;
$smart = &Header::cleanhtml($smart);

View File

@@ -1,117 +1,57 @@
#!/usr/bin/perl
#
# IPFire HDD Shutdown
# IPFire HDD Shutdown state reader
#
# This code is distributed under the terms of the GPL
#
# 13.05.2006 Arne Fitzenreiter
# 20.08.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
#
# begin
sub shutdown_hdd {
my @proc = `cat /proc/diskstats`;
my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
my %diskstatus = "";
my $debug = 1;
my $status = "unknown";
my $hdd = $_[0];
my $hdddev = "/dev/$_[0]";
if ( @ARGV[0] eq "state" ){
my $hdd = @ARGV[1];
$status = `hdparm -C /dev/$hdd | tail -1 | cut -d: -f2`;
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat($hdddev);
my $major = $rdev >> 8;
my $minor = ($rdev & 0xFF) >> 6;
open STAT, "/tmp/hddshutdown-stat";
my @diskstat = <STAT>;
close (STAT);
foreach my $line (@diskstat)
{
chomp ($line);
my @temp = split(/\:\ /,$line);
if ($temp[1]) {
my @devicestat = split(/\ /,$temp[1]);
foreach my $stats (@devicestat)
{
chomp ($stats);
my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
if ($major eq $fields[1] and $minor eq $fields[2])
{
$lastreadwritereq = $fields[3];
}
}
}
}
open STAT, "/proc/stat";
my @diskstat = <STAT>;
close (STAT);
foreach my $line (@diskstat)
{
chomp ($line);
my @temp = split(/\:\ /,$line);
if ($temp[1]) {
my @devicestat = split(/\ /,$temp[1]);
foreach my $stats (@devicestat)
{
chomp ($stats);
my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
if ($major eq $fields[1] and $minor eq $fields[2])
{
$readwritereq = $fields[3];
}
}
}
}
if (! -e "/tmp/hddshutdown-$hdd" ) { system("echo 0 > /tmp/hddshutdown-$hdd"); }
if ($readwritereq==$lastreadwritereq) {
open STAT,"/tmp/hddshutdown-$hdd";
my $lastsleepstate = <STAT>;
close (STAT);
if (! ($lastsleepstate==$readwritereq)) {
system("hdparm -y $hdddev");
system("logger -t ipfire Shuting down $hdddev !");
system("echo $readwritereq > /tmp/hddshutdown-$hdd");
}
}
if ( $status=~/standby/){
my $ftime = localtime((stat("/tmp/hddshutdown-$hdd"))[9]);
print"<B>Disk $hdddev status: <font color=#00FF00>standby</font></B> (since $ftime)";
}
else{
print"<B>Disk $hdddev status: <font color=#FF0000>active</font></B>";
}
exit;
}
if ( -e "/tmp/hddshutdown-stat" ) {
if (open STAT,"/dev/hda") {
close STAT;
shutdown_hdd("hda");
}
if (open STAT,"/dev/hdb") {
close STAT;
shutdown_hdd("hdb");
}
if (open STAT,"/dev/hdc") {
close STAT;
shutdown_hdd("hdc");
}
if (open STAT,"/dev/hdd") {
close STAT;
shutdown_hdd("hdd");
}
if (open STAT,"/dev/hde") {
close STAT;
shutdown_hdd("hde");
}
if (open STAT,"/dev/hdf") {
close STAT;
shutdown_hdd("hdf");
}
if (open STAT,"/dev/hdg") {
close STAT;
shutdown_hdd("hdg");
}
if (open STAT,"/dev/hdh") {
close STAT;
shutdown_hdd("hdh");
}
if ($debug){print "### Reading Diskstats ###\n";}
foreach (@proc){
my @line = split(/ +/,$_);
$diskstatus{$line[3]} =$line[12];
if ($debug){print "Getting device ".$line[3]." with the following value ".$line[12]."\n";}
}
system("cp /proc/stat /tmp/hddshutdown-stat");
if ($debug){print "### Searching for available Disks ###\n";}
foreach (@devices){
chomp $_;
if ($debug){print "Device ".$_." has ".$diskstatus{$_}." IO Requests.\n";}
$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
if ($diskstatus{$_} eq "0" && $status !=~/standby/){
if ($debug){print "Device ".$_." is set to standy.\n";}
system("/sbin/hdparm -y /dev/$_");
system("touch /tmp/hddshutdown-$_");
}
elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){
if ($debug){print "Device ".$_." is active.\n";}
if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
}
}
# end

View File

@@ -1,63 +0,0 @@
#!/usr/bin/perl
#
# IPFire HDD Shutdown state reader
#
# This code is distributed under the terms of the GPL
#
# 11.05.2006 Arne Fitzenreiter
#
# begin
my $hdd = @ARGV[0];
my $hdddev = "/dev/$hdd";
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat($hdddev);
my $major = $rdev >> 8;
my $minor = ($rdev & 0xFF) >> 6;
open STAT, "/proc/stat";
my @diskstat = <STAT>;
close (STAT);
foreach my $line (@diskstat)
{
chomp ($line);
my @temp = split(/\:\ /,$line);
if ($temp[1]) {
my @devicestat = split(/\ /,$temp[1]);
foreach my $stats (@devicestat)
{
chomp ($stats);
my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
if ($major eq $fields[1] and $minor eq $fields[2])
{
$readwritereq = $fields[3];
}
}
}
}
if (! -e "/tmp/hddshutdown-$hdd" ) {
print"<B>Disk $hdddev status:</B> unknown"
}
if ( -e "/tmp/hddshutdown-$hdd" ) {
open STAT,"/tmp/hddshutdown-$hdd";
my $lastsleepstate = <STAT>;
close (STAT);
my $ftime = localtime((stat("/tmp/hddshutdown-$hdd"))[9]);
if (! ($lastsleepstate==$readwritereq)) {
print"<B>Disk $hdddev status: <font color=#FF0000>active</font></B>";
}
if ( ($lastsleepstate==$readwritereq)) {
print"<B>Disk $hdddev status: <font color=#00FF00>standby</font></B> (since $ftime)";
}
}
# end