mirror of https://github.com/CGAL/cgal
Made sure that only one program is running at any time.
This commit is contained in:
parent
aa8df359d8
commit
ae8396d8d7
|
|
@ -12,9 +12,6 @@ use strict;
|
||||||
# the message will be notified.
|
# the message will be notified.
|
||||||
#--------------------------------------------------------------#
|
#--------------------------------------------------------------#
|
||||||
|
|
||||||
# the amount of time between subsequent scans of the mailbox
|
|
||||||
#$::INCREMENT="30 minutes";
|
|
||||||
|
|
||||||
# the mail boxes
|
# the mail boxes
|
||||||
|
|
||||||
$::LOCKFILE='/projects/CGAL/submissions/autohandle/data/collect_submission.lock';
|
$::LOCKFILE='/projects/CGAL/submissions/autohandle/data/collect_submission.lock';
|
||||||
|
|
@ -40,16 +37,28 @@ $::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';
|
||||||
|
|
||||||
$::please_die=0;
|
$::please_die=0;
|
||||||
|
$::hostname = $ENV{HOST};
|
||||||
|
if ($::hostname =~ /^\s*([-\@\w]+)\s*$/) {
|
||||||
|
$::hostname = $1;
|
||||||
|
} else {
|
||||||
|
open NOTICE, "|Mail -s \"Collect_submissions not started!\" $::MAINTAINER";
|
||||||
|
print NOTICE <<"TOTHIER";
|
||||||
|
The script $::SCRIPT did not start because
|
||||||
|
the HOST environment value has a strange value.
|
||||||
|
TOTHIER
|
||||||
|
close NOTICE;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
sub termination_signal_handler {
|
sub termination_signal_handler {
|
||||||
$::please_die=1;
|
$::please_die=1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$::tries = 1;
|
$::tries = 1;
|
||||||
while (1) {
|
$::first_time = 1;
|
||||||
$SIG{INT} = \&termination_signal_handler;
|
$SIG{INT} = \&termination_signal_handler;
|
||||||
$SIG{TERM} = \&termination_signal_handler;
|
$SIG{TERM} = \&termination_signal_handler;
|
||||||
|
while (! $::please_die) {
|
||||||
if ( system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
|
if ( system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
|
||||||
--$::tries;
|
--$::tries;
|
||||||
if ($::tries < 0) {
|
if ($::tries < 0) {
|
||||||
|
|
@ -63,9 +72,26 @@ TOTHIER
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$::tries = $::max_tries_between_warning;
|
$::tries = $::max_tries_between_warning;
|
||||||
|
if ($::first_time) {
|
||||||
|
my $logline = `tail -1 $::LOGFILE`;
|
||||||
|
if ($logline =~ /started/) {
|
||||||
|
unlink $::LOCKFILE;
|
||||||
|
open NOTICE, "|Mail -s \"Collect_submissions busy!\" $::MAINTAINER";
|
||||||
|
print NOTICE <<"TOTHIER";
|
||||||
|
The script $::SCRIPT did not proceed because
|
||||||
|
there seems to be another process collecting the mail messages.
|
||||||
|
The file $::LOGFILE says:
|
||||||
|
|
||||||
|
$logline
|
||||||
|
TOTHIER
|
||||||
|
close NOTICE;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
open LOGFILE, ">>$::LOGFILE";
|
open LOGFILE, ">>$::LOGFILE";
|
||||||
print LOGFILE "$$: Executing script on ", `date`, "\n";
|
print LOGFILE "$::hostname $$: started executing on ", `date`;
|
||||||
close LOGFILE;
|
close LOGFILE;
|
||||||
|
$::first_time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( -f $::MAIL_TMP ) {
|
if ( -f $::MAIL_TMP ) {
|
||||||
open NOTICE, "|Mail -s \"Mail box $::MAIL_TMP was not emptied!\" $::MAINTAINER";
|
open NOTICE, "|Mail -s \"Mail box $::MAIL_TMP was not emptied!\" $::MAINTAINER";
|
||||||
|
|
@ -74,8 +100,8 @@ print NOTICE <<"TOTHIER";
|
||||||
TOTHIER
|
TOTHIER
|
||||||
close NOTICE;
|
close NOTICE;
|
||||||
unlink $::LOCKFILE;
|
unlink $::LOCKFILE;
|
||||||
exit 1;
|
$::please_die = 1;
|
||||||
}
|
} else {
|
||||||
if ( -f $::MAIL_IN ) {
|
if ( -f $::MAIL_IN ) {
|
||||||
rename($::MAIL_IN, $::MAIL_TMP);
|
rename($::MAIL_IN, $::MAIL_TMP);
|
||||||
if (system("$::FORMAIL -ns $::treat_one_mail_program < $::MAIL_TMP")== 0 )
|
if (system("$::FORMAIL -ns $::treat_one_mail_program < $::MAIL_TMP")== 0 )
|
||||||
|
|
@ -83,11 +109,14 @@ TOTHIER
|
||||||
unlink $::MAIL_TMP;
|
unlink $::MAIL_TMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
unlink $::LOCKFILE;
|
unlink $::LOCKFILE;
|
||||||
}
|
}
|
||||||
$SIG{INT} = 'DEFAULT';
|
sleep $::seconds_between_invocations unless $::please_die;
|
||||||
$SIG{TERM} = 'DEFAULT';
|
|
||||||
exit 1 if $::please_die;
|
|
||||||
sleep $::seconds_between_invocations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open LOGFILE, ">>$::LOGFILE";
|
||||||
|
print LOGFILE "$::hostname $$: stopped executing at ", `date`;
|
||||||
|
close LOGFILE;
|
||||||
|
exit 1;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue