1

I use daemon tools with gearman
I was thinking whether I should configure daemon tools for Nginx
or does it handle its shutdown (in case of memory issue, etc..) automatically?

Jad Joubran
  • 160
  • 2
  • 9

1 Answers1

2

As someone who fell in love with daemontools thirteen years ago, I too try to supervise all the things. nginx is a bit feisty though, you have to use at least daemon off; in your config to run it in the foreground, and master_process off; if you really don't want it spawning any children. Just exec it then from your run program and it will behave like you expect.

I was cutting against the grain, however. I've come to accept that nginx has supervision built in. You'll notice that when you run it you get something like this:

$ psg nginx
root      1361     1  0 Mar31 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data  1362  1361  0 Mar31 ?        00:18:10 nginx: worker process
www-data  1363  1361  0 Mar31 ?        00:18:44 nginx: worker process
$ pstree -p 1361
nginx(1361)─┬─nginx(1362)
            └─nginx(1363)

The master process is essentially supervise. It's super lightweight and is solely responsible for making sure workers are running properly. I've never once had it crash on me, even in some fairly busy environments. So now I just let init stop/start it and worry about services I do need to supervise.

There are other considerations. Check out what the official documentation has to say about it: http://nginx.org/en/docs/faq/daemon_master_process_off.html

drewr
  • 146
  • 3
  • Doc TL;DR - `master_process off;` / `daemon off;` break zero-downtime upgrades and are mostly for Nginx developers. –  Sep 12 '15 at 03:36