linux - 如何为nginx服务编写upstart脚本?

标签 linux nginx service amazon-ec2 upstart

在我的用例中,我正在尝试为 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/

相关文章:

linux - dlsym 如何从剥离的二进制库中成功导入函数?

java - 调试一个非常难以重现的 Java Web 应用程序问题(前端)

ios - 尝试使用 armv6 和 arv7 架构为 iPhoneOS 平台编译 FFMPEG 库

linux - 为什么以下转换命令会导致段错误?

nginx - GitLab 发布临时 IP 禁令 - 403 被禁止

file - 网盘的 Camel 文件组件

php - 在 VPS 服务器中运行 PHP 脚本 "forever"

Android:stopService 不调用 onDestroy

linux - 是否可以用 gcc 以外的东西编译 Linux 内核

django - Nginx、Gunicorn、Django、Celery(Redis) : upstream prematurely closed connection 502 gateway