postfix fails to start during macOS with fatal: message about port 25 in use

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

postfix fails to start during macOS with fatal: message about port 25 in use

Gerben Wierda
postfix is started during boot on my macOS system. This fails with:

Jan 10 18:00:08 mail postfix/master[488]: fatal: bind 0.0.0.0 port 25: Address already in use
Jan 10 18:00:10 mail /postfix-script[511]: fatal: mail system startup failed

but when I shortly thereafter launch it it just starts fine.

It seems something in the postfix/macOS combo makes this happen. Probably a weirdness in macOS if postfix starts when the system is still in some startup state (there have been more issues like this with macOS), so what I could use is a way to make postfix a bit more persistent in trying to start on a fatal.

G
Reply | Threaded
Open this post in threaded view
|

Re: postfix fails to start during macOS with fatal: message about port 25 in use

Bill Cole-3
On 10 Jan 2020, at 12:28, Gerben Wierda wrote:

> postfix is started during boot on my macOS system. This fails with:
>
> Jan 10 18:00:08 mail postfix/master[488]: fatal: bind 0.0.0.0 port 25:
> Address already in use
> Jan 10 18:00:10 mail /postfix-script[511]: fatal: mail system startup
> failed
>
> but when I shortly thereafter launch it it just starts fine.

Apple includes its own customized version of Postfix in macOS, with a
launchd config which runs 'master -e 60' at boot and whenever
/var/spool/postfix/maildrop/ changes (i.e. mail is sent using
/usr/sbin/sendmail.) Unfortunately, the default config
(/etc/postfix/master.cf) enables postscreen, smtpd, and submission,
which means ports 25 and 587 have listeners bound for 60 seconds at
boot.

Assuming you're running Postfix in a different prefix (ew.g. MacPort's
/opt/local/) It should be safe to modify /etc/postfix/master.cf to
disable postscreen, smtpd, and submission OR modify
/System/Library/LaunchDaemons/com.apple.postfix.master.plist to reduce
the runtime to something just long enough to clear a single-message
queue under boot-time load, e.g. 2-5 seconds.

It is also possible in older MacOS X versions (i.e. those for which
Apple no longer releases updates) to disable their Postfix entirely and
replace it with your custom one by symlinking /etc/postfix/,
/var/spool/postfix/ and /usr/sbin/sendmail to your custom build's
equivalents.

--
Bill Cole
[hidden email] or [hidden email]
(AKA @grumpybozo and many *@billmail.scconsult.com addresses)
Not For Hire (currently)
Reply | Threaded
Open this post in threaded view
|

Re: postfix fails to start during macOS with fatal: message about port 25 in use

Wietse Venema
In reply to this post by Gerben Wierda
Gerben Wierda:
> postfix is started during boot on my macOS system. This fails with:
>
> Jan 10 18:00:08 mail postfix/master[488]: fatal: bind 0.0.0.0 port 25: Address already in use
> Jan 10 18:00:10 mail /postfix-script[511]: fatal: mail system startup failed

On most UNIX(like) system this means that some process hold
a file descriptor that is bound to that address and port.

For example, an smtpd process still runs after something has killed
the Postfix master daemon.

But that seems unlikely during system boot.

> but when I shortly thereafter launch it it just starts fine.

> Probably a weirdness in macOS if postfix starts when the system
> is still in some startup state (there have been more issues like
> this with macOS), so what I could use is a way to make postfix a
> bit more persistent in trying to start on a fatal.

You could duplicate the "postfix stop" retry loop.

        Wietse

        $INFO stopping the Postfix mail system
        kill `sed 1q pid/master.pid`
        for i in 5 4 3 2 1
        do
            $daemon_directory/master -t && exit 0
            $INFO waiting for the Postfix mail system to terminate
            sleep 1
        done
        $WARN stopping the Postfix mail system with force
        pid=`awk '{ print $1; exit 0 } END { exit 1 }' pid/master.pid` &&
                kill -9 -$pid
Reply | Threaded
Open this post in threaded view
|

Re: postfix fails to start during macOS with fatal: message about port 25 in use

Gerben Wierda
In reply to this post by Bill Cole-3


> On 10 Jan 2020, at 19:01, Bill Cole <[hidden email]> wrote:
>
> On 10 Jan 2020, at 12:28, Gerben Wierda wrote:
>
>> postfix is started during boot on my macOS system. This fails with:
>>
>> Jan 10 18:00:08 mail postfix/master[488]: fatal: bind 0.0.0.0 port 25: Address already in use
>> Jan 10 18:00:10 mail /postfix-script[511]: fatal: mail system startup failed
>>
>> but when I shortly thereafter launch it it just starts fine.
>
> Apple includes its own customized version of Postfix in macOS, with a launchd config which runs 'master -e 60' at boot and whenever /var/spool/postfix/maildrop/ changes (i.e. mail is sent using /usr/sbin/sendmail.) Unfortunately, the default config (/etc/postfix/master.cf) enables postscreen, smtpd, and submission, which means ports 25 and 587 have listeners bound for 60 seconds at boot.
>
> Assuming you're running Postfix in a different prefix (ew.g. MacPort's /opt/local/) It should be safe to modify /etc/postfix/master.cf to disable postscreen, smtpd, and submission OR modify /System/Library/LaunchDaemons/com.apple.postfix.master.plist to reduce the runtime to something just long enough to clear a single-message queue under boot-time load, e.g. 2-5 seconds.

Thank you! That is it of course. I’ve edited /etc/postfix/master.cf.

G
Reply | Threaded
Open this post in threaded view
|

Re: postfix fails to start during macOS with fatal: message about port 25 in use

Gerben Wierda
In reply to this post by Bill Cole-3


> On 10 Jan 2020, at 19:01, Bill Cole <[hidden email]> wrote:
>
> On 10 Jan 2020, at 12:28, Gerben Wierda wrote:
>
>> postfix is started during boot on my macOS system. This fails with:
>>
>> Jan 10 18:00:08 mail postfix/master[488]: fatal: bind 0.0.0.0 port 25: Address already in use
>> Jan 10 18:00:10 mail /postfix-script[511]: fatal: mail system startup failed
>>
>> but when I shortly thereafter launch it it just starts fine.
>
> Apple includes its own customized version of Postfix in macOS, with a launchd config which runs 'master -e 60' at boot and whenever /var/spool/postfix/maildrop/ changes (i.e. mail is sent using /usr/sbin/sendmail.) Unfortunately, the default config (/etc/postfix/master.cf) enables postscreen, smtpd, and submission, which means ports 25 and 587 have listeners bound for 60 seconds at boot.
>
> Assuming you're running Postfix in a different prefix (ew.g. MacPort's /opt/local/) It should be safe to modify /etc/postfix/master.cf to disable postscreen, smtpd, and submission

This is easy enough.

> OR modify /System/Library/LaunchDaemons/com.apple.postfix.master.plist to reduce the runtime to something just long enough to clear a single-message queue under boot-time load, e.g. 2-5 seconds.

One little addition: this is not possible in recent macOS versions as it requires turning System Integrity Protection (SIP) off.

> It is also possible in older MacOS X versions (i.e. those for which Apple no longer releases updates) to disable their Postfix entirely and replace it with your custom one by symlinking /etc/postfix/, /var/spool/postfix/ and /usr/sbin/sendmail to your custom build's equivalents.
>
> --
> Bill Cole
> [hidden email] or [hidden email]
> (AKA @grumpybozo and many *@billmail.scconsult.com addresses)
> Not For Hire (currently)