Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Jan 2006 11:56:58 +0900
From:      Hirohisa Yamaguchi <umq@ueo.co.jp>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/91895: [patch] mail/dk-milter startup script to run multiple instances
Message-ID:  <86bqyb5zph.wl%umq@ueo.co.jp>
Resent-Message-ID: <200601170300.k0H30JQ0055166@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         91895
>Category:       ports
>Synopsis:       [patch] mail/dk-milter startup script to run multiple instances
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 17 03:00:19 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Hirohisa Yamaguchi
>Release:        FreeBSD 7.0-CURRENT amd64
>Organization:
<organization of PR author (multiple lines)>
>Environment:
System: FreeBSD calliope.kaumoge.org 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Mon Nov 7 17:32:33 JST 2005 root@calliope.kaumoge.org:/usr/obj/usr/src/sys/CALLIOPE64 amd64
>Description:
	In some cases, several instances of a milter with different
	configuration run simultaneously; e.g. different key with
	different selector, or domain for dk-milter.

	This patch enables multiple instantiation.

	# almost the same as ports/91894
>How-To-Repeat:
>Fix:

	the patch follows:

diff -rpu ports.orig/mail/dk-milter/files/milter-dk.sh.in ports/mail/dk-milter/files/milter-dk.sh.in
--- ports.orig/mail/dk-milter/files/milter-dk.sh.in	Sun Jan 15 18:11:04 2006
+++ ports/mail/dk-milter/files/milter-dk.sh.in	Tue Jan 17 11:16:54 2006
@@ -3,9 +3,9 @@
 # $FreeBSD: ports/mail/dk-milter/files/milter-dk.sh.in,v 1.2 2006/01/15 09:11:04 pav Exp $
 #
 
-# PROVIDE: milterdk
+# PROVIDE: milter-dk
 # REQUIRE: DAEMON
-# BEFORE: sendmail
+# BEFORE: mail
 # KEYWORD: shutdown
 
 # Define these milterdk_* variables in one of these files:
@@ -13,28 +13,83 @@
 #	/etc/rc.conf.local
 #	/etc/rc.conf.d/milterdk
 #
+# milterdk_enable (bool):   Set to "NO" by default.
+#                             Set it to "YES" to enable dk-milter
+# milterdk_profiles (list):  Set to "" by default.
+#                             Define your profiles here.
+# milterdk_socket (str):    Path to the milter socket.
+# milterdk_domain (str):    Domainpart of From: in mails to sign.
+# milterdk_key (str):       Path to the private key file to sign with.
+# milterdk_flags (str):     Flags passed to start command.
+#
+# milterdk_${profile}_* :   Variables per profile.
+#                             Sockets must be different from each other.
+#
 # DO NOT CHANGE THESE DEFAULT VALUES HERE
 #
 milterdk_enable=${milterdk_enable:-"NO"}
+milterdk_profiles=${milterdk_profiles:-}
 milterdk_socket=${milterdk_socket:-"local:/var/run/dk-filter"}
-milterdk_pid=${milterdk_pid:-"/var/run/dk-filter.pid"}
 milterdk_domain=${milterdk_domain:-"example.com"}
 milterdk_key=${milterdk_key:-"/var/db/domainkeys/default.key.pem"}
-milterdk_flags=${milterdk_flags:-"-d ${milterdk_domain} -c nofws -H -m MSA \
--s ${milterdk_key} -S default"}
+## milterdk_flags expands escaped variables later.
+milterdk_flags=${milterdk_flags:-"-d \${milterdk_domain\} -c nofws -H -m MSA \
+-s \${milterdk_key\} -S default"}
 
 . %%RC_SUBR%%
 
 name="milterdk"
-pidfile=${milterdk_pid}
 rcvar=`set_rcvar`
+
+start_precmd="dk_prepcmd"
+stop_postcmd="dk_prepcmd"
 command="%%PREFIX%%/libexec/dk-filter"
-command_args="-l -p ${milterdk_socket} -P ${milterdk_pid}"
-stop_postcmd="dk_postcmd"
+_pidprefix="/var/run/dk-filter"
+pidfile="${_pidprefix}.pid"
 
 load_rc_config $name
 
-dk_postcmd ()
+if [ -n "$2" ]; then
+    profile="$2"
+    if [ "x${milterdk_profiles}" != "x" ]; then
+	pidfile="${_pidprefix}.${profile}.pid"
+	eval milterdk_enable="\${milterdk_${profile}_enable:-${milterdk_enable}}"
+	eval milterdk_socket="\${milterdk_${profile}_socket:-}"
+	if [ "x${milterdk_socket}" = "x" ];then
+	    echo "You must define a socket (milterdk_${profile}_socket)"
+	    exit 1
+	fi
+	eval milterdk_domain="\${milterdk_${profile}_domain:-${milterdk_domain}}"
+	eval milterdk_key="\${milterdk_${profile}_key:-${milterdk_key}}"
+	eval milterdk_flags="\${milterdk_${profile}_flags:-${milterdk_flags}}"
+	command_args="-l -p ${milterdk_socket} -P ${pidfile}"
+    else
+	echo "$0: extra argument ignored"
+    fi
+else
+    if [ "x${milterdk_profiles}" != "x" -a "x$1" != "x" ]; then
+	if [ "x$1" != "xrestart" ]; then
+	    for profile in ${milterdk_profiles}; do
+		echo "===> milterdk profile: ${profile}"
+		%%PREFIX%%/etc/rc.d/milter-dk.sh $1 ${profile}
+		retcode="$?"
+		if [ "0${retcode}" -ne 0 ]; then
+		    failed="${profile} (${retcode}) ${failed:-}"
+		else
+		    success="${profile} ${success:-}"
+		fi
+	    done
+	    exit 0
+	else
+	    restart_precmd=""
+	fi
+    else
+	milterdk_flags=${milterdk_flags}
+	command_args="-l -p ${milterdk_socket} -P ${pidfile}"
+    fi
+fi
+
+dk_prepcmd ()
 {
     if [ -S ${milterdk_socket##local:} ] ; then
         rm -f ${milterdk_socket##local:}
diff -rpu ports.orig/mail/dk-milter/pkg-message ports/mail/dk-milter/pkg-message
--- ports.orig/mail/dk-milter/pkg-message	Sun May 22 22:39:11 2005
+++ ports/mail/dk-milter/pkg-message	Tue Jan 17 11:22:32 2006
@@ -8,4 +8,8 @@ INPUT_MAIL_FILTER(`dk-filter', `S=unix:/
 define(`confMILTER_MACROS_CONNECT', `j, {daemon_name}')
 define(`confMILTER_MACROS_ENVFROM', `i, {auth_type}')
 
+And to run the milter from startup, add milterdk_enable="YES" in
+your /etc/rc.conf.
+Extra options can be found in startup script.
+
 ************************************************************************

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86bqyb5zph.wl%umq>