File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/restartsrv_spamd
#!/usr/bin/perl
# cpanel - restartsrv_spamd 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 Cpanel::OSSys ();
use Cpanel::CleanupStub ();
use RestartSrv;
$ENV{'TMPDIR'} = '/tmp' if -d '/tmp';
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 $spamd_manualstart = needsmanualstart( $system, 'spamd' );
my $spamdscript = getinitfile( 'spamd', $system );
my $disabled = -e '/etc/spamddisable' ? 1 : 0;
if ( $restart && !$disabled ) {
my $lock_file = '/var/run/restartsrv_spamd.lock';
lock_file($lock_file);
if ( $restart != -1 ) {
system '/scripts/update_sa_rules';
}
if ( my $pid = fork() ) {
waitpid( $pid, 0 );
}
else {
Cpanel::OSSys::setsid();
Cpanel::CleanupStub::daemonclosefds();
if ( $spamdscript && !$spamd_manualstart ) {
nooutputsystem( $spamdscript, 'stop' );
doomedprocess('spamd');
#Bludgeon spamd because it doesn't play nice
system '/scripts/ckillall', '-TERM', 'spamd -d';
if ( $restart != -1 ) {
$ENV{'LANG'} = 'C';
$ENV{'LC_ALL'} = 'C';
system $spamdscript, 'start';
}
}
else {
my $spamdoptions = getspamdopts();
doomedprocess('spamd');
# Bludgeon spamd because it doesn't play nice
if ( $system =~ m/freebsd/i ) {
system '/scripts/ckillall', '-TERM', 'spamd -d';
}
if ( $restart != -1 ) {
if ( -x '/usr/bin/spamd' ) {
$ENV{'LANG'} = 'C';
$ENV{'LC_ALL'} = 'C';
system "/usr/bin/spamd -d $spamdoptions";
}
elsif ( -x '/usr/local/bin/spamd' ) {
$ENV{'LANG'} = 'C';
$ENV{'LC_ALL'} = 'C';
system("/usr/local/bin/spamd -d $spamdoptions");
}
}
}
exit;
}
unlink $lock_file if -e $lock_file;
}
elsif ($status) {
if ($disabled) {
print "spamd is disabled\n";
}
else {
print check_service( 'service' => 'spamd', 'user' => 'root' );
}
}
elsif ($check) {
exit if ($disabled);
my ($spamdstat,$raw_out) = spamdcheck();
if ( $spamdstat == 0 ) {
print "Spamd is not running\nRaw Output: $raw_out\n";
}
}