connie
connie

Reputation: 117

centos 7: nginx Failed to read PID from file /run/nginx.pid: Invalid argument

I can access the nginx welcome page after installing nginx. However, when i run systemctl status nginx, I get this warning:

systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument

Can you please tell me what causes this problem and how to fix it? Thanks.

Detailed response message:

nginx.service - The nginx HTTP and reverse proxy server    
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)    
Active: active (running) since Thu 2017-03-02 06:43:24 CST; 2s ago   
Process: 24007 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)   
Process: 8377 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)   
Process: 8374 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)   
Process: 8373 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)  
Main PID: 8380 (nginx)    CGroup: /system.slice/nginx.service
           |-8380 nginx: master process /usr/sbin/ngin
           `-8381 nginx: worker proces

Mar 02 06:43:24 VM_134_114_centos systemd[1]: Starting The nginx HTTP and reverse proxy server... 
Mar 02 06:43:24 VM_134_114_centos nginx[8374]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
Mar 02 06:43:24 VM_134_114_centos nginx[8374]: nginx: configuration file /etc/nginx/nginx.conf test is successful 
Mar 02 06:43:24 VM_134_114_centos systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument 
Mar 02 06:43:24 VM_134_114_centos systemd[1]: Started The nginx HTTP and reverse proxy server.

Upvotes: 2

Views: 11160

Answers (2)

Stephen Tetreault
Stephen Tetreault

Reputation: 787

Rebooting the server resolved the error for me. Not pretty but it worked.

Upvotes: 0

Mark Stosberg
Mark Stosberg

Reputation: 13381

I don't think you do fix it.

First, notice that the PID file is intentionally being removed just before Nginx starts. You can see that in the output you posted:

ExecStartPre=/usr/bin/rm -f /run/nginx.pid

Why? The answer is a comment in the Nginx service file:

# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid

So if Nginx is running normally and you you can stop/start it fine, I think you can ignore that warning in the logs.

Upvotes: 4

Related Questions