[interchange-cvs] interchange - heins modified 9 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Mon May 16 17:22:28 EDT 2005


User:      heins
Date:      2005-05-16 21:22:28 GMT
Modified:  .        MANIFEST Makefile.PL
Modified:  lib/Vend Config.pm Dispatch.pm Server.pm
Modified:  scripts  interchange.PL
Added:     dist/etc/lib crontab
Added:     lib/Vend Cron.pm
Added:     scripts  crontab.PL
Log:
* Add new cron-style facility for determining HouseKeeping jobs.

* Default is no change, i.e. no cron.

* The recommended method to add the file is:

	HouseKeepingCron  <crontab

  That will use the file etc/lib/crontab by default in the tarball,
  or /etc/interchangec/crontab in an LSB configuration.

* Requires the Set::Crontab module, which has been added to
  Bundle::Interchange.

* Structure of the crontab file is just like crontab(5) in UNIX
  except that a seconds column is added.

  The targets are GlobalSub or anything which you can make run
  with Vend::Dispatch::run_macro. Bear in mind there is no
  catalog context.

  Two special targets exist, :reconfig and :jobs. They allow calling
  of the catalog reconfig routines and jobs routines, respectively.
  The etc/reconfig and etc/jobsqueue files will be ignored if these
  targets are not present -- a warning will be issued at startup
  (and crontab change) if they are not there.

  A target prepended with > runs *after* the reconfig/restart/jobs/pid
  mgmt cycle. Normal specifications run before.

  The basic entry to implement "HouseKeeping 5" would be:

     HouseKeeping 1
	 HouseKeepingCron <<EOC
	 */5 * * * * * :restart
	 */5 * * * * * :jobs
	 EOC

  (Note that would normally be in etc/lib/crontab or /etc/interchange/crontab.)

  To only check the jobs queue every five minutes (on the minute), you
  do:

	 */5 * * * * * :restart
	 0 */5 * * * * :jobs

  If you want to run the GlobalSub "checkit" once a day at 4am, you would
  do:

	 0 0 4 * * * checkit

* If you set HouseKeeping to a granularity besides 1 (or if for some
  reason Interchange skips a second), it does the cron check for
  every intervening second. This ensures a job will not be skipped.
  The :restart and :jobs entries will only run once, but if you have
  a frequent GlobalSub job that pushes the granularity of HouseKeeping
  it can be run twice in succession.

* WARNING: You should not put long-running jobs in a GlobalSub! You have
  been warned. Use the Jobs facility for that.

* Probably should implement the ability to call out jobs, but not quite
  sure how to specify and do. Can we just call run_jobs() directly?
  If so, then maybe an = sign introduces a job:

  	0 0 * * * * =standard_cat hourly
  	0 0 4 * * * =standard_cat daily
  	0 0 2 * * 7 =standard_cat weekly

* Include bin/crontab script to edit the crontab and submit to the
  running IC daemon. BUG: Cannot run as root.

Revision  Changes    Path
2.165     +4 -0      interchange/MANIFEST


rev 2.165, prev_rev 2.164
Index: MANIFEST
===================================================================
RCS file: /var/cvs/interchange/MANIFEST,v
retrieving revision 2.164
retrieving revision 2.165
diff -u -r2.164 -r2.165
--- MANIFEST	10 May 2005 14:04:11 -0000	2.164
+++ MANIFEST	16 May 2005 21:22:27 -0000	2.165
@@ -298,6 +298,7 @@
 code/Widget/select.widget
 code/Widget/show.widget
 code/Widget/text.widget
+code/Widget/time.widget
 code/Widget/uploadblob.widget
 code/Widget/uploadhelper.widget
 code/Widget/value.widget
@@ -1034,6 +1035,7 @@
 lib/Vend/Config.pm
 lib/Vend/Control.pm
 lib/Vend/CounterFile.pm
+lib/Vend/Cron.pm
 lib/Vend/Data.pm
 lib/Vend/DbSearch.pm
 lib/Vend/Dispatch.pm
@@ -1117,6 +1119,7 @@
 scripts/compile_link.PL
 scripts/config_prog.PL
 scripts/configdump.PL
+scripts/crontab.PL
 scripts/dump.PL
 scripts/expire.PL
 scripts/expireall.PL
@@ -1211,3 +1214,4 @@
 WHATSNEW-4.9
 WHATSNEW-5.1
 WHATSNEW-5.3
+META.yml                                 Module meta-data (added by MakeMaker)



2.52      +1 -0      interchange/Makefile.PL


rev 2.52, prev_rev 2.51
Index: Makefile.PL
===================================================================
RCS file: /var/cvs/interchange/Makefile.PL,v
retrieving revision 2.51
retrieving revision 2.52
diff -u -r2.51 -r2.52
--- Makefile.PL	27 Feb 2005 08:29:17 -0000	2.51
+++ Makefile.PL	16 May 2005 21:22:27 -0000	2.52
@@ -305,6 +305,7 @@
 		compile_link
 		config_prog
 		configdump
