You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris Ochs <ch...@paymentonline.net> on 2004/08/26 21:57:55 UTC

reading from STDIN on startup

this is apache 1.3.29/mod_perl 1.28

I use connect_on_init for database connections, and I want to read the
password from STDIN instead of putting the password into the startup.pl
file.  I was reading that apache initializes the modules twice when it
starts up, but I'm confused by the behavior I am getting with the following
code.  It appears to run twice, with the first run setting $my::dbpass fine,
and on the second it contains nothing.   I can't see how to get $my::dbpass
to persist through the second init.  Any ideas on how to do this?

Chris

$my::dbpass = <STDIN> unless defined $my::dbpass;
chop $my::dbpass;

# for testing purposes
   open(OUT, ">>/tmp/db");
   print OUT "$my::dbpass";
   close OUT;







-- 
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: reading from STDIN on startup

Posted by Chris Ochs <ch...@paymentonline.net>.
> > I'm also confused about the documentation for PerlRequire.  It say's
that
> > files loaded via PerlRequire are compiled only once, but my startup.pl
file
> > is definitly being compiled twice.
>
> My impression is that it's just broken, since I recall seeing the same
> behavior.  This has come up before, but no one seems to know quite why
> it doesn't work.  It's typically not much of an issue since the average
> startup.pl just does 'use Foo', and the use statement will only load Foo
> once.
>
> As a workaround, see the $Apache::Server::ReStarting variable in the
> docs or load your startup.pl like this:
> <Perl>use startup.pl;</Perl>
>
> - Perrin
>
I tried the Apache::Server::Starting/Restarting variables.  When using
apachectl startssl, Starting =1 both times that startup.pl is compiled, and
Restarting =0 on both, so those don't work as they should either I guess.

What does work is just writing out the value to a temp file on the first
compile, and reading it on the second then deleting it.  Kind of a hack but
better than just having the password hard coded in the config file.

Chris


>
> -- 
> 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
>
>


-- 
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: reading from STDIN on startup

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2004-08-26 at 16:28, Chris Ochs wrote:
> I'm also confused about the documentation for PerlRequire.  It say's that
> files loaded via PerlRequire are compiled only once, but my startup.pl file
> is definitly being compiled twice.

My impression is that it's just broken, since I recall seeing the same
behavior.  This has come up before, but no one seems to know quite why
it doesn't work.  It's typically not much of an issue since the average
startup.pl just does 'use Foo', and the use statement will only load Foo
once.

As a workaround, see the $Apache::Server::ReStarting variable in the
docs or load your startup.pl like this:
<Perl>use startup.pl;</Perl>

- 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


Re: reading from STDIN on startup

Posted by Chris Ochs <ch...@paymentonline.net>.
I'm also confused about the documentation for PerlRequire.  It say's that
files loaded via PerlRequire are compiled only once, but my startup.pl file
is definitly being compiled twice.  Maybe there is something else in my
config that would cause it?  Or am I misunderstanding something?

Chris

----- Original Message ----- 
From: "Chris Ochs" <ch...@paymentonline.net>
To: <mo...@perl.apache.org>
Sent: Thursday, August 26, 2004 12:57 PM
Subject: reading from STDIN on startup


>
> this is apache 1.3.29/mod_perl 1.28
>
> I use connect_on_init for database connections, and I want to read the
> password from STDIN instead of putting the password into the startup.pl
> file.  I was reading that apache initializes the modules twice when it
> starts up, but I'm confused by the behavior I am getting with the
following
> code.  It appears to run twice, with the first run setting $my::dbpass
fine,
> and on the second it contains nothing.   I can't see how to get
$my::dbpass
> to persist through the second init.  Any ideas on how to do this?
>
> Chris
>
> $my::dbpass = <STDIN> unless defined $my::dbpass;
> chop $my::dbpass;
>
> # for testing purposes
>    open(OUT, ">>/tmp/db");
>    print OUT "$my::dbpass";
>    close OUT;
>
>
>
>
>
>
>
> -- 
> 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
>
>


-- 
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