I won't have time to test before Saturday, sorry.  Do you plan to 
support this in the next update?  That's mostly what I'm looking for.

Mark Martinec wrote:
>> amavisd apparently doesn't
>> check to see that it is running -- however, it apparently
>> steps on some of its own resources.
> 
> At first I didn't have the intention of checking if multiple
> instances are running, which may be a regular condition,
> but each must have it's own working directory / pid file /
> lock file / port.  Nevertheless, adding such a check may prevent
> simple mistakes, and seeing that Postfix also checks for
> already running daemon, here is a patch. It is somewhat
> lengthy as it required moving portions of code around.
> Please see that it works as one might expect.
> 
>   Mark
> 
> 
> --- amavisd~  Mon Oct  2 02:05:20 2006
> +++ amavisd   Thu Oct 12 19:20:37 2006
> @@ -9766,8 +9766,11 @@
>    }
>  }
> [EMAIL PROTECTED] <= 1  or die sprintf("Only one command line parameter 
> allowed: %s\n",
> -                           join(" ",@ARGV));
>  my($cmd) = lc($ARGV[0]);
> -
> +if (@ARGV > 1) {
> +  die "$myversion: Only one command line parameter allowed: %s\n" .
> +      join(" ",@ARGV) . usage();
> +} elsif ($cmd !~ /^(?:start|debug|debug-sa|foreground|reload|stop)?\z/) {
> +  die "$myversion: Unknown command line parameter: $cmd\n\n" . usage();
> +}
>  if (defined $desired_user && ($> == 0 || $< == 0)) {   # drop privileges 
> early
>    local($1);
> @@ -10012,53 +10015,69 @@
>  }
>  
> +# is amavisd daemon already running?
> +my($amavisd_pid);  # obtain PID of the currently running amavisd daemon
> +{ my($pidf) = defined $pid_file_override ? $pid_file_override : $pid_file;
> +  $pidf ne '' or die "Config parameter \$pid_file not defined";
> +  my($errn) = stat($pidf) ? 0 : 0+$!;
> +  if ($errn == ENOENT) {
> +    die "The amavisd daemon is not running, no PID file $pidf\n"
> +      if $cmd =~ /^(?:reload|stop)\z/;
> +  } elsif ($errn != 0) {
> +    die "PID file $pidf is inaccessible: $!\n";
> +  } else {
> +    local($1); my($ln); my($pidf_h) = IO::File->new;
> +    $pidf_h->open($pidf,'<') or die "Can't open PID file $pidf: $!";
> +    for ($! = 0; defined($ln=$pidf_h->getline); $! = 0) {
> +      $amavisd_pid = $1  if $ln =~ /^(\d+)$/ && $1>0 && 
> !defined($amavisd_pid);
> +    }
> +    defined $ln || $!==0  or die "Error reading from file $pidf: $!";
> +    $pidf_h->close or die "Error closing file $pidf: $!";
> +    defined($amavisd_pid)  or die "Invalid process ID in file $pidf";
> +    $amavisd_pid = untaint($amavisd_pid);
> +    if (!kill(0,$amavisd_pid)) { undef $amavisd_pid };  # no such process
> +  }
> +};
>  # act on command line parameter in $cmd
>  my($killed_amavisd_pid); my($kill_sig_used);
> -if ($cmd =~ /^(start|debug|debug-sa|foreground)?\z/) {
> +if ($cmd =~ /^(?:start|debug|debug-sa|foreground)?\z/) {
> +  !defined($amavisd_pid)
> +    or die "The amavisd daemon is already running: PID [$amavisd_pid]\n";
>    $DEBUG=1      if $cmd eq 'debug';
>    $daemonize=0  if $cmd eq 'foreground';
>    $daemonize=0, $sa_debug=1  if $cmd eq 'debug-sa';
> -} elsif ($cmd !~ /^(reload|stop)\z/) {
> -  die "$myversion: Unknown argument: $cmd\n\n" . usage();
> +} elsif ($cmd !~ /^(?:reload|stop)\z/) {
> +  die "$myversion: Unknown command line parameter: $cmd\n\n" . usage();
>  } else {  # stop or reload
> -  eval {  # first stop a running daemon
> -    my($pidf) = defined $pid_file_override ? $pid_file_override : $pid_file;
> -    $pidf ne '' or die "Config parameter \$pid_file not defined";
> -    my($errn) = stat($pidf) ? 0 : 0+$!;
> -    $errn != ENOENT or die "No PID file $pidf\n";
> -    $errn == 0      or die "PID file $pidf inaccessible: $!";
> -    my($ln); my($amavisd_pid); my($pidf_h) = IO::File->new;
> -    $pidf_h->open($pidf,'<') or die "Can't open file $pidf: $!";
> -    for ($! = 0; defined($ln=$pidf_h->getline); $! = 0) {
> -      chomp($ln);
> -      $amavisd_pid = $ln  if $ln =~ /^\d+\z/ && !defined($amavisd_pid);
> -    }
> -    defined $ln || $!==0  or die "Error reading from $pidf: $!";
> -    $pidf_h->close or die "Error closing file $pidf: $!";
> -    defined($amavisd_pid) or die "Invalid PID in the $pidf";
> -    $amavisd_pid = untaint($amavisd_pid);
> -    $kill_sig_used = 'TERM';
> -    kill($kill_sig_used,$amavisd_pid)
> -      or die "Can't SIGTERM amavisd[$amavisd_pid]: $!";
> -    my($waited) = 0; my($sigkill_sent) = 0; my($delay) = 1;  # seconds
> -    for (;;) {  # wait for the old running daemon to go away
> -      sleep($delay); $waited += $delay; $delay = 5;
> -      if (!kill(0,$amavisd_pid))  # is the old daemon still there?
> -        { $killed_amavisd_pid = $amavisd_pid; last }  # old proc is gone, 
> done
> -      if ($waited < 60 || $sigkill_sent) {
> -        print STDERR "Waiting for the process [$amavisd_pid] to terminate\n";
> -      } else {  # use stronger hammer
> -        print STDERR "Sending SIGKILL to amavisd[$amavisd_pid]\n";
> -        $kill_sig_used = 'KILL';
> -        kill($kill_sig_used,$amavisd_pid)
> -          or warn "Can't SIGKILL amavisd[$amavisd_pid]: $!";
> -        $sigkill_sent = 1;
> +  if (!defined($amavisd_pid)) { die "The amavisd daemon is not running\n" }
> +  else {  # first stop a running daemon
> +    eval {
> +      $kill_sig_used = 'TERM';
> +      kill($kill_sig_used,$amavisd_pid)
> +        or die "Can't SIGTERM amavisd[$amavisd_pid]: $!";
> +      my($waited) = 0; my($sigkill_sent) = 0; my($delay) = 1;  # seconds
> +      for (;;) {  # wait for the old running daemon to go away
> +        sleep($delay); $waited += $delay; $delay = 5;
> +        if (!kill(0,$amavisd_pid))  # is the old daemon still there?
> +          { $killed_amavisd_pid = $amavisd_pid; last } # old proc is gone, 
> done
> +        if ($waited < 60 || $sigkill_sent) {
> +          print STDERR "Waiting for the process [$amavisd_pid] to 
> terminate\n";
> +        } else {  # use stronger hammer
> +          print STDERR "Sending SIGKILL to amavisd[$amavisd_pid]\n";
> +          $kill_sig_used = 'KILL';
> +          kill($kill_sig_used,$amavisd_pid)
> +            or warn "Can't SIGKILL amavisd[$amavisd_pid]: $!";
> +          $sigkill_sent = 1;
> +        }
>        }
> -    }
> -  };
> -  if ($@ ne '') { chomp($@); die "$@, can't $cmd the process\n" }
> -  my($msg) = "Daemon [$killed_amavisd_pid] terminated by SIG$kill_sig_used";
> -  if ($cmd eq 'stop') { print STDERR "$msg\n"; exit 0 }
> -  print STDERR "$msg, waiting for dust to settle...\n";
> -  sleep 5;  # wait for the TCP socket to be released
> +    };
> +    if ($@ ne '') { chomp($@); die "$@, can't $cmd the process\n" }
> +  }
> +  my($msg) = !defined($killed_amavisd_pid) ? undef :
> +             "Daemon [$killed_amavisd_pid] terminated by SIG$kill_sig_used";
> +  if ($cmd eq 'stop') { print STDERR "$msg\n" if defined $msg;  exit(0) }
> +  if (defined $killed_amavisd_pid) {
> +    print STDERR "$msg, waiting for dust to settle...\n";
> +    sleep 5;  # wait for the TCP socket to be released
> +  }
>    print STDERR "becoming a new daemon...\n";
>  }
> 
> 
> 
> 
> Mark


-- 
Jo Rhett
Senior Network Engineer
Network Consonance

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
AMaViS-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/amavis-user
AMaViS-FAQ:http://www.amavis.org/amavis-faq.php3
AMaViS-HowTos:http://www.amavis.org/howto/

Reply via email to