Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Here's my situation whenever I reboot:

$ systemctl --failed
UNIT          LOAD   ACTIVE SUB    DESCRIPTION
nginx.service loaded failed failed A high performance web server and a reverse proxy server
...
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2014/01/18 05:44:47 [emerg] 254#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
$ cd /run
$ ls -al | grep nginx
$ sudo systemctl start nginx
$ ls -al | grep nginx
-rw-r--r--  1 root     root        4 Jan 18 06:27 nginx.pid

I don't understand how nginx.pid could have incorrect permissions before it's even created, or what one would do to resolve that.

I'm using Arch and I've seen similar issues relating to chroot-jail, but I did not install nginx in a chroot.

share|improve this question
    
I would suggest that you ensure that there doesn't already exist a pid file with wrong owner or permission. I had a similar issue where I was running uwsgi in a python virtual env and pid file was not accessible because there was already a pid file existing with wrong permissions which someone had created earlier. –  APZ Jan 18 at 19:43
    
Thanks for taking a look. That was my first thought as well, which is why I cd'd to /run and greped for the file. As you can see above, the pid file isn't created until I manually start nginx. I tried changing the permissions, but they're reset after each reboot. –  Ryne Everett Jan 18 at 19:58
    
I am a Ubuntu user mainly and whenever I have start nginx or any service I use sudo . I see you doing nginx -t (not sure of the whole systemctl functioning) but it might be worth check as what user is nginx trying to start because pid is owned by root. –  APZ Jan 18 at 20:28
add comment

1 Answer 1

up vote 0 down vote accepted

The issue seems to be you are using an unprivileged user to test the Nginx configuration. When the test occurs, it attempts to create /run/nginx.pid, but fails and this causes the configuration test to fail. Try running nginx as root.

$ sudo nginx -t

or

$ su - -c "nginx -t"

This way, the Nginx parent process will have the same permission it would when run by systemctl.

If this resolves the error at testing, but not when run from systemctl, you may want to check this page on investigating systemd errors.

share|improve this answer
    
Absolutely right. Silly mistake. At least now I know that the testing error has nothing to do with my actual problem. –  Ryne Everett Jan 18 at 22:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.