1

In my usecase, I am trying to write an upstart script for nginx service. Here is my content,

#nginx upstart script
description "start and stop nginx server"

start on (net-device-up
and local-filesystems
and runlevel [2345])

stop on runlevel [016]

respawn
respawn limit 5 30

console output

exec service nginx start

But this does not work because we need to remove the pid etc after stop and start.

Could someone help me with this? I am using amazon linux [ec2].

Dany
  • 2,692
  • 7
  • 44
  • 67

1 Answers1

1

The command service nginx start is a call to a System V init script that manages the nginx daemon just like upstart would. You want upstart to manage the daemon like the init script does, rather than calling the init script. You can see what the init script does with cat /etc/init.d/nginx

nginx have an upstart example on their wiki.

# nginx

description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"

start on (filesystem and net-device-up IFACE!=lo)
stop on runlevel [!2345]

env DAEMON=/usr/sbin/nginx
env PID=/var/run/nginx.pid

expect fork
respawn
respawn limit 10 5
#oom never

pre-start script
        $DAEMON -t
        if [ $? -ne 0 ]
                then exit $?
        fi
end script

exec $DAEMON
Matt
  • 68,711
  • 7
  • 155
  • 158