[Mimedefang] clamd statility issues?

Martin Blapp mb at imp.ch
Thu Mar 8 12:13:36 EST 2007


Hi,

This is the perl script we use to test the state of clamd to
be able to kill and restart it (if it hangs). Maybe someone
finds it useful. We do :-)

This may work only on FreeBSD, since we use telnet to connect to
a local unix domain socket. If you use different operating systems
you'll need to connect to a tcp adress.

--
Martin

#!/usr/bin/perl

use Expect;

$return = &check_clamd();

if ($return == 4) {
 	print "Successful connected to clamd, exit\n";
 	exit(0);
} else {
 	sleep 2;
 	$return = &check_clamd();
 	if ($return == 4) {
 		print "Successful connected to clamd, exit\n";
 		exit(0);
 	} elsif ($return == 1) {
 		print "ERROR: Connect to clamd failed, error\n";
 	}
 	exit(2);
}

sub check_clamd {
 	#
 	# Open the clamd_socket and disable expect debug
 	# and log_stdout.
 	#
 	my $exp = new Expect;
 	$exp->debug(0);
 	$exp->raw_pty(1);
 	$exp->log_stdout(0);
 	$exp->spawn("telnet /var/run/clamav/clamd.sock")
 		or return 0;;
 	my $spawn_ok;

 	$timeout = 10;
 	$clammatch = $exp->expect($timeout,
 	[
 		qr'No connection.|Connected to .*',
 		sub {
 			$spawn_ok = 1;
 			my $fh = shift;
 			$fh->send("PING\n");
 			exp_continue;
 	       }
 	],
 	[
 		eof =>
 			sub {
 				if ($spawn_ok) {
 					print "ERROR: Premature EOF in login.\n";
 					return 1;
 				} else {
 					print "ERROR: Could not spawn telnet.\n";
 					return 1;
 				}
 			}
 	],
 	[
 		timeout =>
 			sub {
 				print "ERROR: No login.\n";
 				return 1;
 			}
 	],
 		'-re', qr'PONG'
 	);

 	return $clammatch;
}


Martin Blapp, <mb at imp.ch> <mbr at FreeBSD.org>
------------------------------------------------------------------
ImproWare AG, UNIXSP & ISP, Zurlindenstrasse 29, 4133 Pratteln, CH
Phone: +41 61 826 93 00 Fax: +41 61 826 93 01
PGP: <finger -l mbr at freebsd.org>
PGP Fingerprint: B434 53FC C87C FE7B 0A18 B84C 8686 EF22 D300 551E
------------------------------------------------------------------




More information about the MIMEDefang mailing list