postfix/smtp: fatal: unknown service: smtp/tcp – but /var/spool/postfix/etc/services exists
I stumbled over the same issue. In my case this was due to my setup using zfs with /var/spool mounted with flag noexec set. Solution was to clear that flag on mounted file system.
See https://github.com/zfsonlinux/zfs/issues/6803#issuecomment-378271799 for more.
In conclusion Postfix apparently relies on a dynamically linked library also put in chroot jail in /var/spool/postfix for reading its services database. In case of running this folder or any of its parent folders on a separate filesystem which is mounted with option noexec
set this library won't get loaded for containing code to be executed. From Postfix' point of view this isn't considered in particular. Instead it sees and logs a more generic issue with reading the services database.
This same problem I developed after trying to install postfix on Fedora 28 with chroot enabled for smtp through the /etc/postfix/master.cf file.
after reading one of the many readme files, specifically
/postfix-3.3.1/README_FILES/BASIC_CONFIGURATION_README
I was able to realize there was a script i needed to run in order to properly run postfix chrooted.
Note that a chrooted daemon resolves all filenames relative to the Postfix
queue directory (/var/spool/postfix). For successful use of a chroot jail, most
UNIX systems require you to bring in some files or device nodes. The examples/
chroot-setup directory in the source code distribution has a collection of
scripts that help you set up Postfix chroot environments on different operating
systems.
the problem that i figured out was the culprit was that I needed to run the
LINUX2
script file located in
/postfix-3.3.1/examples/chroot-setup/
like so:
[[email protected] ~]$ cd postfix-3.3.1/examples/chroot-setup/
[[email protected] chroot-setup]$ ls
AIX42 BSDI2 BSDI3 FreeBSD2 FREEBSD3 HPUX10 HPUX9 IRIX5 IRIX6 LINUX2 NETBSD1 NEXTSTEP3 OPENSTEP4 OSF1 Solaris10 Solaris2 Solaris8
[[email protected] chroot-setup]$ chmod +x LINUX2
[[email protected] chroot-setup]$ ./LINUX2
you must run this script as root or sudo as it copies files into the /var/spool/postfix directory from etc, lib, lib64, and usr, and they must be owned by root. It was only after executing the script, it ran fine, and reloaded postfix, but i still had errors, so i debugged the very ancient script and found there to be a missing slash in the cond_copy() function.
the correct cond_copy() function should look like
cond_copy() {
# find files as per pattern in $1
# if any, copy to directory $2
dir=`dirname "$1"`
pat=`basename "$1"`
lr=`find "$dir/" -maxdepth 1 -name "$pat"`
if test ! -d "$2" ; then exit 1 ; fi
if test "x$lr" != "x" ; then $CP $1 "$2" ; fi
}
so if this is your error and you are running a chroot jailed postfix, first find the script that copies the correct files into /var/spool/postfix/ correct the error in the copy_cond() function and execute as root, or at least thats how i did it.
a little addendum:
for those that are running SELinux, it probably wouldnt be such a bad idea to enter /var/spool/postfix/ and run restorecon -Rv if you are concerned it might mess something up you can just run it on the files you moved over
[[email protected] postfix]# restorecon -Rv etc/ lib/ lib64/ usr/