0

My normal OS is Windows 7 64-bit, but I'm running VirtualBox with the latests release of Ubuntu installed. I'm trying to use the VM as my web server as developing a Rails application on a Windows box is troublesome at best. I've got it to the point where all the services operate normally and I'm browsing/updating just fine.

I've installed nginx and I can start/stop the service just fine through the terminal. However I've added the nginx start script (below) to the init.d directory and added it to startup via sudo update-rc.d nginx defaults, but it just won't run at startup. At all. The nginx file is executable and the owner is root (same as my mysql service which is working...)

#! /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

PATH=/etc/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/etc/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

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

set -e

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

    exit 0

FYI, I know the normal install directory for nginx is /opt/nginx/sbin but on my system it's actually /etc/nginx/sbin. So that isn't what's wrong.

Running sudo pgrep nginx right after booting to the desktop yields no results, but I can start the service using sudo /etc/init.d/nginx start and it works just fine. On subsequent calls to sudo pgrep nginx, I get the PIDs of the nginx processes.

Why isn't this working?

0

Due to another problem I was having with NFS shares not being auto-mounted on startup, I figure NGINX was either:

A) Not actually being started on bootup
or
B) Being started but failing to load the site because it referenced files on the NFS mount

The NFS mount was probably being loaded via fstab too early in the boot process (before network capabilities loaded) and failed which caused nginx to fail. Fixing the issue outlined here prompted me to add sudo service nginx start to rc.local after sudo mount -a yields expected results.

0

I found this issue to in vagrant using virtual box, the following fixes my issue:

echo "sudo /etc/init.d/nginx start" | sudo tee -a /etc/rc.local

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.