Cloud Insidr

Cybersecurity in the Age of the Machine

  • Subscribe!
  • Privacy Policy
  • Legal
  • Contact Us

Join us on Twitter: @CloudInsidr

  • news & alerts
    • events
    • industry analysis
    • industry gossip
    • people
  • cloud, edge & co.
    • AWS
    • administration & orchestration
      • web servers in the cloud
      • mail servers
      • databases
  • cybersec & warfare
    • encryption
  • blockchain
Home cloud, edge and everything in between administration and orchestration web servers in the cloud NGINX How to fix the NGINX error “Failed to read PID from file”, quick and easy
How to fix the NGINX error “Failed to read PID from file”, quick and easy

Cloud Insidr 2017-12-16 9 Comments

How to fix the NGINX error “Failed to read PID from file”, quick and easy

Here’s a tip on how to fix the error message:

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

quick and easy. This fix should do it for you.

This behavior is a known bug, caused by a race condition between nginx and systemd. Systemd is expecting the PID file to be populated before nginx had the time to create it.

To fix the error, you have basically two options.

Option 1: create the PID file

To fix the error, you have to create the PID file manually.

Step 1. Create the directory /etc/systemd/system/nginx.service.d

Create a directory named nginx.service.d in /etc/systemd/system/:

mkdir /etc/systemd/system/nginx.service.d

Should the system complain that it already exists, ignore and  move on to Step 2.

Step 2. Print data to file

Execute:

printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf

This is a one-liner. printf will write its output into the configuration file /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.

Option 2: an alternative workaround

Another workaround is removing the PIDFile option and adding the line:

ExecStopPost=/bin/rm -f /run/nginx.pid

 

You can find the full documentation of this bug at:

https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864

If you experience this problem, SELinux could be preventing php-fpm from accessing a port. Just a hint. Try

journalctl -xe

for guidance on your next steps.

Filed Under: NGINX Tagged With: NGINX, systemd

Comments

  1. Sanders Gutiérrez says

    2019-10-20 at 6:30 pm

    Option 1 is perfect, work well for me.

    Reply
  2. John Kennel says

    2019-06-01 at 8:11 am

    Wonderful post! Thanks for sharing!

    Reply
  3. Luke says

    2019-04-23 at 12:21 pm

    I had to do this as root for it to work.

    Reply
    • Cloud Insidr says

      2019-04-24 at 6:40 am

      Hi Luke:
      By the way, you should fix your website security headers:
      https://securityheaders.com/?q=https%3A%2F%2Flukeclopez.github.io%2F&followRedirects=on

      I hope it helps! :-)

      Reply
  4. vlarie says

    2019-04-17 at 10:05 am

    Super quick and easy fix, just like you said. Thanks!

    Reply
  5. Cloud Insidr says

    2020-04-08 at 3:24 pm

    > The Transfusion app currently supports both HTTP/S

    Thanks for the information.
    IMHO, HTTP is history. All connections should use HTTPS only.

    Reply

Trackbacks

  1. open() “/run/nginx.pid” failed (13: Permission denied) - Boot Panic says:
    2022-03-08 at 3:21 am

    […] It may be a bug. “This behavior is a known bug, caused by a race condition between nginx and systemd. Systemd is expecting the PID file to be populated before nginx had the time to create it.” https://www.cloudinsidr.com/content/heres-fix-nginx-error-failed-read-pid-file-linux/ […]

    Reply
  2. Resolved: open() "/run/nginx.pid" failed (13: Permission denied) - Resolved Problem says:
    2022-03-03 at 6:14 am

    […] It may be a bug. “This behavior is a known bug, caused by a race condition between nginx and systemd. Systemd is expecting the PID file to be populated before nginx had the time to create it.” https://www.cloudinsidr.com/content/heres-fix-nginx-error-failed-read-pid-file-linux/ […]

    Reply
  3. Confluence: WellSky Blood Management says:
    2020-04-06 at 9:25 am

    Inbound Traffic Splitting

    The Transfusion app currently supports both HTTP/S

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe

SSL/TLS Certificate Square (250 x 250)

Tag Cloud

AWS AWS Billing Dashboard AWS Config AWS Cost Explorer AWS EBS AWS Resource Explorer AWS Tag Editor AWS Trusted Advisor cipher suites cyber security Diffie-Hellman EBS EC2 ECDHE Five Eyes Alliance FLAME HSTS HTTP/2 Java Linux Log4j NGINX NVMe PHP RCE Route 53 SELinux SHA-1 SHA-2 SQL SSL TLS

Pearson Education (InformIT)

SSL/TLS Certificate Medium Rectangle (300 x 250)

©2022 CybrAnalytiqa OÜ

  • Content purchasing and syndication