systemd/systemctl dual sendmail service start

I want to migrate to opensuse 13.1 and I just can’t find out how to configure the systemd scripts to start a dual sendmail daemon. Everything gets sent to systemctl and I’m just not familiar with it…

I need sendmail to start twice: one daemon listening on port 25 and one on port 10025. I use amavis in between listening on port 10024. So: the first sendmail (port 25) receives the mail -from fetchmail-, delivers it to amavis (port 10024) which delivers it to the second sendmail (port 10025), which sends the mails to the mailbox.

I need to start two sendmail daemons, as simple as that…

Thank you all in advance,
Luca

You will need to either create to different units with different name or create template unit that can be used to start different services from the same definition (like “systemctl start sendmail@25.service” and “systemctl start sendmail@10025.service”). See “man systemd.unit” for description of templates and there is plenty of examples in distributed units.

It’s not hard to configure sendmail to listen on both ports. I have it listening on ports 25, 465 (with crypto), 587.

If you need separate daemons, then you’ll need to do something similar to what arvidjaar has suggested.

… and that is my problem… maybe I am too stupid but, as I said, I am not familiar at all with systemd/systemctl, so it’s not easy for me to get it right…
I would be really thankful if someone could post some examples that I could -so to say- copy and paste. One daemon is running as a standard so I guess I should only add one instance, but how? :frowning:

Cheers,
Luca

I am not sure whether I do need two daemons… I actually did it that way because the first one (port 25) doesn’t do delivery, it just receives the mails and gives them to amavis (spam and virus checker), which gives them to the second daemon which then does the delivery…
Is this something you are doing as well?

Thanks
Luca

No.

I’ll admit that if you are doing as you describe, then separate daemons with different configuration is easier to maintain.

so would you (or someone else) be able and willing to guide me through?

Thanks,
Luca

I have not done that with systemd. I’d start by reading the man page recommended above by arvidjaar. If you need further help, hopefully someone with experience creating service definitions will be able to assist.

opensuse forums
systemd/systemctl dual sendmail
Although I haven’t done what you describe, in theory it’s pretty simple to do what you require.

  1. Install sendmail (or postfix which is actually the default SMTP server in openSUSE). It’ll install everything necessary to run in a default state.
  2. run something like the following
systemctl status sendmail.service

In the text you’ll find the path to the Unit file which in systemd is the master config file(likely at /usr/lib/systemd/system/). In some ways it’s similar to an init.d script except for a number of improvements… First invocation creates a CGROUP so all other instances like you’re trying to do will be managed together.and usually share resources instead of creating a whole new process. Also, a Unit file is almost always a “master config” file so it points to other config files (often standard files found in init.d systems).

Although it might be possible to add a new instance configuration to the existing Sendmail service, I suspect it might be easier to keep the new instance configuration completely separate.
3. When you find the original created Unit file, copy it to

/etc/systemd/system/system/

Now, if you wanted to modify the <existing installed> systemd function, you should just modify the file in the new location, it would over-ride the original installed file.

But,
Although it might be possible to add a new instance configuration to the existing Sendmail service, I suspect it might be easier to keep the new instance configuration completely separate.

To keep your copy’s configuration from completely over-writing the original default configuration, giving it a new name so it shouldn’t over-write the original Unit settings and create something new.
You may have to play around with the modifications in the Unit file(careful not to modify original configs which are still used by the original Unit file). Note though by working with a copy of the original you’re in no danger of damaging the original install… just delete the copy you’re working on.

HTH,
TSU

thank you everybody, I seem to have managed to make it work!
I created the two service files (ports 25 and 10025) with the proper variables, renamed the original one, and voila, it works…

thanks again to you all for your support,
Luca

Congrats.

For future Users who look up this thread, if you post your <exact> steps, I’m sure they’ll find it very useful.

TSU

thanks… :slight_smile:

Now, I had a working dual sendmail + amavis setup and just upgraded the OS. I am not going to explain that setup, I am just describing how I made it to start the two needed sendmail daemons under systemd/systemctl.

cd /usr/lib/systemd/system
cp sendmail.service sendmail@25.service
cp sendmail.service sendmail@10025.service
mv sendmail.service sendmail.service.orig
**#** cat sendmail@25.service 
# This file is part of package sendmail.
#
# Copyright (c) 2011 SuSE LINUX Products GmbH, Germany.
# Author: Werner Fink
# Please send feedback to http://www.suse.de/feedback
#
# Description:
#
#  Used to start the sendmail Mail Transport Agent service
#  which handles all mails stored at /var/spool/mqueue/ and
#  all connections on port 25 aka smtp at localhost as well
#  as on all other network interfaces.
#


[Unit]
Description=Sendmail Mail Transport Agent
Requires=var-run.mount nss-lookup.target network.target remote-fs.target time-sync.target
After=var-run.mount nss-lookup.target network.target remote-fs.target time-sync.target
Wants=amavis.service cyrus.service ldap.service nscd.service ypbind.service sendmail-client.service
After=amavis.service cyrus.service ldap.service nscd.service ypbind.service
Before=sendmail-client.service mail-transfer-agent.target
Conflicts=postfix.service exim.service


