# Daemon off in production

**URL:** <https://www.ruby-forum.com/t/daemon-off-in-production/211920>\
**Category:** NGINX\
**Created:** [September 17, 2011, 6:40am UTC](https://www.ruby-forum.com/t/daemon-off-in-production/211920 "2011-09-17T06:40:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 17, 2011, 6:40am UTC](https://www.ruby-forum.com/t/daemon-off-in-production/211920/1 "2011-09-17T06:40:38Z")

</div>

Hi,

The documentations says I should never run nginx with the daemon off  
setting  
in production. I would like to do so anyway so my Python/twisted based  
process manager will have an easier time knowing if nginx terminated or  
not  
(I know there are other ways to do it, but this seems like the easiest;  
if  
I’ll be forced to, I’ll use another way).

I’m aware of SIGWINCH and nginx in general and especially after version  
1.1.1, and I don’t mind taking care of guaranteeing nginx will run  
without a  
controlling terminal (I will fork()/setsid() before exec()ing it), run  
in a  
sensible current working directory, etc. I just don’t want it to do the  
daemonizing double fork.

From skimming the code, it appears to me that nothing bad should happen.  
What am I missing? Why is it so bad to run nginx in the foreground in  
production?

Thanks,

- Yaniv

---

<div class="post-metadata">

**Author:** ![Yaniv\_Aknin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/5f9b8f/32.png) [@Yaniv\_Aknin](https://www.ruby-forum.com/u/Yaniv_Aknin)\
**Post date:** [September 17, 2011, 12:30pm UTC](https://www.ruby-forum.com/t/daemon-off-in-production/211920/2 "2011-09-17T12:30:57Z")

</div>

Hello!

On Sat, Sep 17, 2011 at 07:40:19AM +0300, Yaniv Aknin wrote:

> controlling terminal (I will fork()/setsid() before exec()ing it), run in a  
> sensible current working directory, etc. I just don’t want it to do the  
> daemonizing double fork.
> 
> From skimming the code, it appears to me that nothing bad should happen.  
> What am I missing? Why is it so bad to run nginx in the foreground in  
> production?

Documentation[1] says “daemon” is generally used for development,  
it doesn’t say it shouldn’t be used in production. It’s safe to  
run with “daemon off;” if you use some controlling process  
manager. Note that you don’t really need to setsid(), nginx will  
take care of this even with “daemon off;”.

Please don’t confuse with “master\_process off;”. It’s _unsafe_ to  
run with “master\_process off;” and it’s _only_ used for  
development.

[1] [Основная функциональность](http://sysoev.ru/nginx/docs/ngx_core_module.html#daemon)

Maxim D.

---

<div class="post-metadata">

**Author:** ![Yaniv\_Aknin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/5f9b8f/32.png) [@Yaniv\_Aknin](https://www.ruby-forum.com/u/Yaniv_Aknin)\
**Post date:** [September 17, 2011, 12:49pm UTC](https://www.ruby-forum.com/t/daemon-off-in-production/211920/3 "2011-09-17T12:49:27Z")

</div>

On Sat, Sep 17, 2011 at 07:40:19AM +0300, Yaniv Aknin wrote:

> controlling terminal (I will fork()/setsid() before exec()ing it), run in a  
> sensible current working directory, etc. I just don’t want it to do the  
> daemonizing double fork.
> 
> From skimming the code, it appears to me that nothing bad should happen.  
> What am I missing? Why is it so bad to run nginx in the foreground in  
> production?

There are two directives: “master\_process on|off” and “daemon on|off”.  
Both are used to simplify nginx development: while testing a bug/feature  
I usually run nginx in foreground without master process and simply  
press ^C to stop nginx. This is an analog of Apache’s -X command line  
switch.  
I did not want to type it in commanf line, so these two directives  
have been introduced.

There was thought to allow nginx to run in single process mode in  
production  
as many lightweight server do. So there is some incomplete code to  
support  
this fucntionality. But this code is incomplete, so you should never  
use “master\_process off” in production.

As to “daemon off”, I did not intend to use it in production (and never  
did),  
but many people do it. I believe it is safe to use “daemon off” in  
prodcution. You can apply SIGWINCH fix using:

[http://trac.nginx.org/nginx/changeset/4020/nginx](http://trac.nginx.org/nginx/changeset/4020/nginx)

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Yaniv\_Aknin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/5f9b8f/32.png) [@Yaniv\_Aknin](https://www.ruby-forum.com/u/Yaniv_Aknin)\
**Post date:** [September 17, 2011, 12:58pm UTC](https://www.ruby-forum.com/t/daemon-off-in-production/211920/4 "2011-09-17T12:58:05Z")

</div>

On Sat, Sep 17, 2011 at 02:49:03PM +0400, Igor S. wrote:

> > 1.1.1, and I don’t mind taking care of guaranteeing nginx will run without a  
> > I usually run nginx in foreground without master process and simply  
> > but many people do it. I believe it is safe to use “daemon off” in  
> > prodcution. You can apply SIGWINCH fix using:
> 
> [http://trac.nginx.org/nginx/changeset/4020/nginx](http://trac.nginx.org/nginx/changeset/4020/nginx)

The single option that is not available in “daemon off” mode is online  
upgrade, because after the upgrade you supervior can not control new  
nginx instance.

–  
Igor S.
