Opened 4 years ago

Last modified 4 years ago

#60923 assigned enhancement

mail-server: possible improvements to wrapper script

Reported by: ryandesign (Ryan Carsten Schmidt) Owned by: essandess (Steve Smith)
Priority: Normal Milestone:
Component: ports Version: 2.6.3
Keywords: Cc:
Port: mail-server

Description

With default variants, mail-server installs a mail-server.wrapper file containing in part:

#
# Start
#
Start()
{
	port load clamav-server
	port load apache-solr8
	port load redis
	port load dcc
	port load postfix
	port load dovecot
	port load rspamd
}

#
# Stop
#
Stop()
{
	port unload apache-solr8
	port unload dcc
	port unload postfix
	port unload dovecot
	port unload rspamd
}

#
# Restart
#
Restart()
{
	port reload apache-solr8
	port reload redis
	port reload dcc
	port unload postfix ; \
	sleep 1 ; \
	port load postfix
	port unload dovecot ; \
	sleep 1 ; \
	port load dovecot
	port reload rspamd
}

I have so many questions.

Why do you call port load / unload / reload for each port individually? Why not all at once? If you are concerned that one of the loads / unloads / reloads might fail and you want subsequent ones to be attempted anyway, use the -p flag. (port -p load clamav-server apache-solr8 redis dcc postfix dovecot rspamd)

Why does Start() load redis but Stop() doesn't unload it?

Why does Start() load clamav-server but Stop() doesn't unload it and Restart() doesn't reload it?

Why does Restart() manually reload postfix and dovecot by unloading, then waiting a second, then loading? That is exactly what reload already does so why not use that?

Change History (2)

comment:1 Changed 4 years ago by essandess (Steve Smith)

Why do you call port load / unload / reload for each port individually? Why not all at once? If you are concerned that one of the loads / unloads / reloads might fail and you want subsequent ones to be attempted anyway, use the -p flag. (port -p load clamav-server apache-solr8 redis dcc postfix dovecot rspamd)

Good idea. Would you please modify https://github.com/macports/macports-ports/pull/7893 to do this?

Why does Start() load redis but Stop() doesn't unload it?

redis is a database required by rspamd, so must it be loaded when the mail server starts. But other stuff might also depend on redis, so you don't want to stop it just because the mail server stops. It's a conservative choice intended not to disrupt and annoy redis users.

Why does Start() load clamav-server but Stop() doesn't unload it and Restart() doesn't reload it?

The mail server requires clamav-server to scan incoming mail, so it must be started. But again, clamav-server users, me included, don't want clamd to stop running just because the mail server is stopped.

Why does Restart() manually reload postfix and dovecot by unloading, then waiting a second, then loading? That is exactly what reload already does so why not use that?

This is a robustness hack I found that is necessary on my own systems to make sure that postfix's port 25 is available when the port is reloaded. If the port system already is waiting a second, then perhaps it needs additional time for postfix. macOS launchd timing is frankly a PITA, and I don't known of a general fix beyond just waiting a little longer, or explicitly checking to make sure that port 25 isn't open before reloading. Same comment for dovecot ports.

Last edited 4 years ago by essandess (Steve Smith) (previous) (diff)

comment:2 in reply to:  1 Changed 4 years ago by ryandesign (Ryan Carsten Schmidt)

Replying to essandess:

Why do you call port load / unload / reload for each port individually? Why not all at once? If you are concerned that one of the loads / unloads / reloads might fail and you want subsequent ones to be attempted anyway, use the -p flag. (port -p load clamav-server apache-solr8 redis dcc postfix dovecot rspamd)

Good idea. Would you please modify https://github.com/macports/macports-ports/pull/7893 to do this?

With -p or no?

I don't know how these wrapper scripts normally behave if one command fails: do they proceed to run the subsequent commands or stop on the first failed command?

Or are we not concerned about the case where port load and port unload might fail?

Why does Restart() manually reload postfix and dovecot by unloading, then waiting a second, then loading? That is exactly what reload already does so why not use that?

This is a robustness hack I found that is necessary on my own systems to make sure that postfix's port 25 is available when the port is reloaded. If the port system already is waiting a second,

It is: https://github.com/macports/macports-base/blob/master/src/port1.0/portreload.tcl#L86-L89

then perhaps it needs additional time for postfix. macOS launchd timing is frankly a PITA, and I don't known of a general fix beyond just waiting a little longer, or explicitly checking to make sure that port 25 isn't open before reloading. Same comment for dovecot ports.

According to comment:ticket:36054:8 we added the 1 second delay for redis because it didn't release its tcp port in time. According to comment:ticket:36054:9 this is considered a bug in redis.I don't know if it was ever fixed. Should we also consider this a bug in postfix and dovecot and ask them to fix it? Or can we make port unload and port reload more robust so that they wait for the monitored program to actually finish what it's doing before returning? I had assumed launchctl was already guaranteeing that but I guess not.

Note: See TracTickets for help on using tickets.