HAproxy- Could not open configuration file: Permission denied

configurationhaproxy

I am having some test with HAproxy as Load Balancer. I installed it and configured too, even the log with rsyslog. I checked the configuration with haproxy -c -f /etc/haproxy/haproxy.cnf and with haproxy -d -f /etc/haproxy.cnf. All seem to be fine, but after starting haproxy, systemctl start haproxy, I executed systemctl status haproxy, it showed me this:

haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled)
   Active: inactive (dead) since jue 2015-07-02 14:47:13 CDT; 7s ago
  Process: 29832 ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid (code=exited, status=0/SUCCESS)
 Main PID: 29832 (code=exited, status=0/SUCCESS)
systemd[1]: Started HAProxy Load Balancer.
haproxy-systemd-wrapper[29832]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
haproxy-systemd-wrapper[29832]: [ALERT] 182/144713 (29833) : Could not open configuration file /etc/haproxy/haproxy.cfg : Permission denied
haproxy-systemd-wrapper[29832]: haproxy-systemd-wrapper: exit, haproxy RC=256

Logically this must point to file permissions, so I had 777 permissions to haproxy.cnf with the same result. I test chown haproxy:haproxy, same result.

I had goggle a lot, but I don't find a solution to that problem.

Best Answer

Maybe there is some misconfiguration on Selinux(if you are using a Redhat based distribution) or on apparmor(if you are using ubuntu).

Try to stop them in order to verify if this is the problem. You can also try to read the configuration file using the user running the haproxy daemon using the command:

sudo -u <haproxy_user> cat /etc/haproxy/haproxy.cfg