+		crontab
 		dump
 		expire
 		expireall



1.1                  interchange/dist/etc/lib/crontab


<<crontab: empty>>


2.175     +11 -2     interchange/lib/Vend/Config.pm


rev 2.175, prev_rev 2.174
Index: Config.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Config.pm,v
retrieving revision 2.174
retrieving revision 2.175
diff -u -r2.174 -r2.175
--- Config.pm	12 May 2005 17:54:37 -0000	2.174
+++ Config.pm	16 May 2005 21:22:28 -0000	2.175
@@ -1,6 +1,6 @@
 # Vend::Config - Configure Interchange
 #
-# $Id: Config.pm,v 2.174 2005/05/12 17:54:37 mheins Exp $
+# $Id: Config.pm,v 2.175 2005/05/16 21:22:28 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -50,8 +50,9 @@
 use Vend::Util;
 use Vend::File;
 use Vend::Data;
+use Vend::Cron;
 
-$VERSION = substr(q$Revision: 2.174 $, 10);
+$VERSION = substr(q$Revision: 2.175 $, 10);
 
 my %CDname;
 my %CPname;
@@ -443,6 +444,7 @@
 	['Jobs',		 	 'hash',     	 	 'MaxLifetime 600 MaxServers 1'],
 	['IPCsocket',		 undef,	     	 	 "$Global::VendRoot/etc/socket.ipc"],
 	['HouseKeeping',     'time',          60],
+	['HouseKeepingCron', 'cron',          ''],
 	['Mall',	          'yesno',           'No'],
 	['TagGroup',		 'tag_group',		 $StdTags],
 	['TagInclude',		 'tag_include',		 'ALL'],
@@ -3539,6 +3541,13 @@
 	config_error("Bad time format ('$value') in the $var directive\n")
 	unless defined $n;
 	$n;
+}
+
+sub parse_cron {
+	my($var, $value) = @_;
+
+	return '' unless $value =~ /\s/ and $value =~ /[a-zA-Z]/;
+	return Vend::Cron::read_cron($value);
 }
 
 # Determine catalog structure from Catalog config line(s)



1.54      +14 -4     interchange/lib/Vend/Dispatch.pm


rev 1.54, prev_rev 1.53
Index: Dispatch.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Dispatch.pm,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- Dispatch.pm	3 May 2005 06:03:26 -0000	1.53
+++ Dispatch.pm	16 May 2005 21:22:28 -0000	1.54
@@ -1,6 +1,6 @@
 # Vend::Dispatch - Handle Interchange page requests
 #
-# $Id: Dispatch.pm,v 1.53 2005/05/03 06:03:26 mheins Exp $
+# $Id: Dispatch.pm,v 1.54 2005/05/16 21:22:28 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 2002 Mike Heins <mike at perusion.net>
@@ -26,7 +26,7 @@
 package Vend::Dispatch;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 1.53 $, 10);
+$VERSION = substr(q$Revision: 1.54 $, 10);
 
 use POSIX qw(strftime);
 use Vend::Util;
