Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using nginx with supervisor - nginx process launched multiple times leading to bind error

I am using nginx with Supervisor. My supervisord.conf file content is as follows:

[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log

[program:nginx]
command=/usr/sbin/nginx -c /etc/nginx/nginx.conf
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
redirect_stderr=true

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

I started supervisord after ensuring that netstat -nltp says all ports are free but please find the nginx error log below:

2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:81 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:18081 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:18082 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:18083 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:10080 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:28080 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:18080 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:20081 failed (98: Address already in use)
2014/09/10 20:39:00 [emerg] 277#0: bind() to 0.0.0.0:81 failed (98: Address already in use)

But netstat -nltp command gives me the following:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:28080           0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:20081           0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:18080           0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:10080           0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:18081           0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:18082           0.0.0.0:*               LISTEN      246/nginx: master p
tcp        0      0 0.0.0.0:18083           0.0.0.0:*               LISTEN      246/nginx: master p

Which means nginx is up and running. But is the supervisord trying to launch multiple nginx processes or it is not getting signal from nginx that it has been started. Can anyone shed some light on this ?

like image 535
cucucool Avatar asked Sep 10 '14 20:09

cucucool


1 Answers

You should add -g 'daemon off;' to the nginx arguments.

Supervisor expects the service to run in the foreground. By default, nginx forks off (daemonizes) to the background and exits. Supervisor will think that nginx died when it exits and tries to restart.

In old versions of nginx daemon off was discouraged, but that is no longer the case.

like image 112
mikaraento Avatar answered Sep 28 '22 00:09

mikaraento