Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCGI scripts will not always restart when they are updated #58

Merged
merged 2 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/cgi/sympa_soap_server.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ use Sympa::Log;
use Sympa::SOAP;
use Sympa::SOAP::Transport;

my $birthday = time;

## Load sympa config
unless (Conf::load()) {
printf STDERR
Expand Down Expand Up @@ -83,12 +81,8 @@ my $all_lists = Sympa::List::get_lists('*');
# Soap part
##############################################################################

my $server = Sympa::SOAP::Transport->new();

$server->dispatch_with({'urn:sympasoap' => 'Sympa::SOAP'});
#$server->dispatch_to('--modulesdir--', 'Sympa::SOAP');

$server->handle($birthday);
Sympa::SOAP::Transport->new(cookie_expire => $Conf::Conf{'cookie_expire'})
->dispatch_with({'urn:sympasoap' => 'Sympa::SOAP'})->handle;

__END__

Expand Down
19 changes: 10 additions & 9 deletions src/cgi/wwsympa.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ unless (Conf::data_structure_uptodate()) {
our %in;
my $query;

my $birthday = time;
my $birthday = [stat $PROGRAM_NAME]->[9];

my $bulk = Sympa::Bulk->new;

Expand Down Expand Up @@ -1965,14 +1965,15 @@ while ($query = new_loop()) {
send_html('main.tt2');
}

# exit if wwsympa.fcgi itself has changed
if ($ENV{'SCRIPT_FILENAME'}
and Sympa::Tools::File::get_mtime($ENV{'SCRIPT_FILENAME'}) >
$birthday) {
$log->syslog('notice',
'Exiting because %s has changed since fastcgi server started',
$ENV{'SCRIPT_FILENAME'});
exit(0);
# Exit if wwsympa.fcgi itself has changed.
if (defined $birthday) {
my $age = [stat $PROGRAM_NAME]->[9];
if (defined $age and $birthday != $age) {
$log->syslog('notice',
'Exiting because %s has changed since FastCGI server started',
$PROGRAM_NAME);
exit(0);
}
}

}
Expand Down
45 changes: 31 additions & 14 deletions src/lib/Sympa/SOAP/Transport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,30 @@ package Sympa::SOAP::Transport;

use strict;
use warnings;
use English qw(-no_match_vars);
use SOAP::Transport::HTTP;

use Sympa::Log;
use Sympa::Session;
use Sympa::Tools::File;
use Sympa::Tools::WWW;

# 'base' pragma doesn't work here
our @ISA = qw(SOAP::Transport::HTTP::FCGI);

my $log = Sympa::Log->instance;

sub new {
my $class = shift;
return $class if ref $class;
my %options = @_;

my $self = $class->SUPER::new();
$self->{_ss_birthday} = [stat $PROGRAM_NAME]->[9] if $PROGRAM_NAME;
$self->{_ss_cookie_expire} = $options{cookie_expire} || 0;

$self;
}

sub request {
my $self = shift;

Expand Down Expand Up @@ -84,11 +99,9 @@ sub response {

if (my $response = $_[0]) {
if (defined $ENV{'SESSION_ID'}) {
my $expire = $main::param->{'user'}{'cookie_delay'}
|| $Conf::Conf{'cookie_expire'};
my $cookie =
Sympa::Session::soap_cookie2($ENV{'SESSION_ID'},
$ENV{'SERVER_NAME'}, $expire);
$ENV{'SERVER_NAME'}, $self->{_ss_cookie_expire});
$response->headers->push_header('Set-Cookie2' => $cookie);
}
}
Expand All @@ -97,25 +110,29 @@ sub response {
}

## Redefine FCGI's handle subroutine
sub handle ($$) {
my $self = shift->new;
my $birthday = shift;
sub handle {
my $self = shift->new;

my ($r1, $r2);
my $fcgirq = $self->{_fcgirq};

## If fastcgi changed on disk, die
## Apache will restart the process
while (($r1 = $fcgirq->Accept()) >= 0) {

$r2 = $self->SOAP::Transport::HTTP::CGI::handle;

if (Sympa::Tools::File::get_mtime($ENV{'SCRIPT_FILENAME'}) >
$birthday) {
exit(0);
# Exit if script itself has changed.
my $birthday = $self->{_ss_birthday};
if (defined $birthday and $PROGRAM_NAME) {
my $age = [stat $PROGRAM_NAME]->[9];
if (defined $age and $birthday != $age) {
$log->syslog(
'notice',
'Exiting because %s has changed since FastCGI server started',
$PROGRAM_NAME
);
exit(0);
}
}
# print
# "Set-Cookie: sympa_altemails=olivier.salaun%40cru.fr; path=/; expires=Tue , 19-Oct-2004 14 :08:19 GMT\n";
}
return undef;
}
Expand Down