@@ -1017,10 +1017,12 @@
 	  )
 	{
 
-#::logDebug("deliver image: method=$CGI::request_method type=$mt");
 		my $imgdir = $Vend::Cfg->{ImageDir};
 		my $fn = $CGI::path_info;
+#::logDebug("deliver image: method=$CGI::request_method type=$mt fn=$fn");
 		$fn =~ s:^/+::;
+		## Won't resend any images beginning with admin/
+		$fn =~ s{^admin/}{};
 		if($CGI::secure) {
 			 $imgdir = $Vend::Cfg->{ImageDirSecure}
 				if $Vend::Cfg->{ImageDirSecure};
@@ -1110,7 +1112,15 @@
 		if ($m =~ /^\w+$/) {
 			my $sub = $Vend::Cfg->{Sub}{$m} || $Global::GlobalSub->{$m}
 				or do {
-					logError("Unknown Autoload macro '%s'.", $m);
+					my $call = join(',', caller());
+
+					my $msg = errmsg("Unknown macro '%s' from %s.", $m, $call);
+					if($Vend::Cfg->{CatalogName}) {
+						logError($msg);
+					}
+					else {
+						logGlobal($msg);
+					}
 					next;
 				};
 			$sub->($content_ref);



2.64      +50 -5     interchange/lib/Vend/Server.pm


rev 2.64, prev_rev 2.63
Index: Server.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Server.pm,v
retrieving revision 2.63
retrieving revision 2.64
diff -u -r2.63 -r2.64
--- Server.pm	12 May 2005 17:52:51 -0000	2.63
+++ Server.pm	16 May 2005 21:22:28 -0000	2.64
@@ -1,6 +1,6 @@
 # Vend::Server - Listen for Interchange CGI requests as a background server
 #
-# $Id: Server.pm,v 2.63 2005/05/12 17:52:51 mheins Exp $
+# $Id: Server.pm,v 2.64 2005/05/16 21:22:28 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -26,7 +26,7 @@
 package Vend::Server;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 2.63 $, 10);
+$VERSION = substr(q$Revision: 2.64 $, 10);
 
 use POSIX qw(setsid strftime);
 use Vend::Util;
@@ -1017,6 +1017,23 @@
 #::logDebug("called housekeeping");
 	return if defined $interval and ($now - $Last_housekeeping < $interval);
 
+	my $do;
+	my $do_before;
+	my $do_after;
+
+#my $date = POSIX::strftime("time=%H:%M:%S", localtime($now));
+	if($Global::HouseKeepingCron) {
+		($do, $do_before, $do_after) = Vend::Cron::housekeeping($now);
+#::logDebug("got housekeeping at $date do=" . ::uneval($do));
+	}
+	else {
+		$do = {
+			restart => 1,
+			reconfig => 1,
+			jobs => 1,
+		};
+	}
+
 #::logDebug("actually doing housekeeping interval=$interval now=$now last=$Last_housekeeping");
 	rand();
 	$Last_housekeeping = $now;
@@ -1069,10 +1086,25 @@
 		@files = readdir Vend::Server::CHECKRUN;
 		closedir(Vend::Server::CHECKRUN)
 			or die "closedir $Global::RunDir: $!\n";
-		($reconfig) = grep $_ eq 'reconfig', @files;
+		($reconfig) = grep $_ eq 'reconfig', @files
+			if $do->{reconfig};
 		($restart) = grep $_ eq 'restart', @files
 			if $Signal_Restart || $Global::Windows;
-		($jobs) = grep $_ eq 'jobsqueue', @files;
+		($jobs) = grep $_ eq 'jobsqueue', @files
+			if $do->{jobs};
+
+		if($do_before) {
+			for(@$do_before) {
+#::logDebug("run before macro $_");
+				eval {
+					Vend::Dispatch::run_macro($_);
+				};
+				if($@) {
+					::logGlobal("cron before macro '%s' failed: %s", $_, $@);
+				}
+			}
+		}
+
 		if($Global::PIDcheck) {
 			$Num_servers = 0;
 			@pids = grep /^pid\.\d+$/, @files;
@@ -1101,6 +1133,7 @@
 						last;
 					}
 					chomp $value;
+#::logDebug("restart file reads value '$value'");
 				}
 				eval {
 					if($directive =~ /^\s*(sub)?catalog$/i) {
@@ -1121,7 +1154,7 @@
 						Vend::Config::code_from_file($directive, $value, 'nohup');
 					}
 					else {
-						::change_global_directive($directive, $value);
+						::change_global_directive("$directive $value");
 					}
 				};
 				if($@) {
@@ -1244,6 +1277,18 @@
 
 				if($@) {
 					::logGlobal({ level => 'notice' }, $@);
+				}
+			}
+		}
+
+		if($do_after) {
+			for(@$do_after) {
+#::logDebug("would run after macro $_");
+				eval {
+					Vend::Dispatch::run_macro($_);
+				};
+				if($@) {
+					::logGlobal("cron after macro '%s' failed: %s", $_, $@);
 				}
 			}
 		}



2.1                  interchange/lib/Vend/Cron.pm


rev 2.1, prev_rev 2.0



2.85      +8 -1      interchange/scripts/interchange.PL


rev 2.85, prev_rev 2.84
Index: interchange.PL
===================================================================
RCS file: /var/cvs/interchange/scripts/interchange.PL,v
retrieving revision 2.84
retrieving revision 2.85
diff -u -r2.84 -r2.85
--- interchange.PL	30 Apr 2005 15:17:10 -0000	2.84
+++ interchange.PL	16 May 2005 21:22:28 -0000	2.85
@@ -3,7 +3,7 @@
 #
 # Interchange version 5.3.1
 #
-# $Id: interchange.PL,v 2.84 2005/04/30 15:17:10 mheins Exp $
+# $Id: interchange.PL,v 2.85 2005/05/16 21:22:28 mheins Exp $
 #
 # Copyright (C) 2002-2005 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -639,6 +639,7 @@
 		serve           => $modesub,
 
 		test			=> $modesub,
+		globalconfig	=> sub { $Vend::Quiet = 1; $modesub->('globalconfig') },
 		unixmode        => \$Global::Unix_Mode,
 		version         => sub { version(); exit 0 },
 		stop			=> \&control_interchange,
@@ -709,6 +710,7 @@
         email=s
         exclude|e=s
         help|h
+		globalconfig
         inetmode|inet|i
         jobgroup=s
         kill:s
@@ -813,6 +815,11 @@
 
 	# Read interchange.cfg (or whatever its name is set to be)
 	global_config();
+
+	if($Vend::mode eq 'globalconfig') {
+		print Vend::Util::uneval($Global::Structure);
+		exit;
+	}
 	# Select locking mode
 	set_lock_type();
 



2.1                  interchange/scripts/crontab.PL


rev 2.1, prev_rev 2.0








More information about the interchange-cvs mailing list