[opensuse-factory] Wanted: How to use systemd unit conf files for sendmail
Hi, for bug bnc#710279 I'm also have look how to switch over to systemd unit configuration files for starting sendmail MTA and also sendmail client mail queue handler. Currently I have for the MTA process an smtp.socket file with [Unit] Description=SMTP Socket DefaultDependencies=no [Socket] ListenStream=25 FreeBind=true Accept=false Service=sendmail.service and the service unit sendmail.service: [Unit] Description=Sendmail Mail Transport Agent After=nss-lookup.target network.target remote-fs.target syslog.target rtc-set.target Wants=amavis.service cyrus.service ldap.service nscd.service ypbind.service Conflicts=postfix.service exim.service [Service] Type=forking Environment=SENDMAIL_ARGS=-L sendmail -Am -bd -q30m -om EnvironmentFile=-/etc/sysconfig/mail EnvironmentFile=-/etc/sysconfig/sendmail PIDFile=/var/run/sendmail.pid ExecStartPre=-/usr/bin/make -C /etc/mail ExecStart=/usr/sbin/sendmail $SENDMAIL_ARGS [Install] WantedBy=mail-transfer-agent.target Also=sendmail-client.service ... now the question is: will this work, that is start sendmail MTA on demand if `systemctl enable smtp.socket' was executed? Or is it better to switch in sendmail.service to multi-user.target for WantedBy? For the sendmail client mail queue handler I've path unit sendmail-client.path with: [Unit] Description=Sendmail Client Mail Queue Watcher [Path] DirectoryNotEmpty=/var/spool/clientmqueue/ [Install] WantedBy=multi-user.target to be able to start the service unit sendmail-client.service: [Unit] Description=Sendmail Mail Transport Client After=smtp-local.socket [Service] Type=forking Environment=SENDMAIL_CLIENT_ARGS=-L sendmail-client -Ac -qp30m EnvironmentFile=-/etc/sysconfig/mail EnvironmentFile=-/etc/sysconfig/sendmail PIDFile=/var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/touch /var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/chown mail:mail /var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/chmod 0600 /var/spool/clientmqueue/sm-client.pid ExecStartPre=-/usr/bin/make -C /etc/mail ExecStart=/usr/sbin/sendmail $SENDMAIL_CLIENT_ARGS [Install] WantedBy=mail-transfer-agent.target Does this work? Together with a unit smtp-local.socket it should be possible to start the sendmail MTA if not already up: [Unit] Description=Local SMTP Socket DefaultDependencies=no [Socket] ListenStream=25 BindToDevice=lo Accept=false Service=sendmail.service IMHO this will only used if no process is listen on localhost port 25 or is this wrong? The manual pages of systemd do not show what happens is a port is already busy due an other way of enabling the MTA. Currently I've not found a way to port PortOpts="" for cfg in /etc/sendmail.cf /etc/mail/sendmail.cf do test -s $cfg || continue PortOpts=$(sed -rn '/^O[[:blank:]]+DaemonPortOptions=.*Name=MTA.*$/I { s/[[:blank:]]+//g s/^O[^=]+=(.*)/\1/p }' $cfg) break done unset cfg if test "$SMTPD_LISTEN_REMOTE" != "yes" ; then PortOpts="${PortOpts:+${PortOpts},}Addr=127.0.0.1" SENDMAIL_ARGS="-O DaemonPortOptions=${PortOpts} $SENDMAIL_ARGS" fi from /etc/init.d/sendmail to the service unit sendmail.service. With this there is a control if the MTA is listen on port 25 of any remote network interface or if not. How can this be done within a systemd service unit (without using a wrapper script)? Werner -- "Having a smoking section in a restaurant is like having a peeing section in a swimming pool." -- Edward Burr -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-factory+help@opensuse.org
I've submitted a sendmail version with direct systemd support. As I use ExecStartPre=-/usr/bin/make -C /etc/mail I've added aome make(file) magic to generate an enviroment file /var/run/sendmail.port which defines the variable SENDMAIL_PORT_OPTS accordingly to /etc/sysconfig/sendmail IMHO systemd unit file scheme seems to miss a primitive scripting possiblity. On Fri, Aug 05, 2011 at 12:02:39PM +0200, Werner Fink wrote:
Hi,
for bug bnc#710279 I'm also have look how to switch over to systemd unit configuration files for starting sendmail MTA and also sendmail client mail queue handler.
Currently I have for the MTA process an smtp.socket file with
[Unit] Description=SMTP Socket DefaultDependencies=no
[Socket] ListenStream=25 FreeBind=true Accept=false Service=sendmail.service
and the service unit sendmail.service:
[Unit] Description=Sendmail Mail Transport Agent After=nss-lookup.target network.target remote-fs.target syslog.target rtc-set.target Wants=amavis.service cyrus.service ldap.service nscd.service ypbind.service Conflicts=postfix.service exim.service
[Service] Type=forking Environment=SENDMAIL_ARGS=-L sendmail -Am -bd -q30m -om EnvironmentFile=-/etc/sysconfig/mail EnvironmentFile=-/etc/sysconfig/sendmail PIDFile=/var/run/sendmail.pid ExecStartPre=-/usr/bin/make -C /etc/mail ExecStart=/usr/sbin/sendmail $SENDMAIL_ARGS
[Install] WantedBy=mail-transfer-agent.target Also=sendmail-client.service
... now the question is: will this work, that is start sendmail MTA on demand if `systemctl enable smtp.socket' was executed? Or is it better to switch in sendmail.service to multi-user.target for WantedBy?
For the sendmail client mail queue handler I've path unit sendmail-client.path with:
[Unit] Description=Sendmail Client Mail Queue Watcher
[Path] DirectoryNotEmpty=/var/spool/clientmqueue/
[Install] WantedBy=multi-user.target
to be able to start the service unit sendmail-client.service:
[Unit] Description=Sendmail Mail Transport Client After=smtp-local.socket
[Service] Type=forking Environment=SENDMAIL_CLIENT_ARGS=-L sendmail-client -Ac -qp30m EnvironmentFile=-/etc/sysconfig/mail EnvironmentFile=-/etc/sysconfig/sendmail PIDFile=/var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/touch /var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/chown mail:mail /var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/chmod 0600 /var/spool/clientmqueue/sm-client.pid ExecStartPre=-/usr/bin/make -C /etc/mail ExecStart=/usr/sbin/sendmail $SENDMAIL_CLIENT_ARGS
[Install] WantedBy=mail-transfer-agent.target
Does this work? Together with a unit smtp-local.socket it should be possible to start the sendmail MTA if not already up:
[Unit] Description=Local SMTP Socket DefaultDependencies=no
[Socket] ListenStream=25 BindToDevice=lo Accept=false Service=sendmail.service
IMHO this will only used if no process is listen on localhost port 25 or is this wrong? The manual pages of systemd do not show what happens is a port is already busy due an other way of enabling the MTA.
Currently I've not found a way to port
PortOpts="" for cfg in /etc/sendmail.cf /etc/mail/sendmail.cf do test -s $cfg || continue PortOpts=$(sed -rn '/^O[[:blank:]]+DaemonPortOptions=.*Name=MTA.*$/I { s/[[:blank:]]+//g s/^O[^=]+=(.*)/\1/p }' $cfg) break done unset cfg
if test "$SMTPD_LISTEN_REMOTE" != "yes" ; then PortOpts="${PortOpts:+${PortOpts},}Addr=127.0.0.1" SENDMAIL_ARGS="-O DaemonPortOptions=${PortOpts} $SENDMAIL_ARGS" fi
from /etc/init.d/sendmail to the service unit sendmail.service. With this there is a control if the MTA is listen on port 25 of any remote network interface or if not. How can this be done within a systemd service unit (without using a wrapper script)?
Werner -- "Having a smoking section in a restaurant is like having a peeing section in a swimming pool." -- Edward Burr -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-factory+help@opensuse.org
Le vendredi 05 août 2011 à 12:02 +0200, Dr. Werner Fink a écrit :
Hi,
Sorry for the slow answer, I'm at Desktop Summit, which slows my mail processing a little bit :)
for bug bnc#710279 I'm also have look how to switch over to systemd unit configuration files for starting sendmail MTA and also sendmail client mail queue handler.
Currently I have for the MTA process an smtp.socket file with
[Unit] Description=SMTP Socket DefaultDependencies=no
[Socket] ListenStream=25 FreeBind=true Accept=false Service=sendmail.service
and the service unit sendmail.service:
[Unit] Description=Sendmail Mail Transport Agent After=nss-lookup.target network.target remote-fs.target syslog.target rtc-set.target Wants=amavis.service cyrus.service ldap.service nscd.service ypbind.service Conflicts=postfix.service exim.service
Some fixes for After: After=nss-lookup.target network.target remote-fs.target syslog.target time-sync.target
[Service] Type=forking Environment=SENDMAIL_ARGS=-L sendmail -Am -bd -q30m -om EnvironmentFile=-/etc/sysconfig/mail EnvironmentFile=-/etc/sysconfig/sendmail PIDFile=/var/run/sendmail.pid ExecStartPre=-/usr/bin/make -C /etc/mail ExecStart=/usr/sbin/sendmail $SENDMAIL_ARGS
[Install] WantedBy=mail-transfer-agent.target Also=sendmail-client.service
... now the question is: will this work, that is start sendmail MTA on demand if `systemctl enable smtp.socket' was executed? Or is it better to switch in sendmail.service to multi-user.target for WantedBy?
It should work (but I didn't test it). I think second option might be better. But I guess it is a matter of taste.
For the sendmail client mail queue handler I've path unit sendmail-client.path with:
[Unit] Description=Sendmail Client Mail Queue Watcher
[Path] DirectoryNotEmpty=/var/spool/clientmqueue/
[Install] WantedBy=multi-user.target
to be able to start the service unit sendmail-client.service:
[Unit] Description=Sendmail Mail Transport Client After=smtp-local.socket
[Service] Type=forking Environment=SENDMAIL_CLIENT_ARGS=-L sendmail-client -Ac -qp30m EnvironmentFile=-/etc/sysconfig/mail EnvironmentFile=-/etc/sysconfig/sendmail PIDFile=/var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/touch /var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/chown mail:mail /var/spool/clientmqueue/sm-client.pid ExecStartPre=/bin/chmod 0600 /var/spool/clientmqueue/sm-client.pid ExecStartPre=-/usr/bin/make -C /etc/mail ExecStart=/usr/sbin/sendmail $SENDMAIL_CLIENT_ARGS
[Install] WantedBy=mail-transfer-agent.target
Does this work? Together with a unit smtp-local.socket it should be possible to start the sendmail MTA if not already up:
[Unit] Description=Local SMTP Socket DefaultDependencies=no
[Socket] ListenStream=25 BindToDevice=lo Accept=false Service=sendmail.service
IMHO this will only used if no process is listen on localhost port 25 or is this wrong? The manual pages of systemd do not show what happens is a port is already busy due an other way of enabling the MTA.
Indeed, the socket listening code is systemd will fail and it won't try to activate sendmail.service I would probably use mail-transfer-agent.target for Service= in smtp-local.socket, to not tie smtp-local.socket to sendmail.service.
Currently I've not found a way to port
PortOpts="" for cfg in /etc/sendmail.cf /etc/mail/sendmail.cf do test -s $cfg || continue PortOpts=$(sed -rn '/^O[[:blank:]]+DaemonPortOptions=.*Name=MTA.*$/I { s/[[:blank:]]+//g s/^O[^=]+=(.*)/\1/p }' $cfg) break done unset cfg
if test "$SMTPD_LISTEN_REMOTE" != "yes" ; then PortOpts="${PortOpts:+${PortOpts},}Addr=127.0.0.1" SENDMAIL_ARGS="-O DaemonPortOptions=${PortOpts} $SENDMAIL_ARGS" fi
from /etc/init.d/sendmail to the service unit sendmail.service. With this there is a control if the MTA is listen on port 25 of any remote network interface or if not. How can this be done within a systemd service unit (without using a wrapper script)?
You can't do that directly in a unit file.
One option is to create a systemd generator (which is what is used for crypttab and getty service),
to be installed in /lib/systemd/system-generator which would be started by systemd and would create temporary .service files in
/run/systemd/generators (which is a tmpfs) which would be used by systemd as "normal" service files.
I've tested quickly and just dropping generator script in /lib/systemd/system-generators, make sure it is executable and takes one parameter which is the path where generated
unit files should be written.
Then reboot and voilà :)
But you might want to systemd-devel mailing list to be sure I'm not on crack.
--
Frederic Crozat
On Wed, Aug 10, 2011 at 11:45:01AM +0200, Frederic Crozat wrote:
Currently I've not found a way to port
PortOpts="" for cfg in /etc/sendmail.cf /etc/mail/sendmail.cf do test -s $cfg || continue PortOpts=$(sed -rn '/^O[[:blank:]]+DaemonPortOptions=.*Name=MTA.*$/I { s/[[:blank:]]+//g s/^O[^=]+=(.*)/\1/p }' $cfg) break done unset cfg
if test "$SMTPD_LISTEN_REMOTE" != "yes" ; then PortOpts="${PortOpts:+${PortOpts},}Addr=127.0.0.1" SENDMAIL_ARGS="-O DaemonPortOptions=${PortOpts} $SENDMAIL_ARGS" fi
from /etc/init.d/sendmail to the service unit sendmail.service. With this there is a control if the MTA is listen on port 25 of any remote network interface or if not. How can this be done within a systemd service unit (without using a wrapper script)?
You can't do that directly in a unit file.
Maybe it would be an idea to have to possiblity to use short shell commands as it is possible in make or spec files: Environment=SENDMAIL_PORT_OPTS=$(shell code)
One option is to create a systemd generator (which is what is used for crypttab and getty service), to be installed in /lib/systemd/system-generator which would be started by systemd and would create temporary .service files in /run/systemd/generators (which is a tmpfs) which would be used by systemd as "normal" service files.
I've tested quickly and just dropping generator script in /lib/systemd/system-generators, make sure it is executable and takes one parameter which is the path where generated unit files should be written.
Hmmm ... I'm missing documentation on the topic `System Generators'. Werner -- "Having a smoking section in a restaurant is like having a peeing section in a swimming pool." -- Edward Burr -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-factory+help@opensuse.org
On Wed, Aug 10, 2011 at 11:45:01AM +0200, Frederic Crozat wrote:
Le vendredi 05 août 2011 à 12:02 +0200, Dr. Werner Fink a écrit :
[Unit] Description=Local SMTP Socket DefaultDependencies=no
[Socket] ListenStream=25 BindToDevice=lo Accept=false Service=sendmail.service
IMHO this will only used if no process is listen on localhost port 25 or is this wrong? The manual pages of systemd do not show what happens is a port is already busy due an other way of enabling the MTA.
Indeed, the socket listening code is systemd will fail and it won't try to activate sendmail.service
I would probably use mail-transfer-agent.target for Service= in smtp-local.socket, to not tie smtp-local.socket to sendmail.service.
Systemd dose not like this. Werner -- "Having a smoking section in a restaurant is like having a peeing section in a swimming pool." -- Edward Burr -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-factory+help@opensuse.org
Le jeudi 11 août 2011 à 14:37 +0200, Dr. Werner Fink a écrit :
On Wed, Aug 10, 2011 at 11:45:01AM +0200, Frederic Crozat wrote:
Currently I've not found a way to port
PortOpts="" for cfg in /etc/sendmail.cf /etc/mail/sendmail.cf do test -s $cfg || continue PortOpts=$(sed -rn '/^O[[:blank:]]+DaemonPortOptions=.*Name=MTA.*$/I { s/[[:blank:]]+//g s/^O[^=]+=(.*)/\1/p }' $cfg) break done unset cfg
if test "$SMTPD_LISTEN_REMOTE" != "yes" ; then PortOpts="${PortOpts:+${PortOpts},}Addr=127.0.0.1" SENDMAIL_ARGS="-O DaemonPortOptions=${PortOpts} $SENDMAIL_ARGS" fi
from /etc/init.d/sendmail to the service unit sendmail.service. With this there is a control if the MTA is listen on port 25 of any remote network interface or if not. How can this be done within a systemd service unit (without using a wrapper script)?
You can't do that directly in a unit file.
Maybe it would be an idea to have to possiblity to use short shell commands as it is possible in make or spec files:
Environment=SENDMAIL_PORT_OPTS=$(shell code)
You should suggest this on systemd-devel mailing list but I'm not sure systemd folks wants this.
One option is to create a systemd generator (which is what is used for crypttab and getty service), to be installed in /lib/systemd/system-generator which would be started by systemd and would create temporary .service files in /run/systemd/generators (which is a tmpfs) which would be used by systemd as "normal" service files.
I've tested quickly and just dropping generator script in /lib/systemd/system-generators, make sure it is executable and takes one parameter which is the path where generated unit files should be written.
Hmmm ... I'm missing documentation on the topic `System Generators'.
I've discussed this with systemd people at Desktop Summit. They
suggested only do socket activation on the "main" socket and have the
daemon listen to other sockets specified in sendmail configuration, if
they are free (like cups is doing :
http://0pointer.de/blog/projects/socket-activation2.html ).
System Generators were also mentioned as another way to do this but they
are started very early in boot process (so you can't depend on any
service) and don't have any "API stability promisse" (which is probably
why there is no real documentation about it).
--
Frederic Crozat
participants (2)
-
Dr. Werner Fink
-
Frederic Crozat