File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/restartsrv_clamd
#!/usr/bin/perl
# cpanel - restartsrv_clamd Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel', '/scripts'; }
use strict;
use RestartSrv;
use Cpanel::OSSys ();
eval {
local $SIG{'__DIE__'};
require Cpanel::Rlimit;
Cpanel::Rlimit::set_rlimit_to_infinity();
};
setuppath();
my ( $system, $nodename, $release, $version, $machine ) = Cpanel::OSSys::uname();
my ( $restart, $check, $status ) = parseargv();
my $service = 'clamd';
my $processowner = 'root';
my $disabled = -e '/etc/clamddisable' ? 1 : 0;
my ( $clamd, $msg ) = find_clamd();
if ($restart) {
exit if ($disabled);
my $lock_file = '/var/run/restartsrv_clamd.lock';
lock_file($lock_file);
#--restart or nothing (restart service)
if ($clamd) {
my $dl = `strings $clamd`;
$dl =~ m/^(.*\/clam(?:av|d).conf)/m; # multi-line
my $conf = $1;
if ( !$conf ) { $conf = -e '/etc/clamav.conf' ? '/etc/clamav.conf' : '/etc/clamd.conf'; }
my $socket = '';
open( CONF, "<", $conf );
while (<CONF>) {
if (/^[\s\t]*LocalSocket[\s\t]*(\S+)/i) {
$socket = $1;
}
}
close(CONF);
if ( $socket eq '' ) { $socket = '/var/clamd'; }
system( '/scripts/ckillall', '-TERM', 'clamd' );
system( 'killall', '-TERM', 'clamd' );
system( 'killall', '-9', 'clamd' );
system( '/scripts/ckillall', '-9', 'clamd' );
unlink($socket);
if ( $restart != -1 ) {
system($clamd);
}
}
else { print $msg; }
unlink $lock_file if -e $lock_file;
}
elsif ($status) {
#--status (show ps)
if ($disabled) {
print "$service is disabled\n";
}
else {
print check_service( 'service' => $service, 'user' => $processowner );
}
}
elsif ($check) {
exit if ($disabled);
my ( $clamdscan, $clammsg ) = find_clamdscan();
if ( $clamdscan ne '' ) {
my $result = `$clamdscan --quiet --no-summary /etc/passwd 2>&1`;
if ( $result =~ m/(?:refused|No such|Can't connect|ERROR)/i ) {
print "$service is not running or is crashed.\n";
}
}
else {
print "$service is not installed\n";
}
}
sub find_clamd {
my $clambin = '';
my @LOC = qw( /usr/sbin/clamd /usr/local/sbin/clamd /usr/bin/clamd /usr/local/bin/clamd );
foreach my $loc (@LOC) {
if ( -e $loc ) { return ( $loc, undef ); }
else { $msg = "Unable to locate clamd\n"; }
}
return ( $clambin, $msg );
}
sub find_clamdscan {
my $clambin = '';
my @LOC = qw( /usr/sbin/clamdscan /usr/local/sbin/clamdscan /usr/bin/clamdscan /usr/local/bin/clamdscan );
foreach my $loc (@LOC) {
if ( -e $loc ) { return ( $loc, undef ); }
else { $msg = "Unable to locate clamdscan\n"; }
}
return ( $clambin, $msg );
}