[Service]
Type=forking
PIDFile=/var/run/sendmail-rx.pid
ExecStartPre=-/bin/echo 'Initializing SMTP port 25 (sendmail-rx)'
ExecStartPre=-/etc/mail/system/sm.pre
Environment="SENDMAIL_ARGS=-C/etc/sendmail-rx.cf -L sendmail-rx -Am -bd -qp -om"
Environment=SENDMAIL_PORT_OPTS=
EnvironmentFile=-/etc/sysconfig/mail
EnvironmentFile=-/etc/sysconfig/sendmail
EnvironmentFile=-/var/run/sendmail/port
ExecStart=/usr/sbin/sendmail $SENDMAIL_PORT_OPTS $SENDMAIL_ARGS
ExecReload=/bin/kill -HUP $MAINPID


[Install]
WantedBy=multi-user.target

**#** cat sendmail@25.service 



# cat sendmail@10025.service

This file is part of package sendmail.

Copyright (c) 2011 SuSE LINUX Products GmbH, Germany.

Author: Werner Fink

Please send feedback to http://www.suse.de/feedback

Description:

Used to start the sendmail Mail Transport Agent service

which handles all mails stored at /var/spool/mqueue/ and

all connections on port 25 aka smtp at localhost as well

as on all other network interfaces.

[Unit]
Description=Sendmail Mail Transport Agent
Requires=var-run.mount nss-lookup.target network.target remote-fs.target time-sync.target
After=var-run.mount nss-lookup.target network.target remote-fs.target time-sync.target
Wants=amavis.service cyrus.service ldap.service nscd.service ypbind.service sendmail-client.service
After=amavis.service cyrus.service ldap.service nscd.service ypbind.service
Before=sendmail-client.service mail-transfer-agent.target
Conflicts=postfix.service exim.service

[Service]
Type=forking
PIDFile=/var/run/sendmail-tx.pid
ExecStartPre=-/bin/echo ‘Initializing SMTP port 10025 (sendmail-tx)’
ExecStartPre=-/etc/mail/system/sm.pre
Environment=“SENDMAIL_ARGS=-C/etc/sendmail-tx.cf -L sendmail-tx -Am -bd -qp -om”
Environment=SENDMAIL_PORT_OPTS=
EnvironmentFile=-/etc/sysconfig/mail
EnvironmentFile=-/etc/sysconfig/sendmail
EnvironmentFile=-/var/run/sendmail/port
ExecStart=/usr/sbin/sendmail $SENDMAIL_PORT_OPTS $SENDMAIL_ARGS_2
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target




cd /etc/systemd/system/


rm sendmail.service


  - start yast, go to system --&gt; services manager and activate the two new services



Et voila, it works!

I hope it's understandable...

Cheers,
Luca

FYI - I had a modified /etc/init.d/sendmail which did not need to be touched, but I post it to your better understanding.

cat /etc/init.d/sendmail
#! /bin/sh
# Copyright (c) 1996-2002 SuSE Gmbh Nuernberg, Germany.
# Copyright (c) 2006-2008 SuSE LINUX Products GmbH, Germany.
#
# Author: Florian La Roche, 1996, 1997
#      Werner Fink, 1996, 1999-2007
# Please send feedback to http://www.suse.de/feedback/
#
### BEGIN INIT INFO
# Provides:          sendmail smtp
# Required-Start:    $named $network $remote_fs $syslog $time
# Required-Stop:     $named $network $remote_fs $syslog
# Should-Start:      amavis cyrus ldap nscd ypbind
# Should-Stop:       amavis cyrus ldap nscd ypbind
# Default-Start:     3 5
# Default-Stop:
# Short-Description: Start the Sendmail MTA
# Description:       Start the Sendmail MTA
### END INIT INFO


test -s /etc/sysconfig/mail && \
     . /etc/sysconfig/mail


test -s /etc/sysconfig/sendmail && \
     . /etc/sysconfig/sendmail


if test -z "$SENDMAIL_ARGS" ; then
   SENDMAIL_ARGS="-C/etc/sendmail-rx.cf -L sendmail-rx -Am -bd -qp -om"
fi
if test -z "$SENDMAIL_ARGS_2" ; then
   SENDMAIL_ARGS_2="-C/etc/sendmail-tx.cf -L sendmail-tx -Am -bd -qp -om"
fi
if test -z "$SENDMAIL_CLIENT_ARGS" ; then
   SENDMAIL_CLIENT_ARGS="-L sendmail-client -Ac -qp1m"
fi


PortOpts=""
for cfg in /etc/sendmail-rx.cf /etc/mail/sendmail-rx.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


PortOpts_2=""
for cfg in /etc/sendmail-tx.cf /etc/mail/sendmail-tx.cf
do
   test -s $cfg || continue
   PortOpts_2=$(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_2="${PortOpts_2:+${PortOpts_2},}Addr=127.0.0.1"
   SENDMAIL_ARGS_2="-O DaemonPortOptions=${PortOpts_2} $SENDMAIL_ARGS_2"
fi


msppid=/var/spool/clientmqueue/sm-client.pid
srvpid=/var/run/sendmail-rx.pid
srvpid_2=/var/run/sendmail-tx.pid


#
# This function polls ten seconds on port 25 of localhost
#
poll25 ()
{
   local timeout=1000
   local port=25
   local opt


   for opt in ${PortOpts//,/ } ; do
    case "${opt%=*}" in
    [Pp]ort) port=${opt#*=}
    esac
   done


   while ! fuser -sn tcp $port > /dev/null 2>&1 ; do
    test $timeout -eq 0 && return 1
    usleep 10000
    : $((timeout--))
   done
   return 0
}


# This function polls ten seconds on port 10025 of localhost
#
poll10025 ()
{
   local timeout=1000
   local port=10025
   local opt


   for opt in ${PortOpts_2//,/ } ; do
       case "${opt%=*}" in
       [Pp]ort) port=${opt#*=}
       esac
   done


   while ! fuser -sn tcp $port > /dev/null 2>&1 ; do
       test $timeout -eq 0 && return 1
       usleep 10000
       : $((timeout--))
   done
   return 0
}


. /etc/rc.status
rc_reset
case "$1" in
   start)
    test -d /var/run          || mkdir --mode 0755 /var/run
    test -d /var/run/sendmail || mkdir --mode 1750 /var/run/sendmail
       echo -n "Initializing SMTP port 25 (sendmail-rx)"
       startproc -p $srvpid -i $msppid -i $srvpid_2 /usr/sbin/sendmail $SENDMAIL_ARGS
       rc_status && \
       poll25
       rc_status -v && \
       echo -n "Initializing SMTP port 10025 (sendmail-tx)"
       startproc -p $srvpid_2 -i $msppid -i $srvpid /usr/sbin/sendmail $SENDMAIL_ARGS_2
       rc_status && \
       poll10025
       rc_status -v && \
       echo -n "Initializing sendmail client"
       startproc -p $msppid -i $srvpid -i $srvpid_2 /usr/sbin/sendmail $SENDMAIL_CLIENT_ARGS
       rc_status -v
       ;;
   stop)
       echo -n "Shutting down SMTP ports (sendmail client)"
       killproc  -p $msppid -i $srvpid -i $srvpid_2 -TERM /usr/sbin/sendmail
       rc_status -v
       echo -n "Shutting down SMTP ports (sendmail RX)"
       killproc  -p $srvpid -i $msppid -i $srvpid_2 -TERM /usr/sbin/sendmail
       rc_status -v
       echo -n "Shutting down SMTP ports (sendmail TX)"
       killproc  -p $srvpid_2 -i $msppid -i $srvpid -TERM /usr/sbin/sendmail
       rc_status -v
       ;;
   try-restart)
    $0 stop && $0 start
    rc_status
    ;;
   restart)
    $0 stop
    $0 start
    rc_status
    ;;
   reload|force-reload)
    echo -n "Reload service sendmail client"
    killproc  -p $msppid -i $srvpid -i $srvpid_2 /usr/sbin/sendmail
    rc_status
    startproc -p $msppid -i $srvpid -i $srvpid_2 /usr/sbin/sendmail $SENDMAIL_CLIENT_ARGS
    rc_status
    killproc  -p $srvpid -i $msppid -i $srvpid_2 -HUP  /usr/sbin/sendmail $SENDMAIL_ARGS
    rc_status
    killproc  -p $srvpid_2 -i $msppid -i $srvpid -HUP  /usr/sbin/sendmail $SENDMAIL_ARGS_2
    rc_status -v
    ;;
   status)
       echo -n "Checking for service sendmail (RX): "
       checkproc -p $srvpid -i $msppid -i $srvpid_2 /usr/sbin/sendmail
       rc_status -v
       echo -n "Checking for service sendmail (TX): "
       checkproc -p $srvpid_2 -i $msppid -i $srvpid /usr/sbin/sendmail
       rc_status -v
       echo -n "Checking for service sendmail client: "
       checkproc -p $msppid -i $srvpid -i $srvpid_2 /usr/sbin/sendmail
       rc_status -v
       ;;
   probe)
       todo=""
       test /etc/sendmail-rx.cf    -nt $srvpid && todo=reload
       test /etc/sendmail-tx.cf    -nt $srvpid_2 && todo=reload
       test /etc/mail/submit.cf -nt $msppid && todo=reload
       checkproc -p $srvpid -i $msppid -i $srvpid_2 /usr/sbin/sendmail || todo=restart
       checkproc -p $srvpid_2 -i $msppid -i $srvpid /usr/sbin/sendmail || todo=restart
       checkproc -p $msppid -i $srvpid -i $srvpid_2 /usr/sbin/sendmail || todo=restart
       test -z "$todo" || echo "$todo"
       ;;
   *)
    echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
    exit 1
esac
rc_exit

Cheers,
Luca