Re: supervising nginx

From: Alex Efros <>
Date: Sat, 2 May 2015 14:14:27 +0300


On Thu, Jul 24, 2014 at 02:47:29AM +0300, Alex Efros wrote:
> Is it possible to run nginx under runsv supervision without breaking
> nginx's ability to upgrade (SIGUSR2) gracefully without interrupting
> current connections?

Looks like this workaround may solve this issue, but I'm not sure about
possible races.

1. Create copy of nginx service as nginx2.
2. touch nginx2/down
3. Add this ./finish to both services:

    test -f down && sv d .

4. Add this control/q to nginx service:

    mv ../nginx2/down ./
    sv u ../nginx2
    sleep 1
    exit 1

5. Add this control/q to nginx2 service:

    mv ../nginx/down ./
    sv u ../nginx
    sleep 1
    exit 1

6. Activate nginx2 service (make symlink in /etc/service/ or /var/service/
   etc. - in directory handled by runsvdir).

Now you can `sv q nginx` or `sv q nginx2` (depending on which one of
currently running) to gracefully upgrade/restart it.

I'm afraid there is still some small window when neither new nor old nginx
will listen on ports - new nginx log this on start:

    [emerg] 18098#0: bind() to failed (98: Address already in use)
    [emerg] 18098#0: bind() to failed (98: Address already in use)
    [notice] 18098#0: try again to bind() after 500ms

According to nginx is able
to start new master process using new binary (so it can't use fork and
thus can't inherit listen socket) and have both old and new master
processes accept connections. I suppose it use SO_REUSEADDR in this case,
but I don't know how to activate it manually from ./run or nginx config.

			WBR, Alex.
Received on Sat May 02 2015 - 11:14:27 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC