mirror of https://github.com/CGAL/cgal
Cleaned up the structure of the script.
It now has a initialisation, main loop and finalisation. Now sending messages to the invoker instead of the maintainer.
This commit is contained in:
parent
5f1e7c747a
commit
17536b7a45
|
|
@ -3,23 +3,20 @@
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
#--------------------------------------------------------------#
|
#--------------------------------------------------------------#
|
||||||
# This script scans through the mail box $::MAILBOX, using procmail.
|
# This script scans through the mail box $::MAIL_IN, using formail.
|
||||||
# If a message contains a line with the format
|
# It handles requests automatically.
|
||||||
#
|
# This script deals with reading the mail box and dispatching the separate
|
||||||
# package: <URL>
|
# mails to the program that treats one mail.
|
||||||
#
|
# It takes care that there is only one program doing so, by means of locking.
|
||||||
# this package will be automatically downloaded, and the sender of
|
|
||||||
# the message will be notified.
|
|
||||||
#--------------------------------------------------------------#
|
#--------------------------------------------------------------#
|
||||||
|
|
||||||
# the mail boxes
|
# the mail boxes
|
||||||
|
|
||||||
$::LOCKFILE='/projects/CGAL/submissions/autohandle/data/collect_submission.lock';
|
$::LOCKFILE='/projects/CGAL/submissions/autohandle/data/collect_submission.lock';
|
||||||
$::MAIL_IN='/users/geert/PUBLIC/CGAL-submit/incoming-mail';
|
$::MAIL_IN='/users/geert/PUBLIC/CGAL-submit/incoming-mail';
|
||||||
#$::MAIL_OUT='/users/geert/tmp/handled-mail';
|
#$::MAIL_OUT='/users/geert/PUBLIC/CGAL-submit/handled-mail';
|
||||||
$::MAIL_TMP='/users/geert/PUBLIC/CGAL-submit/temp-mail';
|
$::MAIL_TMP='/users/geert/PUBLIC/CGAL-submit/temp-mail';
|
||||||
$::SCRIPT='/projects/CGAL/submissions/autohandle/scripts/collect_submissions';
|
$::SCRIPT='/projects/CGAL/submissions/autohandle/scripts/collect_submissions';
|
||||||
$::MAINTAINER='cgal-submit@cs.uu.nl';
|
|
||||||
|
|
||||||
# program locations
|
# program locations
|
||||||
$::FORMAIL='/projects/CGAL/submissions/autohandle/scripts/formail';
|
$::FORMAIL='/projects/CGAL/submissions/autohandle/scripts/formail';
|
||||||
|
|
@ -36,47 +33,67 @@ $::max_tries_between_warning= int 21600/$::seconds_between_invocations;
|
||||||
|
|
||||||
$ENV{PATH}='/sbin:/usr/sbin:/usr/bsd:/bin:/usr/bin';
|
$ENV{PATH}='/sbin:/usr/sbin:/usr/bsd:/bin:/usr/bin';
|
||||||
|
|
||||||
|
# variable that is set when there is an attempt to kill this process.
|
||||||
$::please_die=0;
|
$::please_die=0;
|
||||||
|
|
||||||
|
$::invoker = $ENV{USER};
|
||||||
|
if ($::invoker =~ /^\s*([-\@\w]+)\s*$/) {
|
||||||
|
$::invoker = "$1\@cs.uu.nl";
|
||||||
|
} else {
|
||||||
|
print STDERR <<"TOTHIER";
|
||||||
|
The script $::SCRIPT did not start because
|
||||||
|
the USER environment value has a strange value.
|
||||||
|
TOTHIER
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
$::hostname = $ENV{HOST};
|
$::hostname = $ENV{HOST};
|
||||||
if ($::hostname =~ /^\s*([-\@\w]+)\s*$/) {
|
if ($::hostname =~ /^\s*([-\@\w]+)\s*$/) {
|
||||||
$::hostname = $1;
|
$::hostname = $1;
|
||||||
} else {
|
} else {
|
||||||
open NOTICE, "|Mail -s \"Collect_submissions not started!\" $::MAINTAINER";
|
print STDERR <<"TOTHIER";
|
||||||
print NOTICE <<"TOTHIER";
|
|
||||||
The script $::SCRIPT did not start because
|
The script $::SCRIPT did not start because
|
||||||
the HOST environment value has a strange value.
|
the HOST environment value has a strange value.
|
||||||
TOTHIER
|
TOTHIER
|
||||||
close NOTICE;
|
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub termination_signal_handler {
|
sub termination_signal_handler {
|
||||||
$::please_die=1;
|
$::please_die=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$::tries = 1;
|
sub initialisation()
|
||||||
$::first_time = 1;
|
{
|
||||||
$SIG{INT} = \&termination_signal_handler;
|
#
|
||||||
$SIG{TERM} = \&termination_signal_handler;
|
# Disable signals that kill this process.
|
||||||
while (! $::please_die) {
|
#
|
||||||
|
|
||||||
|
$SIG{INT} = \&termination_signal_handler;
|
||||||
|
$SIG{TERM} = \&termination_signal_handler;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Try to acquire the lock.
|
||||||
|
# Quit with a message if it fails.
|
||||||
|
#
|
||||||
|
|
||||||
if ( system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
|
if ( system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
|
||||||
--$::tries;
|
open NOTICE, "|Mail -s \"collect_submissions notice\" $::invoker";
|
||||||
if ($::tries < 0) {
|
|
||||||
open NOTICE, "|Mail -s \"Collect_submissions locked!\" $::MAINTAINER";
|
|
||||||
print NOTICE <<"TOTHIER";
|
print NOTICE <<"TOTHIER";
|
||||||
The script $::SCRIPT could not proceed because
|
The script $::SCRIPT could not proceed because
|
||||||
it could not acquire the needed lock on file $::LOCKFILE.
|
it could not acquire the needed lock on file $::LOCKFILE.
|
||||||
TOTHIER
|
TOTHIER
|
||||||
close NOTICE;
|
close NOTICE;
|
||||||
$::tries = $::max_tries_between_warning;
|
exit 1;
|
||||||
}
|
}
|
||||||
} else {
|
#
|
||||||
$::tries = $::max_tries_between_warning;
|
# Now that you have the lock, check to see if there is another process
|
||||||
if ($::first_time) {
|
# executing this program. If so, quit.
|
||||||
|
#
|
||||||
my $logline = `tail -1 $::LOGFILE`;
|
my $logline = `tail -1 $::LOGFILE`;
|
||||||
if ($logline =~ /started/) {
|
if ($logline !~ /stopped/) {
|
||||||
unlink $::LOCKFILE;
|
unlink $::LOCKFILE;
|
||||||
open NOTICE, "|Mail -s \"Collect_submissions busy!\" $::MAINTAINER";
|
open NOTICE, "|Mail -s \"collect_submissions notice\" $::invoker";
|
||||||
print NOTICE <<"TOTHIER";
|
print NOTICE <<"TOTHIER";
|
||||||
The script $::SCRIPT did not proceed because
|
The script $::SCRIPT did not proceed because
|
||||||
there seems to be another process collecting the mail messages.
|
there seems to be another process collecting the mail messages.
|
||||||
|
|
@ -87,16 +104,41 @@ TOTHIER
|
||||||
close NOTICE;
|
close NOTICE;
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
#
|
||||||
|
# We can proceed. Record a message to the log file that this process
|
||||||
|
# takes control of dealing with the mail box.
|
||||||
|
#
|
||||||
open LOGFILE, ">>$::LOGFILE";
|
open LOGFILE, ">>$::LOGFILE";
|
||||||
print LOGFILE "$::hostname $$: started executing on ", `date`;
|
print LOGFILE "$::hostname $$: started executing on ", `date`;
|
||||||
close LOGFILE;
|
close LOGFILE;
|
||||||
$::first_time = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
unlink $::LOCKFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub main_loop()
|
||||||
|
{
|
||||||
|
my $tries_to_go = $::max_tries_between_warning;
|
||||||
|
while (! $::please_die) {
|
||||||
|
if ( system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
|
||||||
|
--$tries_to_go;
|
||||||
|
if ($tries_to_go < 0) {
|
||||||
|
open NOTICE,
|
||||||
|
"|Mail -s \"collect_submissions notice\" $::invoker";
|
||||||
|
print NOTICE <<"TOTHIER";
|
||||||
|
The script $::SCRIPT could not proceed because
|
||||||
|
it could not acquire the needed lock on file $::LOCKFILE.
|
||||||
|
TOTHIER
|
||||||
|
close NOTICE;
|
||||||
|
$tries_to_go = $::max_tries_between_warning;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tries_to_go = $::max_tries_between_warning;
|
||||||
if ( -f $::MAIL_TMP ) {
|
if ( -f $::MAIL_TMP ) {
|
||||||
open NOTICE, "|Mail -s \"Mail box $::MAIL_TMP was not emptied!\" $::MAINTAINER";
|
open NOTICE,
|
||||||
|
"|Mail -s \"collect_submissions notice\" $::invoker";
|
||||||
print NOTICE <<"TOTHIER";
|
print NOTICE <<"TOTHIER";
|
||||||
The script $::SCRIPT has been stopped!
|
The script $::SCRIPT has been stopped,
|
||||||
|
because the temporary mail box $::MAIL_TMP was not emptied.
|
||||||
TOTHIER
|
TOTHIER
|
||||||
close NOTICE;
|
close NOTICE;
|
||||||
unlink $::LOCKFILE;
|
unlink $::LOCKFILE;
|
||||||
|
|
@ -113,10 +155,18 @@ TOTHIER
|
||||||
unlink $::LOCKFILE;
|
unlink $::LOCKFILE;
|
||||||
}
|
}
|
||||||
sleep $::seconds_between_invocations unless $::please_die;
|
sleep $::seconds_between_invocations unless $::please_die;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open LOGFILE, ">>$::LOGFILE";
|
sub finalisation()
|
||||||
print LOGFILE "$::hostname $$: stopped executing at ", `date`;
|
{
|
||||||
close LOGFILE;
|
open LOGFILE, ">>$::LOGFILE";
|
||||||
exit 1;
|
print LOGFILE "$::hostname $$: stopped executing at ", `date`;
|
||||||
|
close LOGFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
initialisation();
|
||||||
|
main_loop();
|
||||||
|
finalisation();
|
||||||
|
exit 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue