The task at hand was to set up a second instance of Postfix, the original will handle normal mail traffic for domains, both sending and receiving, while the other would only be used solely for sending and logs into a different file, so that it can be handled separately.
Postfix was given, and since I like to install everything from a distribution package to easy maintaining the system, I could not install… Errrrr, yes, one always learns, I could have installed exim for example as they (mail servers) don’t conflict like some other packages providing the same features… Well, never mind.
So Postfix was installed, the task was to create a second instance. I thought that copying /etc/postfix will not be enough, I have to make Postfix somehow to read configuration from the new directory and it would be nice to start the instance automatically at boot time, so I had to copy the /etc/init.d/postfix too. But this will not do yet as Postfix is looking for it’s main.cf configuration in the default location (/etc/postfix on Ubuntu), I needed to find a solution, something elegant, to make it read the files I want. And this is the MAIL_CONFIG environment variable which I set in the startup script to /etc/postfix2. Happiness. And then it has a chroot folder structure under /var/spool/postfix, this had to be copied as well. And there is a /var/lib/postfix, although this may only be used when it uses SSL, but Postfix may use it when acting as a client and connects via SSL/TLS, so it!s better to be copied too. Lastly carving the configuration files to your liking. main.cf had to be altered as follows:
queue_directory=/var/spool/postfix2 data_directory=/var/lib/postfix2 syslog_facility=local7 syslog_name=postfix2 inet_interfaces = loopback-only
syslog_facility obviously can be anything that is supported by the system, but only local0-7 are the only ones not used by normal applications, so only what I want goes into that.
smtp inet n - - - - smtpd
to be replaced with:
125 inet n - - - - smtpd
given that we want the second instance of Postfix to listen on port 125 and bound to the loopback adapter (inet_interfaces in main.cf). I removed all kinds of spam and antivirus filtering from both main.cf and master.cf as there was no need for them in this setup. Your mileage may vary, if you need them you’ll need to take care to allocate separate ports in master.cf for them.
I hit some trouble after copying the startup script under init.d, because copying /var/spool/postfix I copied the PID file of the running instance, along with other files, so the script thought the instance is already running and gave you an OK instead of telling you that it!s already running, when it was not, and I was wondering what may be wrong and there was not a trace of the second instance in the logs… Once I overcome this came logging. This looser rsyslogd does not load its configuration completely on a HUP signal, even though I made a file under /etc/rsyslog.d with the following content it has not created the files and I was at a loss what I have done wrong:
$AddUnixListenSocket /var/spool/postfix2/dev/log local7.info -/var/log/mail2.info local7.warn -/var/log/mail2.warn local7.err /var/log/mail2.err
Obviously nothing, reload/HUP was not enough, I had to restart it. I think that’s it, if it does not work for you leave a comment and I shall get back to you 🙂