implementing offline/maintenance mode, with SMTP reply?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

implementing offline/maintenance mode, with SMTP reply?

PGNet Dev
my usual postfix front-end workflow is

        postscreen
                if 'fail', reject
                if 'pass', then
                        internal smtp
                        etc

i'd like to implement a 'maintenance/offline mode' -- WITH smtp response -- effectively adding

        postscreen
                if 'fail', reject
                if 'pass', then
+ if 'maintenance mode' = ON, then
+ reply SMTP 4XX, msg = (user specified message, e.g. down 4 maintenance, try again in X hours)
+ else if 'maintenance mode' = OFF, then
                                internal smtp
                                etc

there are many paths to that particular mountain.

is there an already built-in maintenance-mode, or somesuch, in postfix?
it'd be most convenient; if it's in docs, i've missed it.

i thought about monkeying with stress-adaptive behavior, but that seems like a bad rabbit-hole for this ...

Reply | Threaded
Open this post in threaded view
|

Re: implementing offline/maintenance mode, with SMTP reply?

Viktor Dukhovni
On Fri, Oct 16, 2020 at 10:51:52AM -0700, PGNet Dev wrote:

> my usual postfix front-end workflow is
>
> postscreen
> if 'fail', reject
> if 'pass', then
> internal smtp
> etc
>
> i'd like to implement a 'maintenance/offline mode' -- WITH smtp response -- effectively adding
>
> postscreen
> if 'fail', reject
> if 'pass', then
> + if 'maintenance mode' = ON, then
> + reply SMTP 4XX, msg = (user specified message, e.g. down 4 maintenance, try again in X hours)
> + else if 'maintenance mode' = OFF, then
> internal smtp
> etc

That can just be handled via smtpd(8) (your 'internal smtp'):

> is there an already built-in maintenance-mode, or somesuch, in postfix?
> it'd be most convenient; if it's in docs, i've missed it.

If the custom 4XX response is not a hard requirement, the simplest
solution is:

    main.cf:
        # To defer all email, change to: lunchtime = y
        lunchtime =
        smtpd_recipient_restrictions =
            ${lunchtime?defer_if_permit}
            ...

Which will still reject invalid recipients, ... and only defer what
you'd otherwise accept.

See:

    http://www.postfix.org/postconf.5.html#defer_if_permit
    http://www.postfix.org/postconf.5.html

If you really must have a custom 4XX response, then you can use:

    main.cf:
        # To defer all email, change to: lunchtime = y
        lunchtime =
        smtpd_client_restrictions =
            ${lunchtime?check_client_access static:{450 4.3.2 Scheduled downtime, come back later}}
            ...

Note that sites that do sender-address-verification (does anyone still
do that?) may then tempfail your outbound mail, during the downtime and
likely for some time after after you restore service.

--
    Viktor.
Reply | Threaded
Open this post in threaded view
|

Re: implementing offline/maintenance mode, with SMTP reply?

Bastian Blank-3
In reply to this post by PGNet Dev
On Fri, Oct 16, 2020 at 10:51:52AM -0700, PGNet Dev wrote:
> is there an already built-in maintenance-mode, or somesuch, in postfix?
> it'd be most convenient; if it's in docs, i've missed it.

Just shut down Postfix, that's equivalent to returning 4xx.

Bastian

--
Intuition, however illogical, is recognized as a command prerogative.
                -- Kirk, "Obsession", stardate 3620.7
Reply | Threaded
Open this post in threaded view
|

Re: implementing offline/maintenance mode, with SMTP reply?

Wietse Venema
In reply to this post by PGNet Dev
PGNet Dev:

> my usual postfix front-end workflow is
>
> postscreen
> if 'fail', reject
> if 'pass', then
> internal smtp
> etc
>
> i'd like to implement a 'maintenance/offline mode' -- WITH smtp response -- effectively adding
>
> postscreen
> if 'fail', reject
> if 'pass', then
> + if 'maintenance mode' = ON, then
> + reply SMTP 4XX, msg = (user specified message, e.g. down 4 maintenance, try again in X hours)
> + else if 'maintenance mode' = OFF, then
> internal smtp
> etc
>
> there are many paths to that particular mountain.
>
> is there an already built-in maintenance-mode, or somesuch, in postfix?
> it'd be most convenient; if it's in docs, i've missed it.

Just let it pass to real smtpd, then reject there.

    smtpd_client_restrictions =
        check_client_access static:{421 Service down for maintenance}
    # Use if you don't care what mail you aren't receiving.
    smtpd_relay_reject = no

With 421, Postfix will hang up.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: implementing offline/maintenance mode, with SMTP reply?

PGNet Dev
In reply to this post by Viktor Dukhovni
On 10/16/20 11:54 AM, Viktor Dukhovni wrote:

> If the custom 4XX response is not a hard requirement, the simplest
> solution is:
>
>      main.cf:
>          # To defer all email, change to: lunchtime = y
>          lunchtime =
>          smtpd_recipient_restrictions =
>              ${lunchtime?defer_if_permit}
>              ...
> Which will still reject invalid recipients, ... and only defer what

> you'd otherwise accept.


hadn't thought to defer.

this should work nicely. thx.

tho, s/lunchtime/cocktails/ might be needed.

> If you really must have a custom 4XX response, then you can use:
>
>      main.cf:
>          # To defer all email, change to: lunchtime = y
>          lunchtime =
>          smtpd_client_restrictions =
>              ${lunchtime?check_client_access static:{450 4.3.2 Scheduled downtime, come back later}}
>              ...
>
> Note that sites that do sender-address-verification (does anyone still
> do that?) may then tempfail your outbound mail, during the downtime and
> likely for some time after after you restore service.

noted.

unfortunately plenty of financial institutions do.

one fail-to-deliver and they toggle user prefs back to snail-mail -- AND send a "we were unable to deliver to your email" _letter_.
the avalanche of dead-tree propectuses roll nicely into firelogs ...