Nginx pendurado na reinicialização

3

Estou tendo que executar o script de inicialização do nginx em segundo plano, ou ele não retorna ao shell quando executado - ele faz isso por meio de

service nginx start

.. ou simplesmente executando ..

/etc/init.d/nginx

.. diretamente. Eu tenho que executá-lo no fundo, em seguida, deserdá-lo ..

Em execução no Ubuntu 14.04.2, Nginx v 1.4.6

nginx -V nos dá:

nginx version: nginx/1.4.6 (Ubuntu)
built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module

.. e "bash -x nginx restart" retorna ..

+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+ DAEMON=/usr/sbin/nginx
+ NAME=nginx
+ DESC=nginx
+ '[' -f /etc/default/nginx ']'
+ . /etc/default/nginx
+ test -x /usr/sbin/nginx
+ set -e
+ . /lib/lsb/init-functions
+++ run-parts --lsbsysinit --list /lib/lsb/init-functions.d
++ for hook in '$(run-parts --lsbsysinit --list /lib/lsb/init-functions.d 2>/dev/null)'
++ '[' -r /lib/lsb/init-functions.d/20-left-info-blocks ']'
++ . /lib/lsb/init-functions.d/20-left-info-blocks
++ for hook in '$(run-parts --lsbsysinit --list /lib/lsb/init-functions.d 2>/dev/null)'
++ '[' -r /lib/lsb/init-functions.d/50-ubuntu-logging ']'
++ . /lib/lsb/init-functions.d/50-ubuntu-logging
+++ LOG_DAEMON_MSG=
++ FANCYTTY=
++ '[' -e /etc/lsb-base-logging.sh ']'
++ true
+ case "$1" in
+ echo -n 'Restarting nginx: '
Restarting nginx: + start-stop-daemon --stop --quiet --pidfile /var/run/nginx.pid --exec /usr/sbin/nginx
+ sleep 1
nginx.
+ test_nginx_config
+ /usr/sbin/nginx -t
+ return 0
+ start-stop-daemon --start --quiet --pidfile /var/run/nginx.pid --exec /usr/sbin/nginx --

.. e depois nada.

CONFIGS:

nginx.conf

# Generic startup file.
user www-data developers;

#ususally equal to number of CPU's you have. run command "grep processor /proc/cpuinfo | wc -l" to find it
worker_processes auto;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

# Keeps the logs free of messages about not being able to bind().
daemon     off;

events {
    worker_connections  1024;
}

http {
#   rewrite_log on;

    include mime.types;
    default_type       application/octet-stream;
    access_log         /var/log/nginx/access.log;
    sendfile           on;
#   tcp_nopush         on;
    keepalive_timeout  3;
#   tcp_nodelay        on;
#   gzip               on;
        #php max upload limit cannot be larger than this
    client_max_body_size 13m;

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;

    index              index.php index.html index.htm;

    # Upstream to abstract backend connection(s) for PHP.
    upstream php {
                #this should match value of "listen" directive in php-fpm pool
        server unix:/var/run/php5-fpm.sock;
    }

    include sites-enabled/*;
}

Qualquer ideia seria muito apreciada.

    
por Sp4cecat 29.06.2015 / 02:37

2 respostas

6

O script init, e especificamente o helper start-stop-daemon , espera que o programa comece a se colocar em segundo plano por padrão. No entanto, alguém alterou por engano sua configuração nginx para evitar que isso ocorra:

# Keeps the logs free of messages about not being able to bind().
daemon     off;

Esta seção deve ser removida completamente. Primeiro, o nginx deve estar em daemonizing. Segundo, se tais mensagens sobre não conseguir ligar () aparecerem, não é porque o nginx estava rodando como um daemon, é porque o nginx já estava rodando quando alguém tentou iniciar uma segunda cópia.

    
por 30.06.2015 / 05:56
-1
    #! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

## MAKE SURE YOUR BASE NGINX DIR IS LISTED HERE
PATH=/usr/local/nginx:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

## THIS IS THE ABSOLUTE PATH TO THE NGINX EXECUTABLE
DAEMON=/usr/local/nginx/sbin/nginx

## Username you want nginx to run as
NAME=nginx

## Process description you want to assign to nginx
DESC=nginx

## Options to pass to nginx - manual config location (see then nginx wiki for more options)
DAEMON_OPTS="-c /etc/nginx/nginx.conf"

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
    . /etc/default/nginx
fi

set -e

. /lib/lsb/init-functions

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
        --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;
  stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
        --exec $DAEMON || true
    echo "$NAME."
    ;;
  restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --quiet --pidfile \
        /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
    sleep 1
    start-stop-daemon --start --quiet --pidfile \
        /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;
  reload)
      echo -n "Reloading $DESC configuration: "
      start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
          --exec $DAEMON || true
      echo "$NAME."
      ;;
  status)
      status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
      ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
    exit 1
    ;;
esac

exit 0
    
por 23.02.2016 / 14:05

Tags