How to fix the NGINX error “Failed to read PID from file”, quick and easy
以下是有关如何修复错误消息的提示:
nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
或者
openresty.service: Failed to parse PID from file /run/openresty.pid: Invalid argument
此行为是一个已知错误,由nginx和systemd之间的竞争条件引起。 Systemd期望在nginx有时间创建之前填充PID文件。要修复错误,您必须创建该文件。
Step 1. 创建目录:/etc/systemd/system/nginx.service.d
Create a directory named nginx.service.d in /etc/systemd/system/:
mkdir /etc/systemd/system/nginx.service.d
Step 2. Print data to file
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
确保在其自己的行上输入>之后的字符串,以便printf将其输出写入配置文件:
/etc/systemd/system/nginx.service.d/override.conf
Step 3. Reload the daemon
Reload systemd manager configuration:
systemctl daemon-reload
This will rerun all generators, reload all unit files and recreate the entire systemd dependency tree.
Step 4. Restart NGINX
This line will restart NGINX for you:
systemctl restart nginx
The error should be fixed now.
An alternative workaround
Another workaround is removing the PIDFile option and adding the line:
ExecStopPost=/bin/rm -f /run/nginx.pid
https://www.cloudinsidr.com/content/heres-fix-nginx-error-failed-read-pid-file-linux/
发表回复