Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an init.d script for nginx that normally works fine. However, after a reboot it doesn't work properly and the worker process would die leaving just the master process.

nginx has some mongodb stuff (nginx-gridfs) compiled in and needs to start after mongodb which is being started by upstart.

That's all I've been able to figure out after some troubleshooting. I believe I have to change over nginx to upstart and make it dependent on mongo. How can I do that?

share|improve this question
up vote 2 down vote accepted

Since nginx-gridfs connects to mongodb, the db server should already be running and ready. This was causing a problem. First I removed the /etc/init.d/nginx script using 'update-rc.d remove nginx' Then I created an 'upstart' script in /etc/init/nginx.conf :

# nginx

description "nginx http daemon"

#start on mongodb  
start on (local-filesystems
    and net-device-up IFACE=lo
    and started mongodb) 
stop on stopped mongodb

env DAEMON=/usr/local/nginx/sbin/nginx 
env PID=/usr/local/nginx/logs/

expect fork 
respawn limit 10 5

pre-start script
        $DAEMON -t
        if [ $? -ne 0 ]
                then exit $?
        # Add a sleep of 10 sec. to allow mongodb to finish starting up
        sleep 10 
end script

exec $DAEMON

This fixed the problem for me.

share|improve this answer
Try to kill nginx. Respawn will never happen. And sudo start nginx says: start: Job is already running: nginx. – Ivan Black Sep 14 '15 at 1:30

You probably didn't set it up correctly use update-rc.d <yourscript> start [startorder] 2 3 4 5 . stop [end order] 0 1 6 . to create the runlevel links.

If your script is done correctly, it accepts start and stop command, check that all dependencies are started before your script, normally 40 is safe for startorder, and that all services that depend of your script end before it, 20 is probably good enough for endorder.

To better know how to make a good script take a look to the ones in your /etc/init.d

share|improve this answer
Edited my question to clarify. I believe I did use update-rc.d properly. Anyway, figured out how to set up the 'upstart' script. – user146668 Nov 23 '12 at 6:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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