Wietse Venema:
> I think that Docker fundamentally wants one service instance per
> container. On Postfix service instance translates into one queue,
> for example submission+smtp sharing one queue, similar to http+https
> sharing one website. Let's not fight the Docker approach, and leave
> orchestration to a different layer in the stack.
...
> As for forgrounding, this must happen only after the 'postfix
> check' sanity checks and repairs complete sucessfully. Running a
> 'bare' master daemon would violate design assumptions. So this
> will require a new 'postfix' subcommand that starts exactly one
> instance in the foreground.

Attached is a proof-of-concept implementation.
Manpage fragment:

POSTFIX(1)                                                          POSTFIX(1)

NAME
       postfix - Postfix control program
        ...
DESCRIPTION
        ...
       The following commands are implemented:

       check  Warn about bad directory/file ownership or permissions, and cre-
              ate missing directories.

       start  Start  the Postfix mail system. This also runs the configuration
              check described above.

       start-fg
              Like start, but keep the master  daemon  running  in  the  fore-
              ground.  This  requires  that multi-instance support is disabled
              (i.e. the multi_instance_directories parameter value is  empty).
        ...

I suppose one approach is to make a Postfix container disposable,
i.e. a container is never updated with a new Postfix version, but
it is replaced with a newer one, and it imports its queue and data
directories from the host. These directories must of course not be
imported into multiple containers. I don't know how to prevent that.

Also, a Postfix container would import the logging sockets from the
host (www.projectatomic.io/blog/2016/10/playing-with-docker-logging)
and would set 'syslog_name = $myhostname/postfix' in the container's
main.cf file to make logging from different containers distinct.
Of course the logging sockets may be imported into as many containers
as needed.

If one wants multiple Postfix instances in a single container, then
that will require a 'minder' program that runs in the foreground and
that plays nice with higher-level orchestration systems. I won't
sabotage that approach.

        Wietse

diff --exclude=man --exclude=html --exclude=README_FILES --exclude=INSTALL 
--exclude=.indent.pro --exclude=Makefile.in -r -ur 
/var/tmp/postfix-3.3-20171218/conf/postfix-script ./conf/postfix-script
--- /var/tmp/postfix-3.3-20171218/conf/postfix-script   2017-09-12 
14:16:54.000000000 -0400
+++ ./conf/postfix-script       2017-12-19 09:37:18.000000000 -0500
@@ -117,7 +117,7 @@
        echo "Stop postfix"
        ;;
 
-start)
+start|start-fg)
 
        $daemon_directory/master -t 2>/dev/null || {
                $FATAL the Postfix mail system is already running
@@ -135,11 +135,28 @@
                $daemon_directory/postfix-script check-warn
        fi
        $INFO starting the Postfix mail system
-       # NOTE: wait in foreground process to get the initialization status.
-       $daemon_directory/master -w || {
-           $FATAL "mail system startup failed"
-           exit 1
-       }
+       case $1 in
+       start)
+           # NOTE: wait in foreground process to get the initialization status.
+           $daemon_directory/master -w || {
+               $FATAL "mail system startup failed"
+               exit 1
+           }
+           ;;
+       start-fg)
+           # Foreground start-up is incompatible with multi-instance mode.
+           # We can't use "exec $daemon_directory/master" here: that would
+           # break process group management, and "postfix stop" would kill
+           # too many processes.
+           case $instances in
+           "") $daemon_directory/master
+               ;;
+            *) $FATAL "start-fg does not support multi_instance_directories"
+               exit 1
+               ;;
+           esac
+           ;;
+       esac
        ;;
 
 drain)
diff --exclude=man --exclude=html --exclude=README_FILES --exclude=INSTALL 
--exclude=.indent.pro --exclude=Makefile.in -r -ur 
/var/tmp/postfix-3.3-20171218/src/postfix/postfix.c ./src/postfix/postfix.c
--- /var/tmp/postfix-3.3-20171218/src/postfix/postfix.c 2016-09-17 
10:50:56.000000000 -0400
+++ ./src/postfix/postfix.c     2017-12-19 09:19:59.000000000 -0500
@@ -31,6 +31,11 @@
 /* .IP \fBstart\fR
 /*     Start the Postfix mail system. This also runs the configuration
 /*     check described above.
+/* .IP \fBstart-fg\fR
+/*     Like \fBstart\fR, but keep the master daemon running in the
+/*     foreground. This requires that multi-instance support is
+/*     disabled (i.e. the multi_instance_directories parameter
+/*     value is empty).
 /* .IP \fBstop\fR
 /*     Stop the Postfix mail system in an orderly fashion. If
 /*     possible, running processes are allowed to terminate at

Reply via email to