Can’t open PID file /var/run/nginx.pid (yet?) after start: Too many levels of symbolic links

Went to the server I am, I think — will update it ( have not put the update on it). Performed the update. Wanted something pomenyat in the config with nginx ( changed that wasn’t supposed to break the web server). But after restart the service — the web server’s down anyway… Bidnenko!

PS: If you ask what I gun do not update packages or the OS — you don’t. To lyagla all! This is the answer to the question ( if anyone will).

Error look like this:

(captain-notes)─(✗)─(10:08 PM Wed Apr 29) └─(/home)─(5 files, 28Kb)─> systemctl status nginx.service ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: activating (start) since Wed 2020-04-29 22:06:39 EEST; 1min 54s ago Docs: http://nginx.org/en/docs/ CGroup: /system.slice/nginx.service ├─2197 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf ├─2198 nginx: worker process ├─2199 nginx: worker process ├─2200 nginx: worker process ├─2201 nginx: worker process └─2202 nginx: cache manager process Apr 29 22:06:39 captain-notes systemd[1]: Starting nginx - high performance web server... Apr 29 22:06:39 captain-notes systemd[1]: Can't open PID file /var/run/nginx.pid (yet?) after start: Too many levels of symbolic links

Proceed to the solution!

Can’t open PID file /var/run/nginx.pid (yet?) after start: Too many levels of symbolic links

Let me give a couple of solyushenov that I found in the Internet. Tried a few of them fixed ICU.

Solution 1

The folder /var/run is not a symlink (symbolic link) to /run directory. You can check this:

ls-ld /var/run drwxr-xr-x 12 root root 4096 Apr 29 22:10 /var/run

Also, the folder /run exists on the server, check:

# ls-ld /run drwxr-xr-x 32 root root 980 Apr 29 22:12 /run

Also, you can granute the nginx configuration:

# grep -ir pid /etc/nginx /etc/nginx/nginx.conf.default:#pid /var/run/nginx.pid; /etc/nginx/nginx.conf:#pid /var/run/nginx.pid;

And actually, the solution here:

# mv /var/run /var/run_orig && ln-s ../run /var/run && ls-ld /var/run

Restart the server with nginx and it should fix the problem.

I have not solved… Try another solution….

Solution # 2

Look what we have in nginx config:

# grep -ir pid /etc/nginx /etc/nginx/nginx.conf:pid /run/nginx.pid; /etc/nginx/nginx.conf:#pid /var/run/nginx.pid; 

Find the line:

pid /var/run/nginx.pid;

And change it to:

pid /run/nginx.pid;

PS: you Can use SED to do replacement:

# sed -i 's/pid /var/run/nginx.pid/pid /run/nginx.pid/' /etc/nginx/nginx.conf

On, open:

# vim /lib/systemd/system/nginx.service

And change the line:

PIDFile=/var/run/nginx.pid

On:

PIDFile=/run/nginx.pid

To apply changes, execute:

# systemctl daemon-reload

Then, restart the web server:

# service nginx restart

In the end, we get:

┌(captain-notes)─(✓)─(10:12 PM Wed Apr 29) └─(/home)─(5 files, 28Kb)─> systemctl status nginx.service ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2020-04-29 22:12:24 EEST; 10s ago Docs: http://nginx.org/en/docs/ Process: 2996 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 2997 (nginx) CGroup: /system.slice/nginx.service ├─2997 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf ├─2998 nginx: worker process ├─2999 nginx: worker process ├─3000 nginx: worker process ├─3001 nginx: worker process ├─3002 nginx: cache manager process └─3003 nginx: cache loader process Apr 29 22:12:24 captain-notes systemd[1]: Starting nginx - high performance web server... Apr 29 22:12:24 captain-notes systemd[1]: Started nginx - high performance web server. 

I forgot to use strace to catch the error, but normal behavior is:

# strace /run/nginx.pid execve("/run/nginx.pid", ["/run/nginx.pid"], 0x7ffcaef1ce40 /* 29 vars */) = -1 EACCES (Permission denied) open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, an st_size=2502, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8def0a3000 read(3, "# Locale name alias data base.n#"..., 4096) = 2502 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7f8def0a3000, 4096) = 0 open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8def0a3000 write(2, "strace: exec: Permission deniedn", 32strace: exec: Permission denied ) = 32 exit_group(1) = ? +++ exited with 1 +++ 

NOTE! This problem can casata not only nginx, but can affect mysql or fail2ban and perhaps other services.

That’s all the article is “Can’t open PID file /var/run/nginx.pid (yet?) after start: Too many levels of symbolic links” — completed!

Source: linux-notes.org

(Visited 13 times, 1 visits today)