You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Farokh Irani <fa...@mcfsoftware.com> on 2007/08/01 22:48:50 UTC

Module initialization

I must just be dense, but I've spent a whole bunch of time trying to 
figure exactly how I can put initialization code into my module. It's 
code that needs to run only once when apache (2.2.x) is starting up, 
so any pointers would be appreciated.

Thanks!
-- 

Farokh
----------------------------------------------------------------------------
MCF Software...simply dependably engineered
Developers of ListSTAR http://www.liststar.com/, MacRADIUS
http://www.macradius.com/, Address List Sorter
http://www.mcfsoftware.com/als/, SimpleText Filter for EIMS
http://www.mcfsoftware.com/stf/ and Auto Reply plug-in for EIMS 
http://www.mcfsoftware.com/ar/.

Re: Module initialization

Posted by César Leonardo Blum Silveira <ce...@gmail.com>.
Is preconfig code run only once, not being run again even on a restart?

On 8/1/07, Tim Bray <Ti...@sun.com> wrote:
>
> On Aug 1, 2007, at 1:48 PM, Farokh Irani wrote:
>
> > I must just be dense, but I've spent a whole bunch of time trying
> > to figure exactly how I can put initialization code into my module.
> > It's code that needs to run only once when apache (2.2.x) is
> > starting up, so any pointers would be appreciated.
>
> ap_hook_pre_config(your_routine, NULL, NULL, APR_HOOK_MIDDLE)
>
> static int your_routine(apr_pool_t * p_conf, apr_pool_t * p_log,
> apr_pool_t * p_temp);
>
>
>
>


-- 
César L. B. Silveira
http://cesarbs.wordpress.com/

Re: Module initialization

Posted by Tim Bray <Ti...@Sun.COM>.
On Aug 1, 2007, at 1:48 PM, Farokh Irani wrote:

> I must just be dense, but I've spent a whole bunch of time trying  
> to figure exactly how I can put initialization code into my module.  
> It's code that needs to run only once when apache (2.2.x) is  
> starting up, so any pointers would be appreciated.

ap_hook_pre_config(your_routine, NULL, NULL, APR_HOOK_MIDDLE)

static int your_routine(apr_pool_t * p_conf, apr_pool_t * p_log,  
apr_pool_t * p_temp);




Re: Module initialization

Posted by Danie Qian <da...@bestningning.com>.
----- Original Message ----- 
From: "Tim Bray" <Ti...@Sun.COM>
To: <mo...@httpd.apache.org>
Sent: Wednesday, August 01, 2007 5:20 PM
Subject: Re: Module initialization


> 
> On Aug 1, 2007, at 1:48 PM, Farokh Irani wrote:
> 
>> I must just be dense, but I've spent a whole bunch of time trying  
>> to figure exactly how I can put initialization code into my module.  
>> It's code that needs to run only once when apache (2.2.x) is  
>> starting up, so any pointers would be appreciated.
> 
> oops, incomplete answer:
> 
> static int your_routine(apr_pool_t * p_conf, apr_pool_t * p_log,  
> apr_pool_t * p_temp);
> 
> /* register our interests */
> static void hooks(apr_pool_t * p)
> {
>   ap_hook_pre_config(your_routine, NULL, NULL, APR_HOOK_MIDDLE);
>  ...
> }
> 
> module AP_MODULE_DECLARE_DATA atom_module = {
>   STANDARD20_MODULE_STUFF,
>   NULL,                       /* create per-directory config  
> structure */
>   NULL,                       /* merge per-directory config  
> structures */
>   NULL,                       /* create per-server config structure */
>   NULL,                       /* merge per-server config structures */
>   directives,                 /* handle config directive */
>   hooks                       /* registrar */
> };
> 
> 

Any impact if put in ap_hook_post_config() ?

Re: Module initialization

Posted by Graham Dumpleton <gr...@gmail.com>.
Go have a read of:

  http://www.fmc-modeling.org/category/projects/apache/amp/Apache_Modeling_Project.html

It goes into quite a lot of details of how the internals of Apache
works. It includes lots of pretty pictures of how all the phases and
hooking functions for this sort of thing relate to each other and when
they are triggered.

Graham

