Nginx Service Scripts do not work after update?

Bug #1033856 reported by PhoinixGr on 2012-08-07
42
This bug affects 9 people
Affects Status Importance Assigned to Milestone
Nginx
High
Michael Lustfield

Bug Description

After a recent update on an ubuntu server system, using the : "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" Repository, there seems to be problem restarting starting and stoping the nginx service. I think it's related with the init scripts.

When I do
# /etc/init.d/nginx stop
I get:
Stopping nginx: start-stop-daemon: invalid schedule item (must be [-]<signal-name>, -<signal-number>, <timeout> or 'forever'
Try 'start-stop-daemon --help' for more information.

# /etc/init.d/nginx restart
Restarting nginx: nginx: invalid option: "/var/run/nginx.pid"
nginx.

The versions of nginx installed is:
nginx-common/lucid uptodate 1.2.2-0ubuntu0ppa2~lucid
nginx-full/lucid uptodate 1.2.2-0ubuntu0ppa2~lucid

Best Regards,

Channel4 (channel4) wrote :

Hello all,

The retry needs a parameter (in example I have said 5 seconds)... in both stop and restart|force-reload case statements.

In the restart|force-reload the --pidfile argument does not have the pid location (instead it have retry argument)

Will work:

/etc/init.d/nginx

...

        stop)
                echo -n "Stopping $DESC: "
                start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid --retry 5 \
                        --exec $DAEMON || true
                echo "$NAME."
                ;;

        restart|force-reload)
                echo -n "Restarting $DESC: "
                start-stop-daemon --stop --quiet --pidfile \
                    /var/run/$NAME.pid --retry 5 --exec $DAEMON || true
                sleep 1
                test_nginx_config
                # Check if the ULIMIT is set in /etc/default/nginx
                if [ -n "$ULIMIT" ]; then
                        # Set the ulimits
                        ulimit $ULIMIT
                fi
                start-stop-daemon --start --quiet --pidfile \
                        /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
                echo "$NAME."
                ;;

Thanks,

Chris

PhoinixGr (maziotisakis) wrote :

That seems to do the work!

Thanks Chris :)

Thanks for doing the hard part! I'll get a new PPA build pushed as
soon as I get home.

Gavin Chappell (g-a-c) wrote :

As well as the retry lacking an interval, there's also incorrect ordering of the arguments in the restart section:

start-stop-daemon --start --quiet --pidfile --retry /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true

should read

start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid --retry 5 --exec $DAEMON -- $DAEMON_OPTS || true

One thing you may want to consider is simply writing the start/stop logic as a function outside of the case statement, and then just using "stop" or "start" as necessary. This way, each piece of code is only stored once, and makes it harder for a typo to introduce inconsistency as it does here (a restart should pretty much always do the same thing as a stop/start but doesn't in this case due to the commands not matching up). I've attached an example which (in theory) is easier to maintain due to only having one function for start and stop so each piece of code only needs to be maintained once.

Changed in nginx:
status: New → In Progress
importance: Undecided → High
assignee: nobody → Michael Lustfield (michaellustfield)
Changed in nginx:
status: In Progress → Fix Committed

New build is being pushed to launchpad!

Changed in nginx:
status: Fix Committed → Fix Released

Thanks for the fix.

Note for others:
If you see the following during install...

Setting up nginx-full (1.2.3-0ubuntu0ppa3~lucid) ...
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] still could not bind()
nginx.

and start & restart don't work...
$sudo /etc/init.d/nginx start
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
$sudo /etc/init.d/nginx restart
Restarting nginx: nginx.
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Just get the nginx worker process ids and then kill them.

for example:
$ ps aux | grep nginx
www-data 4619 0.0 0.2 10584 1340 ? S 18:51 0:00 nginx: worker process
www-data 4620 0.0 0.2 10584 1340 ? S 18:51 0:00 nginx: worker process
www-data 4621 0.0 0.2 10584 1340 ? S 18:51 0:00 nginx: worker process

$ kill -9 4619 4620 4621

Hope that helps anyone with this problem.

"killall nginx; sleep 3; killall -9 nginx" would also work

On Thu, 09 Aug 2012 01:09:34 -0000
Thaddeus Albers <email address hidden> wrote:

> Thanks for the fix.
>
> Note for others:
> If you see the following during install...
>
> Setting up nginx-full (1.2.3-0ubuntu0ppa3~lucid) ...
> Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address
> already in use) nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address
> already in use) nginx: [emerg] still could not bind()
> nginx.
>
> and start & restart don't work...
> $sudo /etc/init.d/nginx start
> Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address
> already in use) $sudo /etc/init.d/nginx restart
> Restarting nginx: nginx.
> nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
>
> Just get the nginx worker process ids and then kill them.
>
> for example:
> $ ps aux | grep nginx
> www-data 4619 0.0 0.2 10584 1340 ? S 18:51 0:00 nginx:
> worker process www-data 4620 0.0 0.2 10584 1340 ? S 18:51
> 0:00 nginx: worker process www-data 4621 0.0 0.2 10584 1340 ?
> S 18:51 0:00 nginx: worker process
>
> $ kill -9 4619 4620 4621
>
> Hope that helps anyone with this problem.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers