diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-07-13 15:38:15 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-07-13 15:38:15 +0400 |
commit | 44c8c04604f42725c7da6853f94faf4e0d47f9a8 (patch) | |
tree | 2ed76c60b18fbd709d5cb4aefb5c29014c2417bf /utils | |
parent | cc8abc2714383fa1d204ce9ec3d94e093f9c14af (diff) | |
download | rspamd-44c8c04604f42725c7da6853f94faf4e0d47f9a8.tar.gz rspamd-44c8c04604f42725c7da6853f94faf4e0d47f9a8.zip |
* Some improvements to redirector
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/redirector.pl.in | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/utils/redirector.pl.in b/utils/redirector.pl.in index 64213b5ca..9dd6a24f0 100755 --- a/utils/redirector.pl.in +++ b/utils/redirector.pl.in @@ -85,8 +85,13 @@ sub write_log { if ($cfg{do_log}) { my $now_string = strftime "%F %T", localtime; - LOG->autoflush(1); - print LOG "[$now_string]: $remote_ip: $str\n"; + if (!$cfg{debug}) { + LOG->autoflush(1); + print LOG "[$now_string]: $remote_ip: $str\n"; + } + else { + print STDERR "[$now_string]: $remote_ip: $str\n"; + } } } @@ -418,12 +423,19 @@ sub process_input { ############################### Main code fragment ################################## + # Try to eval config file if (-f $cfg{cfg_file}) { my $config = read_file ($cfg{cfg_file}); eval $config; } +while (my $arg = shift @ARGV) { + if ($arg eq '-debug' || $arg eq '-d') { + $cfg{debug} = 1; + } +} + die "Process is already started, check $cfg{pidfile}" if Proc::PidUtil::is_running($cfg{pidfile}); # Do daemonization @@ -437,8 +449,10 @@ if ($> == 0) { $) = $( = $gid; } -die "Cannot write to pidfile $cfg{pidfile}" if ! open(PID, "> $cfg{pidfile}"); -close(PID); +if (!$cfg{debug}) { + die "Cannot write to pidfile $cfg{pidfile}" if ! open(PID, "> $cfg{pidfile}"); + close(PID); +} # Reopen log on SIGUSR1 $SIG{USR1} = sub { $do_reopen_log = 1; }; @@ -446,12 +460,19 @@ $SIG{INT} = sub { $poe_kernel->stop(); }; $SIG{QUIT} = sub { $poe_kernel->stop(); }; $SIG{PIPE} = 'IGNORE'; +if (!$cfg{debug}) { + $cfg{do_log} = 1 if open(LOG, ">> $cfg{logfile}"); +} +else { + $cfg{do_log} = 1; +} -$cfg{do_log} = 1 if open(LOG, ">> $cfg{logfile}"); - -Proc::PidUtil::make_pidfile($cfg{pidfile}, $$) or die "Cannot write pidfile $cfg{pidfile}"; +if (!$cfg{debug}) { + Proc::PidUtil::make_pidfile($cfg{pidfile}, $$) or die "Cannot write pidfile $cfg{pidfile}"; +} # Init memcached connection +write_log ("", "Starting memcached connection"); $memd = new Cache::Memcached::Fast({ servers => $cfg{memcached_servers}, connect_timeout => 0.2, @@ -477,6 +498,7 @@ POE::Component::Client::HTTP->spawn( ), ); +write_log ("", "Starting HTTP server"); POE::Component::Server::TCP->new ( Alias => "", Port => $cfg{port}, |