在我的用例中,我正在尝试为 nginx 服务编写一个 upstart 脚本。这是我的内容,
#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
但这不起作用,因为我们需要在停止和启动后删除 pid
等。
有人可以帮我解决这个问题吗?我正在使用亚马逊 Linux [ec2]。
最佳答案
命令 service nginx start
是对 System V init 脚本的调用,它像 upstart 一样管理 nginx 守护进程。您希望 upstart 像 init 脚本一样管理守护进程,而不是调用 init 脚本。你可以看到 init 脚本用 cat/etc/init.d/nginx
nginx 有一个 Upstart 的例子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
关于linux - 如何为nginx服务编写upstart脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38657142/