You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Marcin Kosewski <M....@itl.waw.pl> on 2004/11/18 03:21:37 UTC

PerlRequire script starts two times - how to avoid this

Hi Gurus,

I'm using Apache 1.3.33 with mod_perl 1.29. In Apache httpd.conf file I'm
loading external perl directives using:
    PerlRequire startup.pl

I've checked, that during apache startup 'startup.pl' runs two times. And
I want, that this script runs only once (because I'm allocating there
shared memory areas for later use).

So, question is: how to force Apache to run this script exactly once during
startup.

In my other servers with previous versions of Apache and mod_perl I've used
in startup script directive:
  return 1 if ( getppid() != 1 );
and it solved the problem - commands after this one were executed only
once. But now it doesn't work.


I've tried this in startup.pl:
  WriteToDebugFile( "begin, getppid=".getppid()." getpid=".$$." );
  return 1 if ( getppid() != 1 );
  WriteToDebugFile( "Done" );

And after apache run i've found in debug-file this:
  begin, getppid=1005 getpid=1006
  begin, getppid=1005 getpid=1006


I've checked pid's of starting Apache processes:
1. I've started Apache:
  sh /www/apache_1.3.33/bin/apachectl start 
  (Pid: 1005, Parent: 1004)
2. One process was started
  /www/apache_1.3.33/bin/httpd -f /www/conf/httpd.conf 
  (Pid: 1006, Parent: 1005)
3. After some time (and executing TWO times startup.pl) apache was ready:
   /www/apache_1.3.33/bin/httpd -f /www/conf/httpd.conf
   (Pid:1009, Parent: 1)
   /www/apache_1.3.33/bin/httpd -f /www/conf/httpd.conf
   (Pid: 1012, Parent 1009)
   .
   .
   .
   (other workers)


-- 
 | Marcin Kosewski
 | M.Kosewski@itl.waw.pl
-+------------------------------------------------------------------------
 |

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: PerlRequire script starts two times - how to avoid this

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2004-11-18 at 11:55, John Wittkoski wrote:
> The code is _always_ called twice (i.e. when I do a start OR restart) 
> and $Apache::Server::Starting is always true the first time it's called 
> but not the second and $Apache::Server::ReStarting is always false.
> 
> That is, when starting the server I see:
> 
> Called
> Server is Starting
> Called

With mod_perl 1.29 and Perl 5.8.3 I see this from my startup.pl:
Called
Server is Starting

The versions may make a difference here.  Anyway, there is a simpler way
to make sure you don't do things twice: put them in a module and call
the module via "use" in your startup.pl.

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Apache::Session delete error

Posted by Bart Simpson <ba...@yahoo.com>.
HI. I've been working on this for over a day now.
Truth is i don't really understand the nature of the
problem. Google give many old results for setgid
problems. If some wise perl programmer could help, i'd
be much obliged. 

I'm getting this error when I call
tied(%session)->delete.

-e:   Insecure dependency in unlink while running
setgid at
/usr/lib/perl5/site_perl/5.8.3/Apache/Session/Store/File.pm
line 106.

Here is relevant 106 area.
if (-e $directory.'/'.$session->{data}->{_session_id})
{
        unlink
($directory.'/'.$session->{data}->{_session_id}) ||
            die "Could not remove file: $!";
}

I saw this on perlmonks and untied my session before
processing the template but that didn't help.

[quote]
If you really want to use Apache::Session rather than
something simpler like MLDBM::Sync, I suggest you
treat it as a hot potato, i.e. create the hash, get
what you want in and out of it as fast as you can, and
get rid of it immediately. Don't leave it hanging
around while you do other stuff.
[/quote]

Thank you very much.


		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: PerlRequire script starts two times - how to avoid this

Posted by John Wittkoski <jo...@aol.com>.

Stas Bekman wrote on 11/17/04, 10:34 PM:

 > Marcin Kosewski wrote:
 > > Hi Gurus,
 > >
 > > I'm using Apache 1.3.33 with mod_perl 1.29. In Apache httpd.conf
 > file I'm
 > > loading external perl directives using:
 > >     PerlRequire startup.pl
 > >
 > > I've checked, that during apache startup 'startup.pl' runs two
 > times. And
 > > I want, that this script runs only once (because I'm allocating there
 > > shared memory areas for later use).
 > >
 > > So, question is: how to force Apache to run this script exactly once
 > during
 > > startup.
 >
 > 
http://perl.apache.org/docs/1.0/guide/config.html#Apache_Restarts_Twice_On_Start 

 >
 >


While this does explain why the server needs to restart twice, I thought 
I'd mention for Marcin's sake that with 1.3.x $Apache::Server::Starting 
and $Apache::Server::ReStarting don't (in my experience) work as expected.

When I put this slightly modified code in my httpd.conf:

<Perl>
   open(OUT, ">/tmp/log");
   print OUT "Called\n";
   print OUT "Server is Starting\n"   if $Apache::Server::Starting;
   print OUT "Server is ReStarting\n" if $Apache::Server::ReStarting;
   close(OUT);
</Perl>

(I write to a temp file instead of STDERR because under apache 1.3 
logging to STDERR during startup isn't always redirected...)

The code is _always_ called twice (i.e. when I do a start OR restart) 
and $Apache::Server::Starting is always true the first time it's called 
but not the second and $Apache::Server::ReStarting is always false.

That is, when starting the server I see:

Called
Server is Starting
Called

And when restarting:

Called
Server is Starting
Called

Because of this, you can't actually tell the difference between starting 
and restarting.

I know this has been discussed on the list before, but I just thought 
I'd save him the same frustration I went though trying to do this.


    --John




-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: PerlRequire script starts two times - how to avoid this

Posted by Stas Bekman <st...@stason.org>.
Marcin Kosewski wrote:
> Hi Gurus,
> 
> I'm using Apache 1.3.33 with mod_perl 1.29. In Apache httpd.conf file I'm
> loading external perl directives using:
>     PerlRequire startup.pl
> 
> I've checked, that during apache startup 'startup.pl' runs two times. And
> I want, that this script runs only once (because I'm allocating there
> shared memory areas for later use).
> 
> So, question is: how to force Apache to run this script exactly once during
> startup.

http://perl.apache.org/docs/1.0/guide/config.html#Apache_Restarts_Twice_On_Start

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html