Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open file /var/log/nginx/access.log: open /var/log/nginx/access.log: permission denied #354

Open
ghost opened this issue Oct 10, 2023 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 10, 2023

whuy i recieve fail state in start service?
$ systemctl start prometheus-nginxlog-exporter

The log contains the following errors ($ journalctl -f)
...
Oct 11 01:36:18 xxxx.fvds.ru prometheus-nginxlog-exporter[2058796]: 2023-10-11T01:36:18.887+0300 fatal prometheus-nginxlog-exporter/main.go:213 Unable to open file /var/log/nginx/access.log: open /var/log/nginx/access.log: permission denied

....
Oct 11 01:36:19 xxxx.fvds.ru systemd[1]: prometheus-nginxlog-exporter.service: Main process exited, code=exited, status=1/FAILURE
Oct 11 01:36:19 xxxx.fvds.ru systemd[1]: prometheus-nginxlog-exporter.service: Failed with result 'exit-code'.
Oct 11 01:36:19 xxxx.fvds.ru systemd[1]: prometheus-nginxlog-exporter.service: Scheduled restart job, restart counter is at 5.
Oct 11 01:36:19 xxxx.fvds.ru systemd[1]: Stopped NGINX metrics exporter for Prometheus.
Oct 11 01:36:19 xxxx.fvds.ru systemd[1]: prometheus-nginxlog-exporter.service: Start request repeated too quickly.
Oct 11 01:36:19 xxxx.fvds.ru systemd[1]: prometheus-nginxlog-exporter.service: Failed with result 'exit-code'.
Oct 11 01:36:19 xxxx.fvds.ru systemd[1]: Failed to start NGINX metrics exporter for Prometheus.

Help me please!

@ghost ghost added the bug label Oct 10, 2023
@martin-helmich
Copy link
Owner

open /var/log/nginx/access.log: permission denied

This looks like a straightforward permissions error; which user owns the access log file (and what are the file's permissions), and under which user does the exporter run? Does it work when you're removing the CapabilityBoundingSet directive from the systemd unit?

@dirkvranckaert
Copy link

@martin-helmich I just ran into the same issue. The prometheus-nginxlog-exporter service was running fine for it's first 24 hours, all of the sudden Nginx rolled the files and created a new main log file and the prometheus-nginxlog-exporter stopped because the file could not be accessed, permissions denied...

I've tried your solution of removing CapabilityBoundingSet and that works perfect! Thanks!
Note: When doing so you may not forget to:

  • Reload the deamon: systemctl daemon-reload
  • Restart the service: sudo systemctl restart prometheus-nginxlog-exporter

@yatesliang
Copy link

If you use k8s to deploy this exporter, one possible solution is to run the exporter container as the nginx log files owner by applying security context:
https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

@HectorB-2020
Copy link

solution of removing CapabilityBoundingSet and that works perfect!

@dirkvranckaert, I also end up with removing this directive.

removing the CapabilityBoundingSet directive from the systemd unit

@martin-helmich, can you share original reason why this directive was added to the systemd unit? Has anybody confirmed this exporter working with this directory left in the systemd unit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants