You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2004/11/30 21:56:12 UTC

[mp2 patch] $Apache::Server::(re)starting functionality

This patch returns the functionality we had in mp1:

use Apache::ServerUtil ();
my $cnt = Apache->server->start_cnt();
open my $fh, ">>/tmp/out" or die "$!";
print $fh "cnt: $cnt\n";
close $fh;

but I'm not sure at all if we want to keep those $Starting/$Restarting 
vars, based on previous discussions on httpd-dev those could be totally 
wrong since httpd.conf is reparsed too many times (including graceful and 
shutdown).

So i was thinking to just give a variable which will return the 
generation. So start_cnt() returns 1 when server starts, and 2 when it 
immediately restarts.

please post comments since I want to integrate it now. I need it at least 
for the tests.

Index: src/modules/perl/mod_perl.c
===================================================================
--- src/modules/perl/mod_perl.c	(revision 109224)
+++ src/modules/perl/mod_perl.c	(working copy)
@@ -280,8 +280,12 @@
              newSVpv(ap_server_root_relative(p, "lib/perl"), 0));
  #endif /* MP_COMPAT_1X */

+
+    /* things to be done only in the main server */
      if (!s->is_virtual) {
          modperl_handler_anon_init(aTHX_ p);
+
+        modperl_init_cnt_inc(s);
      }

      if (!modperl_config_apply_PerlRequire(s, scfg, perl, p)) {
Index: src/modules/perl/modperl_util.c
===================================================================
--- src/modules/perl/modperl_util.c	(revision 106739)
+++ src/modules/perl/modperl_util.c	(working copy)
@@ -797,3 +797,26 @@
      }

  }
+
+#define MP_INIT_KEY "mod_perl_init_cnt"
+
+void modperl_init_cnt_inc(server_rec *main_server)
+{
+    void *data;
+    int cnt = 1;
+    apr_pool_userdata_get(&data, MP_INIT_KEY, main_server->process->pool);
+    if (data) {
+        cnt = (int)data + 1;
+    }
+
+    apr_pool_userdata_set((const void *)cnt, MP_INIT_KEY,
+                          apr_pool_cleanup_null,
+                          main_server->process->pool);
+}
+
+int modperl_init_cnt(server_rec *main_server)
+{
+    void *data;
+    apr_pool_userdata_get(&data, MP_INIT_KEY, main_server->process->pool);
+    return data ? (int)data : 0;
+ }
Index: src/modules/perl/modperl_util.h
===================================================================
--- src/modules/perl/modperl_util.h	(revision 106739)
+++ src/modules/perl/modperl_util.h	(working copy)
@@ -139,4 +139,12 @@
          : (char *)apr_psprintf(p, "%s...",                               \
                                 apr_pstrmemdup(p, str, MP_TRACE_STR_LEN))

+/* functions maintaining the amount of times mod_perl was restarted,
+ * e.g. on Apache start, it restarts itself, so the count will be
+ * first 1, and on on restart 2 */
+void modperl_init_cnt_inc(server_rec *main_server);
+int  modperl_init_cnt(server_rec *main_server);
+
+
+
  #endif /* MODPERL_UTIL_H */
Index: xs/maps/apache_functions.map
===================================================================
--- xs/maps/apache_functions.map	(revision 106739)
+++ xs/maps/apache_functions.map	(working copy)
@@ -157,6 +157,7 @@
  -ap_scan_script_header_err_brigade

  MODULE=Apache::ServerUtil   PACKAGE=Apache::ServerRec BOOT=1
+ int:DEFINE_start_cnt | | server_rec *:s
  ~ap_method_register
   int:DEFINE_method_register | | server_rec *:s, const char *:methname
  ~add_version_component
Index: xs/Apache/ServerUtil/Apache__ServerUtil.h
===================================================================
--- xs/Apache/ServerUtil/Apache__ServerUtil.h	(revision 106739)
+++ xs/Apache/ServerUtil/Apache__ServerUtil.h	(working copy)
@@ -13,7 +13,9 @@
   * limitations under the License.
   */

-#define mpxs_Apache__ServerRec_method_register(s, methname)    \
+#define mpxs_Apache__ServerRec_start_cnt modperl_init_cnt
+
+#define mpxs_Apache__ServerRec_method_register(s, methname)     \
      ap_method_register(s->process->pconf, methname);

  #define mpxs_Apache__ServerRec_add_version_component(s, component)    \

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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] $Apache::Server::(re)starting functionality

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:

>>  > So i was thinking to just give a variable which will return the
>>  > generation. So start_cnt() returns 1 when server starts, and 2 when it
>>  > immediately restarts.
>>
>> Yes, but I'd call it generation or something like that.
> 
> 
> Good idea.

I changed that, but then it was very confusing since it wasn't clear what 
generation it returns when taken out of the context of this discussion. So 
I ended up calling it:

   Apache::ServerUtil::restart_count

which is very intuitive IMHO.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] $Apache::Server::(re)starting functionality

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Reposting to the list on gozer's behalf who forgets to hit Reply-All 
> once in a while :)
> 
> Stas Bekman wrote:
>  > This patch returns the functionality we had in mp1:
>  >
>  > use Apache::ServerUtil ();
>  > my $cnt = Apache->server->start_cnt();
>  > open my $fh, ">>/tmp/out" or die "$!";
>  > print $fh "cnt: $cnt\n";
>  > close $fh;
> 
> Interestingly simpler idea. But isn't this what ap_my_generation is more
> or less representing ?

Not quite. Look for example at server/mpm/prefork/prefork.c - it ++ the 
generation only in multiple server mode. Besides there is no API to get 
this ap_my_generation global. It also doesn't behave the same way (numbers 
wise). Also other modules haven't used it to figure out where they are 
just booted (e.g. post_config in mod_rewrite.c). A year ago I've proposed 
an httpd API to handle that centrally, but alas that didn't get anywhere :(

>  > but I'm not sure at all if we want to keep those $Starting/$Restarting
>  > vars, based on previous discussions on httpd-dev those could be totally
>  > wrong since httpd.conf is reparsed too many times (including graceful
>  > and shutdown).
> 
> Yeah, I think $Starting/$Restarting was _way_ to esoteric.
> 
>  > So i was thinking to just give a variable which will return the
>  > generation. So start_cnt() returns 1 when server starts, and 2 when it
>  > immediately restarts.
> 
> Yes, but I'd call it generation or something like that.

Good idea.

>  > please post comments since I want to integrate it now. I need it at
>  > least for the tests.
> 
> +1 on the concept, maybe stick $Starting/$Restarting in Apache::compat ?

That might be tricky. Since it'll require to make those TIE'd variables. 
Otherwise how would they be updated. Or may be just assigning those at 
Apache::compat compile time will just work. Since one needs to load the 
module before using those vars.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] $Apache::Server::(re)starting functionality

Posted by Stas Bekman <st...@stason.org>.
Reposting to the list on gozer's behalf who forgets to hit Reply-All once 
in a while :)

Stas Bekman wrote:
 > This patch returns the functionality we had in mp1:
 >
 > use Apache::ServerUtil ();
 > my $cnt = Apache->server->start_cnt();
 > open my $fh, ">>/tmp/out" or die "$!";
 > print $fh "cnt: $cnt\n";
 > close $fh;

Interestingly simpler idea. But isn't this what ap_my_generation is more
or less representing ?

 > but I'm not sure at all if we want to keep those $Starting/$Restarting
 > vars, based on previous discussions on httpd-dev those could be totally
 > wrong since httpd.conf is reparsed too many times (including graceful
 > and shutdown).

Yeah, I think $Starting/$Restarting was _way_ to esoteric.

 > So i was thinking to just give a variable which will return the
 > generation. So start_cnt() returns 1 when server starts, and 2 when it
 > immediately restarts.

Yes, but I'd call it generation or something like that.

 > please post comments since I want to integrate it now. I need it at
 > least for the tests.

+1 on the concept, maybe stick $Starting/$Restarting in Apache::compat ?



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] $Apache::Server::(re)starting functionality

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> This patch returns the functionality we had in mp1:
> 
> use Apache::ServerUtil ();
> my $cnt = Apache->server->start_cnt();
> open my $fh, ">>/tmp/out" or die "$!";
> print $fh "cnt: $cnt\n";
> close $fh;

So I threw that into a module, which I PerlLoadModule, and I see the 
following behavior:

httpd -k start
cnt: 1
cnt: 2

httpd -k graceful
cnt: 1
cnt: 3

httpd -k graceful
cnt: 1
cnt: 4

httpd -k stop
cnt: 1

So one can always tell that when cnt == 1, that means that the config is 
parsed for the first time, when the count is 2 or higher that means that's 
the restart. Numbers 3 and higher mean that it's a graceful restart, after 
internal restart.

Are we happy with that behavior?

Now to the API: since Apache->server is global anyway, this:

   Apache->server->start_cnt();

can be made into just an function:

   Apache::ServerUtil::start_cnt();

but I'm not sure what's the best function name (take a look at the counts 
above). really what it means is how many times httpd.conf was parsed (or 
still being parsed on the nth time). with the special case for those '1' 
values.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org