Nginx 服务行为异常,systemd 与 upstart?

Nginx 服务行为异常,systemd 与 upstart?

我有 Ubuntu 16.04 LTS 并且我使用过本指南构建 Nginx这个LDAP模块。

我相信我的问题是该指南使用了较旧的 /etc/init.d 脚本,该脚本在 16.04 上运行得不太好。然后我尝试了这个较新的脚本对于 systemd 来说,它可以工作,但我得到了一些奇怪的服务行为。

目前我可以“systemctl start nginx”并且服务启动(网络服务器工作),但我必须按 ctrl-c 才能取回命令。 “systemctl status nginx”将在下面显示。 “systemctl stop nginx”不会停止 nginx Web 服务器。为了停止 nginx,我必须“systemctl Kill nginx”。我确实发现 /usr/local/nginx/logs/nginx.pid 文件丢失,但自己创建它并没有修复该错误。

从这里我有点迷失了,我该如何解决这个问题?

    ● nginx.service - LSB: nginx init.d dash script for Ubuntu or other *nix.
   Loaded: loaded (/etc/init.d/nginx; bad; vendor preset: enabled)
   Active: activating (start) since Thu 2018-04-05 15:44:43 EDT; 48s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 28806 ExecStart=/etc/init.d/nginx start (code=exited, status=0/SUCCESS)
    Tasks: 2
   Memory: 9.2M
      CPU: 29ms
   CGroup: /system.slice/nginx.service
           ├─28815 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.con
           └─28816 nginx: worker process                   

Apr 05 15:44:43 ubuntu systemd[1]: Starting LSB: nginx init.d dash script for Ubuntu or other *nix....
Apr 05 15:44:43 ubuntu nginx[28806]:  * Starting Nginx Server...
Apr 05 15:44:43 ubuntu nginx[28806]:    ...done.
Apr 05 15:44:43 ubuntu systemd[1]: nginx.service: PID file /usr/local/nginx/logs/nginx.pid not readable (yet?) after start: No such file or directory

答案1

根据您发布的输出,您没有使用 systemd 服务单元,但仍在使用 init.d 脚本。

可能您没有正确添加服务单元并重新加载 systemd,或者您的旧 init.d 脚本正在干扰,或者您正在服务单元中执行一些未显示的操作。这不应该是您发布的 systemd 文件的行为。

如果内容您发布的 systemd 服务单位确实位于正确的位置 ( /etc/systemd/system/nginx.service),并且您已发出systemctl daemon-reload加载新服务单元的命令,然后尝试将您的 nginx init.d 文件 ( /etc/init.d/nginx) 移开,或者如果不再需要它,请将其删除。

这里的关键是状态输出顶部的一行“Loaded”,它指示正在使用的脚本。您需要确保输出告诉您它正在使用 systemd。查看您发布的 nginx 服务单元,只要您将其设置PIDFile到正确的位置,它就应该正常运行。

相关内容