Postfix is throwing up an error saying:
Jul 9 14:41:26 tmail postfix/trivial-rewrite[4342]: 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) Jul 9 14:41:26 tmail postfix/trivial-rewrite[4342]: fatal: mysql:/etc/postfix/mysql-yaa-aliases.cf(0,lock|fold_fix): table lookup problem
In main.cf I have:
virtual_alias_maps = mysql:/etc/postfix/mysql-yaa-aliases.cf
In mysql-yaa-aliases.cf I have:
hosts = unix:/var/run/mysqld/mysqld.sock
# hosts = 127.0.0.1
user = yaa_admin
password = ********
dbname = yaa
query = SELECT dest FROM yaa_active_aliases WHERE address='%s'
If I use 127.0.0.1 it works (not ideal as I would prefer the speed of a socket.) Also if I test the socket with postmap it works:
# postmap -q "[email protected]" mysql:/etc/postfix/mysql-yaa-aliases.cf
[email protected], [email protected]
When I use strace on the trivial-rewrite daemon I get:
connect(11, {sa_family=AF_FILE, path="/var/run/mysqld/mysqld.sock"}, 110) = -1 ENOENT (No such file or directory)
Whereas strace using postmap I get:
connect(4, {sa_family=AF_FILE, path="/var/run/mysqld/mysqld.sock"}, 110) = 0
BTW - Currently running Postfix 2.7, but the fault still shows with 2.9
FOUND IT :) - trivial-rewrite takes place in a chroot jail, therefore the socket file REALLY doesn't exist.
The solution (thanks to https://serverfault.com/questions/229389 for helping me with this) is to add this to the /etc/fstab:
/var/run/mysqld /var/spool/postfix/var/run/mysqld bind defaults,bind 0 0
Thus allowing Postfix to keep its chroot config, and giving it access to the mysql socket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With