[pve-devel] r5740 - in pve-manager/pve2: bin/cron/daily lib/PVE/API2 www/manager

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Mar 22 09:03:27 CET 2011


Author: dietmar
Date: 2011-03-22 09:03:26 +0100 (Tue, 22 Mar 2011)
New Revision: 5740

Modified:
   pve-manager/pve2/bin/cron/daily/pve
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/www/manager/NodeConfig.js
Log:
simple log rotation for task index


Modified: pve-manager/pve2/bin/cron/daily/pve
===================================================================
--- pve-manager/pve2/bin/cron/daily/pve	2011-03-22 06:01:37 UTC (rev 5739)
+++ pve-manager/pve2/bin/cron/daily/pve	2011-03-22 08:03:26 UTC (rev 5740)
@@ -1,14 +1,68 @@
 #!/usr/bin/perl -w
 
 use strict;
-use PVE::APLInfo;
+#use PVE::APLInfo;
 use PVE::SafeSyslog;
+use IO::File;
+use File::Find;
+use File::stat;
 
 initlog ('pvedailycron', 'daemon');
 
-# update appliance info
-if (!PVE::APLInfo::update()) {
-    syslog ('err', "update appliance info failed - see /var/log/pveam.log for details");
+# fixme: update APL info?
+#my $pvecfg = PVE::Config::read_file('pvecfg');
+#my $proxy = ($pvecfg && $pvecfg->{http_proxy}) ? $pvecfg->{http_proxy} : undef;
+
+## update appliance info
+#if (!PVE::APLInfo::update()) {
+#    syslog ('err', "update appliance info failed - see /var/log/pveam.log for details");
+#}
+
+sub cleanup_tasks {
+
+    my $taskdir = "/var/log/pve/tasks";
+    my $filename = "$taskdir/index.1";
+
+    my $fh = IO::File->new($filename, O_RDONLY);
+    return if !$fh;
+
+    my $endtime = 0;
+    while (defined(my $line = <$fh>)) {
+	if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})(\s(\S.*))?)?$/) {
+	    $endtime = hex($3);
+	    last;
+	}
+    }
+    close($fh);
+
+    return if !$endtime;
+
+    # print "delete task older that $endtime\n" . localtime($endtime) . "\n";
+
+    my $count = 0;
+
+    my $wanted = sub {
+	my $filename = $_;
+
+	return if $filename !~ m/^UPID:/;
+
+	my $st;
+	if (($st = stat($filename)) && ($st->mtime < $endtime)) {
+	    unlink($filename);
+	    $count++;
+	}
+    };
+
+    foreach my $subdir (qw(0 1 2 3 4 5 6 7 8 9 A B C F E F)) {
+	my $path = "$taskdir/$subdir";
+	find($wanted, $path);
+    }
+
+    if ($count) {
+	syslog('info', "cleanup removed $count task logs");
+    }
 }
 
+cleanup_tasks();
+
 exit (0);

Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-22 06:01:37 UTC (rev 5739)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-22 08:03:26 UTC (rev 5740)
@@ -203,14 +203,13 @@
 
 	my $filename = "/var/log/pve/tasks/index";
 
-	my $bw = File::ReadBackwards->new($filename);
-	die "unable to open file '$filename' - $!\n" if !$bw;
-	
 	my $start = $param->{start} || 0;
 	my $limit = $param->{limit} || 50;
 
 	my $count = 0;
-	while (defined (my $line = $bw->readline)) {
+	my $line;
+
+	my $parse_line = sub {
 	    if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})(\s(\S.*))?)?$/) {
 		my $upid = $1;
 		my $endtime = $3;
@@ -226,8 +225,20 @@
 		    $limit--;
 		}
 	    }
+	};
+
+	if (my $bw = File::ReadBackwards->new($filename)) {	
+	    while (defined ($line = $bw->readline)) {
+		&$parse_line();
+	    }
+	    $bw->close();
 	}
-	$bw->close();
+	if (my $bw = File::ReadBackwards->new("$filename.1")) {	
+	    while (defined ($line = $bw->readline)) {
+		&$parse_line();
+	    }
+	    $bw->close();
+	}
 
 	$rpcenv->set_result_count($count);
 

Modified: pve-manager/pve2/www/manager/NodeConfig.js
===================================================================
--- pve-manager/pve2/www/manager/NodeConfig.js	2011-03-22 06:01:37 UTC (rev 5739)
+++ pve-manager/pve2/www/manager/NodeConfig.js	2011-03-22 08:03:26 UTC (rev 5740)
@@ -1347,7 +1347,7 @@
 	    restful: true
 	});
 
-	var page_size = 10;
+	var page_size = 50;
 
 	taskstore.load({
 	    params: {




More information about the pve-devel mailing list