steffen: server/kolab/kolab kolabquotawarn,1.3,1.4

cvs at intevation.de cvs at intevation.de
Tue Aug 3 13:25:59 CEST 2004


Author: steffen

Update of /kolabrepository/server/kolab/kolab
In directory doto:/tmp/cvs-serv14005/kolab/kolab

Modified Files:
	kolabquotawarn 
Log Message:
quotascript improved. dcron is gone from openpkg, so we have to use the systems cron as a stopgap solution...

Index: kolabquotawarn
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/kolabquotawarn,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- kolabquotawarn	17 May 2004 12:10:46 -0000	1.3
+++ kolabquotawarn	3 Aug 2004 11:25:57 -0000	1.4
@@ -30,6 +30,7 @@
 use strict;
 use warnings;
 use Getopt::Std;
+use Sys::Syslog qw(:DEFAULT setlogsock);
 use IO::File;
 use DB_File;
 use Mail::Message;
@@ -49,6 +50,43 @@
     exit 0;
 }
 
+#
+# Syslogging options for verbose mode and for fatal errors.
+# NOTE: comment out the $syslog_socktype line if syslogging does not
+# work on your system.
+#
+my $syslog_socktype = 'unix'; # inet, unix, stream, console
+my $syslog_facility="mail";
+my $syslog_options="pid";
+my $syslog_priority="info";
+
+sub mylog {
+  my $prio = shift;
+  my $fmt = shift;
+
+  my $text = sprintf( "kolabquotawarn: $fmt", @_ );
+
+  #print STDERR "$text\n";
+  syslog $prio, $text;
+}
+
+#
+# This process runs as a daemon, so it can't log to a terminal. Use
+# syslog so that people can actually see our messages.
+#
+setlogsock $syslog_socktype;
+openlog $0, $syslog_options, $syslog_facility;
+
+#
+# Log an error and abort.
+#
+sub fatal_exit {
+    my($first) = shift(@_);
+    #printf( STDERR "fatal: $first", @_ );
+    mylog("err", "fatal: $first", @_);
+    exit 1;
+}
+
 my $prefix = $Kolab::config{'prefix'};
 my $warninterval = 60*60*24; # seconds between warnings
 my $warnmessage = '';
@@ -60,11 +98,11 @@
   $warnmessage =~ s/<admin>/MAILER-DAEMON/g;
   $warnh->close;
 } else {
-  die "Can't open quotawarning.txt";
+  fatal_exit( "Can't open quotawarning.txt" );
 }
 
 dbmopen( %quotawarn_db, $prefix.'/var/kolab/quotawarn.db', 0666 ) 
-  || die ('Unable to open quotawarn db');
+  || fatal_exit ('Unable to open quotawarn db');
 
 if( $opt_d ) {
   my $now = time();
@@ -131,17 +169,20 @@
   }
 }
 
+mylog( $syslog_priority, "starting up");
 
 ### Connect to Cyrus
 my $cyrus = Cyrus::IMAP::Admin->new('localhost');
-$cyrus || die 'Unable to connect to local Cyrus admin interface\n';
+$cyrus || fatal_exit( 'Unable to connect to local Cyrus admin interface\n' );
 $cyrus->authenticate(
 					 'User'          => $Kolab::config{'cyrus_admin'},
 					 'Password'      => $Kolab::config{'cyrus_admin_pw'},
 					 'mechanisms'    => 'plaintext', )
-  || die("Unable to authenticate with Cyrus admin interface, Error = `" . $cyrus->error. "'");
+  || fatal_exit("Unable to authenticate with Cyrus admin interface, Error = `" . $cyrus->error. "'");
 
 ### Mail offending users
 kolablistquotas( $cyrus, 'user/*', '*', $quotawarnpct );
 #print "\nSHARED FOLDERS:\n---------------\n";
 #kolablistquotas( $cyrus, 'user.*', '*', 80 );
+
+mylog( $syslog_priority, "shutting down");





More information about the commits mailing list