Welcome! Log In Create A New Profile

Advanced

Re: init module callback called twice

Maxim Dounin
April 08, 2021 09:12AM
Hello!

On Thu, Apr 08, 2021 at 05:54:42AM -0400, xdrew wrote:

> Hello,
>
> I'm developing a little custom module for nginx, and I need to execute some
> user code once my module is loaded. I do this by attaching to the hook in
> ngx_module_t structure:
>
> ngx_module_t ngx_http_hello_world_module = {
> ...
> NULL, /* init master */
> init_module, /* init module */
> NULL, /* init process */
> ...
> }
>
> static ngx_int_t init_module(ngx_cycle_t *cycle) {
> ngx_log_stderr (0, "Initializing module") ; }
>
> Surprisingly my callback is called twice. First time it follows log message
>
> nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
> nginx: Initializing module
>
> and then
>
> nginx: configuration file /etc/nginx/nginx.conf test is successful
> nginx: Initializing module
>
> Is there a way to recognize that I'm called in some different context (e.g.
> some value from ngx_cycle_t structure)?
> Or may be I'm doing something completely wrong?

What you observe is perfectly expected: the module initialization
callback is called once per configuration parsing, and your output
seems to be from running a startup script which does something
like "nginx -t; nginx", which starts nginx twice: once to test the
configuration, and again to actually start nginx.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

init module callback called twice

xdrew April 08, 2021 05:54AM

Re: init module callback called twice

Maxim Dounin April 08, 2021 09:12AM

Re: init module callback called twice

xdrew April 08, 2021 09:48AM

Re: init module callback called twice

Maxim Dounin April 08, 2021 11:22AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 78
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready