postfix not working with mysql socket but with localhost
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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?
Last edited by sohmc; 05-03-2012 at 04:26 PM.
Reason: grammar errors.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.