Mail-SpamAssassin
view release on metacpan or search on metacpan
spamd-apache2/bin/apache-spamd.pl view on Meta::CPAN
#!/usr/bin/perl -w
use strict;
use Mail::SpamAssassin::Spamd::Config ();
use Mail::SpamAssassin::Util (); # heavy, loads M::SA
use Sys::Hostname qw(hostname);
use File::Spec ();
use Cwd ();
=head1 NAME
apache-spamd -- start spamd with Apache as backend
=head1 SYNOPSIS
apache-spamd --pidfile ... [ OPTIONS ]
OPTIONS:
--httpd_path=path path to httpd, eg. /usr/sbin/httpd.prefork
--httpd_opt=opt option for httpd (can occur multiple times)
--httpd_directive=line directive for httpd (can occur multiple times)
-k CMD passed to httpd (see L<httpd(1)> for values)
--apxs=path path to apxs, eg /usr/sbin/apxs
--httpd_conf=path just write a config file for Apache and exit
See L<spamd(1)> for other options.
If some modules are not in @INC, invoke this way:
perl -I/path/to/modules apache-spamd.pl \
--httpd_directive "PerlSwitches -I/path/to/modules"
Note: pass the -H / --helper-home-dir option; there is no reasonable default.
=head1 DESCRIPTION
Starts spamd with Apache as a backend. Apache is configured according to
command line options, compatible to spamd where possible and makes sense.
If this script doesn't work for you, complain.
=head1 TODO
* misc MPMs
* testing on different platforms and configurations
* fix FIXME's
* review XXX's
* --create-prefs (?), --help, --virtual-config-dir
* current directory (home_dir_for_helpers?)
=cut
# NOTE: the amount of code here and list of loaded modules doesn't matter;
# we exec() anyway.
# NOTE: no point in using -T, it'd only mess up code with workarounds;
# we don't process any user input but command line options.
my $opt = Mail::SpamAssassin::Spamd::Config->new(
{
defaults => { daemonize => 1, port => 783, },
moreopts => [
qw(httpd_path|httpd-path=s httpd_opt|httpd-opt=s@
httpd_directive|httpd-directive=s@ k:s apxs=s
httpd_conf|httpd-conf=s)
],
}
);
# only standalone spamd implements these options.
# you miss vpopmail? get a real MTA.
for my $option (
qw(round-robin setuid-with-sql setuid-with-ldap socketpath
socketowner socketgroup socketmode paranoid vpopmail)
)
{
die "ERROR: --$option can't be used with apache-spamd\n"
if defined $opt->{$option};
}
#
# XXX: move these options (and sanity checks for them) to M::SA::S::Config?
#
die "ERROR: '$opt->{httpd_path}' does not exist or not executable\n"
if exists $opt->{httpd_path}
and !-f $opt->{httpd_path} || !-x _;
$opt->{httpd_path} ||= 'httpd'; # FIXME: find full path
$opt->{pidfile} ||= '/var/run/apache-spamd.pid' # reasonable default
if -w '/var/run/' && -x _ && !-e '/var/run/apache-spamd.pid';
die "ERROR: --pidfile is mandatory\n" # this seems ugly, but has advantages
unless $opt->{pidfile}; # we won't be able to stop otherwise
$opt->{pidfile} = File::Spec->rel2abs($opt->{pidfile});
if (-d $opt->{pidfile}) {
die "ERROR: can't write pid, '$opt->{pidfile}' directory not writable\n"
unless -x _ && -w _;
$opt->{pidfile} = File::Spec->catfile($opt->{pidfile}, 'apache-spamd.pid');
}
if (exists $opt->{k}) { # XXX: other option name? or not?
die "ERROR: can't use -k with --httpd_conf\n" if exists $opt->{httpd_conf};
## I'm not sure if this toggle idea is a good one...
## useful for development.
$opt->{k} ||= -e $opt->{pidfile} ? 'stop' : 'start';
die "ERROR: -k start|stop|restart|reload|graceful|graceful-stop"
. " or empty for toggle\n"
unless $opt->{k} =~ /^(?:start|stop|restart|reload|graceful(?:-stop)?)$/;
( run in 0.640 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )