There's probably an answer to this already, but I just can't figure out how to search for it correctly.


We have a failover situation for two nodes, using keepalived, passing a floating IP between them. The main purpose of the nodes is to run haproxy. Each node also runs a local postfix that is solely used to deliver email from keepalived or from haproxy, to an actual operator account, relaying through SendGrid to an external mail domain, as it happens. No mail is accepted from any other machine.

All this is working well. Too well; my mailbox is flooded. I would like to suppress mail from the non-active node, and when failover happens, make postfix suddenly start delivering mail.

So here's the idea.

  • normal mode: postfix accepts mail on port 25 and relays through Sendgrid.
  • silent mode: postfix still accepts mail on port 25, but it drops it on the floor, not relaying it anywhere, not returning failure to the client, not sending a bounce. (Yes, this is terrible behavior for an MTA normally. MTAs shouldn't lie about accepting mail. But this is a restricted situation.)
  • How to tell whether I should be in normal or silent mode: a simple script, probably something like ip addr | grep -q $FLOAT_IP.

So ... I guess the basic question is how does "silent mode" happen. Is it a totally separate postfix config, and I have to restart postfix with the right config?

Would it be better to set up an After-Queue Content Filter?

Is there some other idea?

  • You can also use the discard transport, but that needs changing a file or running a command. – sebix Aug 22 '17 at 20:26
  • I don't mind running a command, especially if that would be quicker to execute than reloading postfix. How do I do that? – Ross Presser Aug 23 '17 at 1:29
  • Would it be something like this? although that does say "restart postfix"... – Ross Presser Aug 23 '17 at 1:33

OK, after the hint from @sebix to "use the discard transport", I have something that seems to be working:

Set up a transport map:

# echo >>/etc/postfix/main.cf 'transport_maps = hash:/etc/postfix/transport'

Set up the default transport map as empty; also set up a file for discard transport

# cat </dev/null >/etc/postfix/transport
# cat </dev/null >/etc/postfix/transport.normal
# echo >/etc/postfix/transport.discard '* discard:'

A bash script /usr/local/bin/keepalived_togglemail.sh that keepalived can invoke to switch postfix on or off:



case $STATE in
        "MASTER") cp /etc/postfix/transport.normal /etc/postfix/transport
                  postmap /etc/postfix/transport
                  /etc/init.d/postfix reload
                  exit 0
        "BACKUP") cp /etc/postfix/transport.discard /etc/postfix/transport
                  postmap /etc/postfix/transport
                  /etc/init.d/postfix reload
                  exit 0
        "FAULT")  echo FAULT
                  exit 0
        *)        echo "unknown state"
                  exit 1

And a line in /etc/keepalived/keepalived.conf to make it happen. (excerpt):

vrrp_instance VRRP1 {
     state BACKUP
     interface ens32
     notify /usr/local/bin/keepalived_togglemail.sh
  • 2
    You can simply issue postconf transport_maps=hash:/etc/postfix/transport, it does also reload. – sebix Aug 23 '17 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.