# Running code in nginx's master process

**URL:** <https://www.ruby-forum.com/t/running-code-in-nginxs-master-process/246469>\
**Category:** NGINX\
**Created:** [October 22, 2013, 2:27am UTC](https://www.ruby-forum.com/t/running-code-in-nginxs-master-process/246469 "2013-10-22T02:27:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [October 22, 2013, 2:27am UTC](https://www.ruby-forum.com/t/running-code-in-nginxs-master-process/246469/1 "2013-10-22T02:27:51Z")

</div>

Is it possible to have a module run code in nginx’s master process, i.e.  
not  
in a worker process?  
I know init\_master is just a stub for now. Are there any chances this  
gets  
implemented in the near future?

Thanks in advance,  
Marcelo.

Posted at Nginx Forum:

> **[Running code in nginx's master process](https://forum.nginx.org/read.php?2,243942,243942#msg-243942)**
>
> Is it possible to have a module run code in nginx's master process, i.e. not in a worker process? I know init\_master is just a stub for now. Are there any chances this gets implemented in the near future? Thanks in advance, Marcelo.

---

<div class="post-metadata">

**Author:** ![mzabani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@mzabani](https://www.ruby-forum.com/u/mzabani)\
**Post date:** [October 22, 2013, 2:03pm UTC](https://www.ruby-forum.com/t/running-code-in-nginxs-master-process/246469/2 "2013-10-22T14:03:19Z")

</div>

Hello!

On Mon, Oct 21, 2013 at 08:27:01PM -0400, mzabani wrote:

> Is it possible to have a module run code in nginx’s master process, i.e. not  
> in a worker process?  
> I know init\_master is just a stub for now. Are there any chances this gets  
> implemented in the near future?

I wouldn’t recommend running a code in master process, but if you  
have to for some reason, you may try using init\_module callback.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![mzabani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@mzabani](https://www.ruby-forum.com/u/mzabani)\
**Post date:** [October 24, 2013, 2:38pm UTC](https://www.ruby-forum.com/t/running-code-in-nginxs-master-process/246469/3 "2013-10-24T14:38:05Z")

</div>

It seems like the init\_module callback is not executed in nginx’s master  
process. At least, I’ve printed a call to getpid() and the pid returned  
was  
that of a process that wasn’t running, which makes me think it is  
executed  
in a process that forks the master process itself.

Posted at Nginx Forum:

> **[Re: Running code in nginx's master process](https://forum.nginx.org/read.php?2,243942,244069#msg-244069)**
>
> Is it possible to have a module run code in nginx's master process, i.e. not in a worker process? I know init\_master is just a stub for now. Are there any chances this gets implemented in the near future? Thanks in advance, Marcelo.

---

<div class="post-metadata">

**Author:** ![mzabani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@mzabani](https://www.ruby-forum.com/u/mzabani)\
**Post date:** [October 24, 2013, 6:50pm UTC](https://www.ruby-forum.com/t/running-code-in-nginxs-master-process/246469/4 "2013-10-24T18:50:02Z")

</div>

Hello!

On Thu, Oct 24, 2013 at 08:37:03AM -0400, mzabani wrote:

> It seems like the init\_module callback is not executed in nginx’s master  
> process. At least, I’ve printed a call to getpid() and the pid returned was  
> that of a process that wasn’t running, which makes me think it is executed  
> in a process that forks the master process itself.

Yes, the init\_module callback is called after configuration parsing,  
and on initial startup this happens before demonization, hence  
there is no master process yet. On reconfiguration it’s executed  
in the master process itself.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