On 03/08/07, Farokh Irani <fa...@mcfsoftware.com> wrote:
> >On Aug 1, 2007, at 1:48 PM, Farokh Irani wrote:
> >
> >>I must just be dense, but I've spent a whole bunch of time trying
> >>to figure exactly how I can put initialization code into my module.
> >>It's code that needs to run only once when apache (2.2.x) is
> >>starting up, so any pointers would be appreciated.
> >
> >oops, incomplete answer:
> >
> >static int your_routine(apr_pool_t * p_conf, apr_pool_t * p_log,
> >apr_pool_t * p_temp);
> >
> >/* register our interests */
> >static void hooks(apr_pool_t * p)
> >{
> >   ap_hook_pre_config(your_routine, NULL, NULL, APR_HOOK_MIDDLE);
> >  ...
> >}
> >
> >module AP_MODULE_DECLARE_DATA atom_module = {
> >   STANDARD20_MODULE_STUFF,
> >   NULL,                       /* create per-directory config structure */
> >   NULL,                       /* merge per-directory config structures */
> >   NULL,                       /* create per-server config structure */
> >   NULL,                       /* merge per-server config structures */
> >   directives,                 /* handle config directive */
> >   hooks                       /* registrar */
> >};
>
> OK, thanks for that tidbit. However, as someone else mentioned, if I
> need to do something when apache is restarted, will this do the trick?
>
> Also, when apache is shutting down, can my module do clean up and how
> do I handle that?
>
> Thanks!
> --
>
> Farokh
> ----------------------------------------------------------------------------
> MCF Software...simply dependably engineered
> Developers of ListSTAR http://www.liststar.com/, MacRADIUS
> http://www.macradius.com/, Address List Sorter
> http://www.mcfsoftware.com/als/, SimpleText Filter for EIMS
> http://www.mcfsoftware.com/stf/ and Auto Reply plug-in for EIMS
> http://www.mcfsoftware.com/ar/.
>

Re: Module initialization

Posted by Farokh Irani <fa...@mcfsoftware.com>.
>On Aug 1, 2007, at 1:48 PM, Farokh Irani wrote:
>
>>I must just be dense, but I've spent a whole bunch of time trying 
>>to figure exactly how I can put initialization code into my module. 
>>It's code that needs to run only once when apache (2.2.x) is 
>>starting up, so any pointers would be appreciated.
>
>oops, incomplete answer:
>
>static int your_routine(apr_pool_t * p_conf, apr_pool_t * p_log, 
>apr_pool_t * p_temp);
>
>/* register our interests */
>static void hooks(apr_pool_t * p)
>{
>   ap_hook_pre_config(your_routine, NULL, NULL, APR_HOOK_MIDDLE);
>  ...
>}
>
>module AP_MODULE_DECLARE_DATA atom_module = {
>   STANDARD20_MODULE_STUFF,
>   NULL,                       /* create per-directory config structure */
>   NULL,                       /* merge per-directory config structures */
>   NULL,                       /* create per-server config structure */
>   NULL,                       /* merge per-server config structures */
>   directives,                 /* handle config directive */
>   hooks                       /* registrar */
>};

OK, thanks for that tidbit. However, as someone else mentioned, if I 
need to do something when apache is restarted, will this do the trick?

Also, when apache is shutting down, can my module do clean up and how 
do I handle that?

Thanks!
-- 

Farokh
----------------------------------------------------------------------------
MCF Software...simply dependably engineered
Developers of ListSTAR http://www.liststar.com/, MacRADIUS
http://www.macradius.com/, Address List Sorter
http://www.mcfsoftware.com/als/, SimpleText Filter for EIMS
http://www.mcfsoftware.com/stf/ and Auto Reply plug-in for EIMS 
http://www.mcfsoftware.com/ar/.

Re: Module initialization

Posted by Tim Bray <Ti...@Sun.COM>.
On Aug 1, 2007, at 1:48 PM, Farokh Irani wrote:

> I must just be dense, but I've spent a whole bunch of time trying  
> to figure exactly how I can put initialization code into my module.  
> It's code that needs to run only once when apache (2.2.x) is  
> starting up, so any pointers would be appreciated.

oops, incomplete answer:

static int your_routine(apr_pool_t * p_conf, apr_pool_t * p_log,  
apr_pool_t * p_temp);

/* register our interests */
static void hooks(apr_pool_t * p)
{
   ap_hook_pre_config(your_routine, NULL, NULL, APR_HOOK_MIDDLE);
  ...
}

module AP_MODULE_DECLARE_DATA atom_module = {
   STANDARD20_MODULE_STUFF,
   NULL,                       /* create per-directory config  
structure */
   NULL,                       /* merge per-directory config  
structures */
   NULL,                       /* create per-server config structure */
   NULL,                       /* merge per-server config structures */
   directives,                 /* handle config directive */
   hooks                       /* registrar */
};