Suppose that you need second full functional Postfix instance on the same machine. You can edit ‘master.cf‘ file of course but this solution does not provide necessary separation level. This tutorial describes how to start second Postfix instance with separate ‘/var/spool/postfix‘ directory (queues, sockets, pids etc.).
In first step you need to create separate working directory for another server instance. Let’s copy:
– /var/spool/postfix directory to /var/spool/postfix2,
– /etc/postfix directory to /etc/postfix2.
Next create a copy of /usr/lib/systemd/system/postfix.service (with new name ‘postfix2.service’) and change following lines in ‘[Service]‘ section.
[Service] Type=forking PIDFile=/var/spool/postfix2/pid/master.pid EnvironmentFile=-/etc/sysconfig/network ExecStartPre=-/usr/libexec/postfix/aliasesdb ExecStartPre=-/usr/libexec/postfix/chroot-update ExecStart=/usr/sbin/postfix -c /etc/postfix2 start ExecReload=/usr/sbin/postfix -c /etc/postfix2 reload ExecStop=/usr/sbin/postfix -c /etc/postfix2 stop
Now we have defined a new service (postfix2.service) with forced new configuration directory (-c /etc/postfix2). Let’s try to start it!
systemctl restart postfix2
This steps will succeed unless SELinux is disabled. When it’s enabled (enforcing=1) you need to do additional steps.
1. Create permanent fcontexts for new Postfix directories.
semanage fcontext -a -t etc_t "/var/spool/postfix2/etc(/.*)?" semanage fcontext -a -t lib_t "/var/spool/postfix2/lib(/.*)?" semanage fcontext -a -t lib_t "/var/spool/postfix2/usr(/.*)?" semanage fcontext -a -t postfix_var_run_t "/var/spool/postfix2/pid/.*" semanage fcontext -a -t lib_t "/var/spool/postfix2/lib64(/.*)?" semanage fcontext -a -t postfix_spool_t "/var/spool/postfix2/defer(/.*)?" semanage fcontext -a -t postfix_spool_t "/var/spool/postfix2/flush(/.*)?" semanage fcontext -a -t postfix_public_t "/var/spool/postfix2/public(/.*)?" semanage fcontext -a -t postfix_spool_bounce_t "/var/spool/postfix2/bounce(/.*)?" semanage fcontext -a -t ld_so_t "/var/spool/postfix2/lib/ld.*.so.*" semanage fcontext -a -t spamass_milter_data_t "/var/spool/postfix2/spamass(/.*)?" semanage fcontext -a -t postfix_private_t "/var/spool/postfix2/private(/.*)?" semanage fcontext -a -t postfix_spool_t "/var/spool/postfix2/deferred(/.*)?" semanage fcontext -a -t postfix_spool_t "/var/spool/postfix2/maildrop(/.*)?" semanage fcontext -a -t postgrey_spool_t "/var/spool/postfix2/postgrey(/.*)?"
2. Restore contexts on all new Postfix directories.
restorecon -R /var/spool/postfix2/
3. Let’s try start new Postfix again.
systemctl restart postfix2
Verify that Postfix is running and listening on specified IP/port.