LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 05-02-2012, 09:14 PM   #1
sohmc
Member
 
Registered: Aug 2002
Location: Alexandria
Distribution: ubuntu 12.04.2
Posts: 217

Rep: Reputation: 30
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?
 
Old 05-03-2012, 12:28 PM   #2
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,124

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
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?
 
Old 05-03-2012, 04:24 PM   #3
sohmc
Member
 
Registered: Aug 2002
Location: Alexandria
Distribution: ubuntu 12.04.2
Posts: 217

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Noway2 View Post
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.
 
Old 05-04-2012, 04:27 AM   #4
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,124

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
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
 
Old 05-07-2012, 05:34 PM   #5
sohmc
Member
 
Registered: Aug 2002
Location: Alexandria
Distribution: ubuntu 12.04.2
Posts: 217

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Noway2 View Post
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 View Post
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.
 
  


Reply

Tags
mysql, postfix, virtual


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 16 12-10-2012 02:34 AM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Software 3 06-28-2007 11:46 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 03:35 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM


All times are GMT -5. The time now is 05:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration