2

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?

2 Answers 2

2

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/nginx.pid

expect fork 
respawn 
respawn limit 10 5

pre-start script
        $DAEMON -t
        if [ $? -ne 0 ]
                then exit $?
        fi
        # 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.

1
  • Try to kill nginx. Respawn will never happen. And sudo start nginx says: start: Job is already running: nginx.
    – Ivan Black
    Sep 14, 2015 at 1:30
0

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

1
  • 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, 2012 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .