Re: Apache::Registry and -M

2000-01-13 Thread Stas Bekman

> > "Stas" == Stas Bekman <[EMAIL PROTECTED]> writes:
> 
> Stas> Apache::StatINC is perfect for development stage, if you need the same
> Stas> behavior for just a few files on production server, see:
> Stas> http://perl.apache.org/guide/porting.html#Reloading_Modules_and_Required_F
> 
> I don't know if this is in your guide, but I stopped using StatINC a
> while ago when it kept stat'ing all over creation for every request,

But it's OK for development server, I don't feel the overhead, do you?
Or did you use StatINC on your production box?

> and then never quite got the re-import right.

Randal, it would help immensely if you could explain about what happens
with exported symbols when module gets reloaded. I understand that they
just stay untouched since StatINC doesn't call import, because it doesn't
know what to import. and there is no 'reset' call or something that flash
the namespace called, so why should be any problem with re-import?

I understand that you are talking about the case where you modify a module
and add a new symbol to be exported. The symbol wouldn't be imported with
StatINC.  Otherwise there shouldn't be any problem. 

If my understanding is correct, your observation is correct and I'll add
it to the guide. But at large, how much symbols do you add to the export
list? It happens very rarely, IMHO. 

> Instead, any module that I'm likely to change during the current server
> restart, I add this:
> 
> sub handler { # the beginning of the request
>   use Stonehenge::Reload; goto &handler if Stonehenge::Reload->reload_me;
>   ...
> }

> When I'm finally done tweaking the module, I remove the line, and it
> reloads one last time, never to watch the file again.
> 
> Here's Stonehenge::Reload:

I don't see where you actually pass the list of symbols to be reimported?
Actually what we have here is a StatINC code that forced to be executed on
the module you develop and not for all loaded modules. Did I miss
something?

> 
> package Stonehenge::Reload;
> 
> use vars qw($VERSION);
> $VERSION = (qw$Revision: 1.1 $ )[-1];
> 
> use Apache::Log;
> 
> my %mtime;
> 
> sub reload_me {
>   goto &reload_me if &_reload_caller; # test myself first
>   goto &_reload_caller;   # now test for caller
> }
> 
> sub _reload_caller {
>   my $file = (caller)[1];
> 
>   ## Apache->server->log->notice("$$ is testing $file with $mtime{$file}");
> 
>   return 0 if exists $mtime{$file} and $mtime{$file} == -M $file;
>   ## Apache->server->log->notice("$$ is recompiling $file");
>   delete @INC{grep $INC{$_} eq $file, keys %INC};
>   my $old = \&{(caller(1))[3]};
>   do $file;
>   my $new = \&{(caller(1))[3]};
>   ## Apache->server->log->notice("$$ got $old => $new for $file");
>   return 0 if $old == $new;   # safety
>   $mtime{$file} = -M $file;
>   return 1;
> }
> 
> sub import {
>   my $file = (caller)[1];
>   ## Apache->server->log->notice("$$ is importing ",__PACKAGE__," into $file");
>   $mtime{$file} = -M $file;
> }
> 
> BEGIN {
>   __PACKAGE__->import;# for self reload watching
> };
> 
> 1;
> 
> 
> 
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
> 



___
Stas Bekmanmailto:[EMAIL PROTECTED]  http://www.stason.org/stas
Perl,CGI,Apache,Linux,Web,Java,PC http://www.stason.org/stas/TULARC
perl.apache.orgmodperl.sourcegarden.org   perlmonth.comperl.org
single o-> + single o-+ = singlesheavenhttp://www.singlesheaven.com



Re: Apache::Registry and -M

2000-01-12 Thread Vivek Khera

> "BM" == Bill Moseley <[EMAIL PROTECTED]> writes:

BM> I'd like to be able to move the updated script and module into place and
BM> either do a -USR1 restart or just wait for the Apache processes to go
BM> through their normal life cycle.  As is, it seems as if I have to bring

Well, you can do it in an order that will let you keep working fine.

Since you are adding functions to your modules, just move them in
place first, send the USR1 signal to make all children exit.  Now,
move your script in place.  The children will notice the change and
any that had the old one will restart, but they already have your new
modules.



Re: Apache::Registry and -M

2000-01-12 Thread Randal L. Schwartz

> "Stas" == Stas Bekman <[EMAIL PROTECTED]> writes:

Stas> Apache::StatINC is perfect for development stage, if you need the same
Stas> behavior for just a few files on production server, see:
Stas> http://perl.apache.org/guide/porting.html#Reloading_Modules_and_Required_F

I don't know if this is in your guide, but I stopped using StatINC a
while ago when it kept stat'ing all over creation for every request,
and then never quite got the re-import right.

Instead, any module that I'm likely to change during the current server
restart, I add this:

sub handler { # the beginning of the request
  use Stonehenge::Reload; goto &handler if Stonehenge::Reload->reload_me;
  ...
}

When I'm finally done tweaking the module, I remove the line, and it
reloads one last time, never to watch the file again.

Here's Stonehenge::Reload:

package Stonehenge::Reload;

use vars qw($VERSION);
$VERSION = (qw$Revision: 1.1 $ )[-1];

use Apache::Log;

my %mtime;

sub reload_me {
  goto &reload_me if &_reload_caller; # test myself first
  goto &_reload_caller; # now test for caller
}

sub _reload_caller {
  my $file = (caller)[1];

  ## Apache->server->log->notice("$$ is testing $file with $mtime{$file}");

  return 0 if exists $mtime{$file} and $mtime{$file} == -M $file;
  ## Apache->server->log->notice("$$ is recompiling $file");
  delete @INC{grep $INC{$_} eq $file, keys %INC};
  my $old = \&{(caller(1))[3]};
  do $file;
  my $new = \&{(caller(1))[3]};
  ## Apache->server->log->notice("$$ got $old => $new for $file");
  return 0 if $old == $new; # safety
  $mtime{$file} = -M $file;
  return 1;
}

sub import {
  my $file = (caller)[1];
  ## Apache->server->log->notice("$$ is importing ",__PACKAGE__," into $file");
  $mtime{$file} = -M $file;
}

BEGIN {
  __PACKAGE__->import;  # for self reload watching
};

1;



-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Re: Apache::Registry and -M

2000-01-12 Thread Stas Bekman

> >From my quick look at Registry.pm it looks like there's no way to disable
> the feature where a script will be re-compiled if it changes on disk.

* take a look at Apache::RegistryNG
* move the code into a module and require from the 2 lines script

> Is this correct?
> 
> This is a problem if I update both the main script, and modules used by the
> script. For example, adding a new subroutine to a module and then calling
> it from the main Registry script.  The main script will be recompiled, but
> not the module, so I'll get an undefinded subroutine called.
> 
> I'm not using Apache::StatINC - the module isn't in the @INC path at startup.
> 
> I'd like to be able to move the updated script and module into place and
> either do a -USR1 restart or just wait for the Apache processes to go
> through their normal life cycle.  As is, it seems as if I have to bring
> down the server, move in the updated scripts in, and restart.  Not the most
> graceful process.

Apache::StatINC is perfect for development stage, if you need the same
behavior for just a few files on production server, see:
http://perl.apache.org/guide/porting.html#Reloading_Modules_and_Required_F

___
Stas Bekmanmailto:[EMAIL PROTECTED]  http://www.stason.org/stas
Perl,CGI,Apache,Linux,Web,Java,PC http://www.stason.org/stas/TULARC
perl.apache.orgmodperl.sourcegarden.org   perlmonth.comperl.org
single o-> + single o-+ = singlesheavenhttp://www.singlesheaven.com



Re: Apache::Registry and -M

2000-01-11 Thread Michael Hall

On Tue, Jan 11, 2000 at 05:18:00PM -0800, Jeffrey W. Baker wrote:

> From my quick look at Registry.pm it looks like there's no way to disable
> the feature where a script will be re-compiled if it changes on disk.
> 
> Is this correct?
> 
> This is a problem if I update both the main script, and modules used by the
> script. For example, adding a new subroutine to a module and then calling
> it from the main Registry script.  The main script will be recompiled, but
> not the module, so I'll get an undefinded subroutine called.
> 
> I'm not using Apache::StatINC - the module isn't in the @INC path at startup.
> 
> I'd like to be able to move the updated script and module into place and
> either do a -USR1 restart or just wait for the Apache processes to go
> through their normal life cycle.  As is, it seems as if I have to bring
> down the server, move in the updated scripts in, and restart.  Not the most
> graceful process.

  May be mistaken but doesn't RegistryBB skip the recompile checks and
just compiles once ? Seem to remember it being 'bare bones' and didn't
do the 'stat's and stuff.

--
When she hauled ass, it took three trips.

Mike Hall,
Unix Admin   - Rock Island Communications   <[EMAIL PROTECTED]>
System Admin - riverside.org<[EMAIL PROTECTED]>



Re: Apache::Registry and -M

2000-01-11 Thread Jeffrey W. Baker

Bill Moseley wrote:
> 
> >From my quick look at Registry.pm it looks like there's no way to disable
> the feature where a script will be re-compiled if it changes on disk.
> 
> Is this correct?
> 
> This is a problem if I update both the main script, and modules used by the
> script. For example, adding a new subroutine to a module and then calling
> it from the main Registry script.  The main script will be recompiled, but
> not the module, so I'll get an undefinded subroutine called.
> 
> I'm not using Apache::StatINC - the module isn't in the @INC path at startup.
> 
> I'd like to be able to move the updated script and module into place and
> either do a -USR1 restart or just wait for the Apache processes to go
> through their normal life cycle.  As is, it seems as if I have to bring
> down the server, move in the updated scripts in, and restart.  Not the most
> graceful process.

Here is a pretty way to disable script reloading.  It is not the most
efficient.

--- Registry.pm Tue Jan 11 10:00:45 2000
+++ Registry-no_reload.pm   Tue Jan 11 17:17:44 2000
@@ -85,11 +85,7 @@
 
$r->chdir_file;
 
-   if (
-   exists $Apache::Registry->{$package}{'mtime'}
-   &&
-   $Apache::Registry->{$package}{'mtime'} <= $mtime
-  ){
+   if (exists $Apache::Registry->{$package}{'mtime'}) {
# we have compiled this subroutine already, nothing left to do
} else {
$r->log_error("Apache::Registry::handler reading $filename")