Saturday, July 27, 2013

Postfix Not Running at Startup on CentOS - SOLVED

My server was not able to send email. Further investigation showed that postfix was not running at startup.

After running
# postfix check

I got this output (in blue):
postfix/postfix-script: warning: not owned by root: /etc/postfix/main.cf

Running "ls -l" verified that main.cf was indeed not owned by root. (This is a file that I imported from a recent working configuration. I forgot to reset the proper permissions).

# ls -l /etc/postfix
total 232
drwxr-xr-x.  2 root root  4096 Jul 27 16:14 .
drwxr-xr-x. 64 root root  4096 Jul 27 16:27 ..
-rw-r--r--.  1 root root 19579 Dec  3  2011 access
-rw-r--r--.  1 root root     0 Jul 27 15:46 body_checks
-rw-r--r--.  1 root root 11681 Dec  3  2011 canonical
-rw-r--r--.  1 root root  9904 Dec  3  2011 generic
-rw-r--r--.  1 root root 18287 Dec  3  2011 header_checks
-rw-r--r--.  1 aco  aco  28437 Jul 27 16:10 main.cf
-rw-r--r--.  1 root root 28437 Jul 27 15:37 main.cf.bak
-rw-r--r--.  1 root root 27014 Jul 27 15:24 main.cf.orig
-rw-r--r--.  1 root root  5113 Dec  3  2011 master.cf
-rw-r--r--.  1 root root  6816 Dec  3  2011 relocated
-rw-r--r--.  1 root root 12500 Dec  3  2011 transport
-rw-r--r--.  1 root root 12531 Jul 27 16:14 virtual
-rw-r--r--.  1 root root 12288 Jul 27 16:14 virtual.db
-rw-r--r--.  1 root root 12494 Jul 27 15:41 virtual.orig

To correct the issue, I changed the permissions back to root:
# chown -Rv root:root /etc/postfix/main.cf

However, postfix still failed to start:
# /etc/init.d/postfix start

Starting postfix:                                          [  FAILED ]

I then checked maillog to see if any additional insight could be gleaned:
# tail -5 /var/log/maillog
Jul 27 16:51:06 vps31 postfix[1323]: fatal: open /etc/postfix/main.cf: Permission denied

After running the following command, postfix was then able to restart. From what I've read online, this seems to be related to SELinux access control (see links at the bottom).
# restorecon -v /etc/postfix/main.cf
restorecon reset /etc/postfix/main.cf context unconfined_u:object_r:user_home_t:s0->unconfined_u:object_r:postfix_etc_t:s0

For good measure:
# restorecon -v /etc/postfix

Verification:
# /etc/init.d/postfix start

Starting postfix:                                          [  OK ]

Courtesy of:
http://nixcraft.com/centos-rhel-fedora/19497-postfix-fails-start.html
http://serverfault.com/questions/503642/postfix-main-cf-permission-denied

No comments:

Post a Comment