LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   postfix not working with mysql socket but with localhost (http://www.linuxquestions.org/questions/linux-server-73/postfix-not-working-with-mysql-socket-but-with-localhost-943005/)

sohmc 05-02-2012 10:14 PM

postfix not working with mysql socket but with localhost
 
After looking through the various threads that are similar to this, it seems that this one is unique.

I've configured postfix to use mysql as it's source of aliases. Needless to say, everything works when I use localhost as the hosts:

Code:

hosts = 127.0.0.1
user = postfix_user
password = somepassword

dbname = postfix_db
query = SELECT goto FROM alias WHERE address='%s' AND active=1

However, when I change hosts to be:
Code:

hosts = unix:/var/run/mysqld/mysqld.sock
everything stops working:
Code:

May  2 21:23:47 helo postfix/trivial-rewrite[11776]: warning: connect to mysql server unix:/var/run/mysqld/mysqld.sock: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
May  2 21:23:47 helo postfix/trivial-rewrite[11776]: fatal: mysql:/etc/postfix/virtual/domains.cf(0,lock|fold_fix): table lookup problem
May  2 21:23:48 helo postfix/master[9880]: warning: process /usr/lib/postfix/trivial-rewrite pid 11776 exit status 1

The socket is set to 777 and I am able to successfully use mysql via:
Code:

mysql -u postfix_user -p --socket=/var/run/mysqld/mysqld.sock
What's going on that postfix can't use the socket by the mysql client can?

Noway2 05-03-2012 01:28 PM

A couple of things to check:
1 - in your domains.cf file, if you have any spaces at the end of the line following the text, delete them. This will cause a failure.
2 - Is either SELinux or Apparmor preventing access to the pid file? (Check your logs)
3 - when you restart or reload Postfix, do you get any warning or error messages in your mail log or syslog that could point to a problem?

sohmc 05-03-2012 05:24 PM

Quote:

Originally Posted by Noway2 (Post 4669597)
A couple of things to check:
1 - in your domains.cf file, if you have any spaces at the end of the line following the text, delete them. This will cause a failure.
2 - Is either SELinux or Apparmor preventing access to the pid file? (Check your logs)
3 - when you restart or reload Postfix, do you get any warning or error messages in your mail log or syslog that could point to a problem?

Answer to 1:
domains.cf is also a mysql table. I have virtualized both files; however, they both work with 127.0.0.1 but not with the socket.

2:
I thought I removed all instances of SELinux. I've never heard of apparmor. I did a dpkg -get-selections for both and did not find them installed.

3:
No, nothing that indicates the files failed to load. I only get the messages when an e-mail comes in.

Interestingly, I left aliases to use the MYSQL the socket and the domain to still use 127.0.0.1. Aliases work but domains do not.

Is this a limitation on postfix that it can't use sockets when retrieving domain names?

Noway2 05-04-2012 05:27 AM

You should be able to use MySQL for all of the lookups, alias, domain, etc. Looking through the postfix manuals, I found this interesting statement that I think may be related to the problem (link here. Pay particular attention to the note at the bottom)
Quote:

hosts The hosts that Postfix will try to connect to and
query from. Specify unix: for UNIX domain sockets,
inet: for TCP connections (default). Example:
hosts = host1.some.domain host2.some.domain : port
hosts = unix:/file/name

The hosts are tried in random order, with all con-
nections over UNIX domain sockets being tried
before those over TCP. The connections are auto-
matically closed after being idle for about 1
minute, and are re-opened as necessary. Postfix
versions 2.0 and earlier do not randomize the host
order.

NOTE: if you specify localhost as a hostname even
if you prefix it with inet:, MySQL will connect to
the default UNIX domain socket. In order to
instruct MySQL to connect to localhost over TCP you
have to specify
hosts = 127.0.0.1
A few more things to check:
1 - check the bind address on which mysql is running and make sure that this hasn't been blocked in a firewall somewhere. This may be why localhost is working, but othe connections are not. The fact that you can connect to mysql via the socket, but postfix can't suggests this probably isn't the problem, but it is worth double checking.
2 - Check your configuration file again. Look very carefully for any form of sytax error, such as a ' versus `, especially if you copied from any how to document.
3 - If you haven't be sure to check your mySQL logs. There may be information as to the problem in there.

This seems to be a semi common problem, but has a few different causes. You might try to Google on the error message "fatal: mysql:/etc/postfix/virtual/domains.cf(0,lock|fold_fix):". Here are a few hits from that with different causes:
1) http://www.howtoforge.com/forums/arc...p/t-53917.html
2) http://www.howtoforge.com/forums/arc...p/t-45905.html
3) http://askubuntu.com/questions/79226...ld-mysqld-sock
4) http://askubuntu.com/questions/69380...it/69450#69450

sohmc 05-07-2012 06:34 PM

Quote:

Originally Posted by Noway2 (Post 4670091)
A few more things to check:
1 - check the bind address on which mysql is running and make sure that this hasn't been blocked in a firewall somewhere. This may be why localhost is working, but othe connections are not. The fact that you can connect to mysql via the socket, but postfix can't suggests this probably isn't the problem, but it is worth double checking.
2 - Check your configuration file again. Look very carefully for any form of sytax error, such as a ' versus `, especially if you copied from any how to document.
3 - If you haven't be sure to check your mySQL logs. There may be information as to the problem in there.

The thing that doesn't make sense is that only thing I'm changing is the hosts line. It works fine when I do "127.0.0.1" The problem only arises when I change it to the socket.

Keep in mind that the socket works fine for the aliases file.

Quote:

Originally Posted by Noway2 (Post 4670091)
This seems to be a semi common problem, but has a few different causes. You might try to Google on the error message "fatal: mysql:/etc/postfix/virtual/domains.cf(0,lock|fold_fix):". Here are a few hits from that with different causes:
1) http://www.howtoforge.com/forums/arc...p/t-53917.html
2) http://www.howtoforge.com/forums/arc...p/t-45905.html
3) http://askubuntu.com/questions/79226...ld-mysqld-sock
4) http://askubuntu.com/questions/69380...it/69450#69450

I've goggled the error and haven't gotten very good results. A lot of the solutions cover how to get the socket working (which it is) to making sure that the inet portion works on 127.0.0.1 instead of localhost.

It's just so odd that it works for one type of file but not the other. Here's a diff of the two files:
Code:

root@helo:/etc/postfix/virtual# diff aliases.cf domains.cf
1,2c1,2
< hosts = unix:/var/run/mysqld/mysqld.sock
< #hosts = 127.0.0.1
---
> #hosts = unix:/var/run/mysqld/mysqld.sock
> hosts = 127.0.0.1
7c7
< query = SELECT goto FROM alias WHERE address='%s' AND active=1
---
> query = SELECT domain FROM domain WHERE domain='%s' AND backupmx=0 AND active=1

I'm to the point of actually e-mailing the postfix list serve but wanted to see if anyone else had the same issue. it seems like my issue is very specific.


All times are GMT -5. The time now is 03:18 AM.