Runit and nginx

nginxrunit

I'm working on a system whose primary startup system is runit.

Unfortunately, runit requires that whatever application it is running be running in the foreground like so:

#!/bin/bash

exec sshd -D

Seeing as nginx doesn't offer a way to run it in the foreground, how can I have runit still manage nginx and be able to stop, start, and restart it using runit's sv commands?

Best Answer

You can use option daemon off:

exec /usr/sbin/nginx -c /etc/nginx/nginx.conf  -g "daemon off;"

From nginx wiki:

You can use daemon off safely in production mode with runit / daemontools however you can't do a graceful upgrade. master_process off should never be used in production.

When you use runit to control nginx, it becomes the parent process of the nginx master process. But if you try to do an online upgrade, the nginx master process will fork and execute the new binary.

A new master process is created, but because old master process still exists (because it's controlled by runit), the parent of the new master process will be the init process, because runit can not control new master master process as it didn't start it.

Related Question