ports/110545: rcNG script for qmail-smtpd

Clement Moulin freebsd at simplerezo.com
Mon Mar 19 23:30:06 UTC 2007


>Number:         110545
>Category:       ports
>Synopsis:       rcNG script for qmail-smtpd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 19 23:30:02 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Clement Moulin
>Release:        6.2-RELEASE
>Organization:
SimpleRezo
>Environment:
N/A
>Description:
I have made a rcNG script for qmail-smtpd, so maybe the qmail port maintainer want to import it ...

This script is capable of managing multiple instances of qmail-smtpd, for example, one for outgoing and one for incoming.

For each instance, you can specificy to enable or not qmail-scanner (you may want to disable it for outgoing mails...).

Of course, for each instance you need a tcprules file (.cdb) and you can use a rbl file, just place that files in /usr/local/etc/smtp/ and use following names: rbls-INSTANCE.conf and rules-INSTANCE.cdb
>How-To-Repeat:
WARNING: the status/stop functionnality may not work if your /etc/rc.subr is too old
   for 5.X branch, you need the 1.31.2.5 revision
   for 6.X branch, you need at least the 1.34.2.5 revision

>Fix:
#!/bin/sh
#
# $Id: qmail-smtpd.sh,v 1.2 2007/02/19 12:59:21 cvs Exp $
#
# PROVIDE: smtpd
# REQUIRE: NETWORKING
# KEYWORD: FreeBSD
#
# Add the following lines to /etc/rc.conf to enable smtpd:
# smtpd_instances="in out"
# smtpd_in_enable="YES"
# smtpd_in_host="1.2.3.4"
# smtpd_in_qscan="YES"
# smtpd_out_enable="YES"
# smtpd_out_host="192.168.0.1"
#
# WARNING: the status/stop functionnality may not work if your /etc/rc.subr is too old
#   for 5.X branch, you need the 1.31.2.5 revision
#   for 6.X branch, you need at least the 1.34.2.5 revision

name=smtpd

. /etc/rc.subr

load_rc_config ${name}

prefix=/usr/local

smtpd_qsmtpd=${smtpd_qsmtpd:-"/var/qmail/bin/qmail-smtpd"}
smtpd_qscan=${smtpd_qscan:-"${prefix}/bin/qmail-scanner-queue.pl"}
smtpd_rblsmtpd=${smtpd_rblsmtpd:-"${prefix}/bin/rblsmtpd"}
smtpd_tcpserver=${smtpd_tcpserver:-"${prefix}/bin/tcpserver"}

start_postcmd()
{
  echo -n $! > ${pidfile}
}

start_precmd()
{
  rbls=
  if [ -n "${name_rbls}" ]; then
    if [ -r "${name_rbls}" ]; then
      for rbl in `/bin/cat ${name_rbls}`; do
        rbls="$rbls -r $rbl"
      done
    else
      warn "File ${name_rbls} cannot be found/read"
    fi
  fi
  if [ -n "${rbls}" ]; then
    [ -n "${smtpd_rblsmtpd}" -a ! -x "${smtpd_rblsmtpd}" ] && err "Missing ${smtpd_rblsmtpd}"
    rbls=" ${smtpd_rblsmtpd}${rbls}"
  fi

  cdb=
  if [ -n "${name_cdb}" ]; then
    if [ -r ${name_cdb} ]; then
      cdb="-x ${name_cdb}"
    else
      warn "File ${name_cdb} cannot be found/read"
    fi
  fi

  command_args="${cdb} ${host} ${port} ${rbls} ${smtpd_qsmtpd} &"
}

status()
{
  if [ -n "$rc_pid" ]; then
    echo "${name} is running as pid $rc_pid."
  else
    echo "${name} is not running."
    return 1
  fi
}

stop_postcmd()
{
  [ -r "${pidfile}" ] && /bin/rm ${pidfile}
}

# Hack until run_rc_command() get rid of exit()
stop()
{
  if [ -z ${rc_pid} ]; then
    echo "${name} not running? (check ${pidfile})."
    return 1
  fi
  echo "Stopping ${name}."
  kill -${sig_stop:-TERM} ${rc_pid}
  [ $? -ne 0 ] && [ -z "$rc_force" ] && return 1
  wait_for_pids ${rc_pid}
}

for instance in ${smtpd_instances}; do
  name=smtpd_${instance}
  rcvar=`set_rcvar`
  required_files="${smtpd_qsmtpd}"

  eval host=\${${name}_host:-""}
  eval port=\${${name}_port:-"smtp"}

  [ -z "${host}" ] && err "${name}_host is not set."

  eval ${name}_enable=\${${name}_enable:-"NO"}
  eval ${name}_flags=\${${name}_flags:-"-q -H -D -R -u `/usr/bin/id -u qmaild` -g `/usr/bin/id -g qmaild` -l ${host}"}
  eval ${name}_qscan=\${${name}_qscan:-"NO"}

  eval name_rbls=\${${name}_rbls:-${prefix}/etc/smtpd/rbls-${instance}.conf}
  eval name_cdb=\${${name}_rules:-${prefix}/etc/smtpd/rules-${instance}.cdb}

  if checkyesno ${name}_qscan; then
    required_files="${required_files} ${smtpd_qscan}"
    export QMAILQUEUE="${smtpd_qscan}"
  else
    unset QMAILQUEUE
  fi

  command="${smtpd_tcpserver}"
  pidfile=/var/run/smtpd-${instance}.pid
  procname=${command}
  start_precmd=start_precmd
  start_postcmd=start_postcmd
  status_cmd=status
  stop_cmd=stop
  stop_postcmd=stop_postcmd

  run_rc_command "$1"
done
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list