[Mimedefang] FreeBSD/NetBSD mimedefang startup files

Jan-Pieter Cornet johnpc at xs4all.nl
Thu Oct 18 12:12:38 EDT 2007


While looking for a nice way to start mimedefang on our new
FreeBSD 6.2 cluster, I came upon John Nemeth's submissions to the
list last august. However, these scripts are completely different
from the default init-script as supplied by MIMEDefang itself.

The disadvantage is that it's no longer possible to use the nice
configuration parameters, like MX_RECIPIENT_CHECK or MX_USER,
which make the startup process much more managable.

So, I decided to take the standard init-script, and turn it into
something that can be dropped into FreeBSD's /usr/local/etc/rc.d 
directory, with a minimal amount of changes.

I came up with the attached set of patches. This minimally
changes the init-script (putting the "reread" in a function),
stays completely backwards compatible with the current script,
yet it's a fully operational FreeBSD/NetBSD startup script.

The only configuration it needs (if running on FreeBSD), is
a mimedefang_enable=YES in your rc.conf file. (or mimedefang=YES
on NetBSD). But you'd expect that anyway, if you're on FreeBSD/NetBSD.

The 'rest' of the configuration goes into the mimedefang default
of /usr/local/etc/mimedefang/mimedefang.conf, and not in rc.conf,
like John's script. However, you can use the easy environment variables
to config it, and nobody needs to change the startup script, so it
can be replaced on upgrades, etc.

So I suggest that either this patch is incorporated into the FreeBSD
port version, or better yet, that a FreeBSD example init script is
provided by MIMEDefang, or possibly even change the provided init
script with these patches :)

Comments welcome, of course. (However, since I'll be in Rome for a long
weekend, I won't respond until monday...)

-- 
Jan-Pieter Cornet <johnpc at xs4all.nl>
!! Disclamer: The addressee of this email is not the intended recipient. !!
!! This is only a test of the echelon and data retention systems. Please !!
!! archive this message indefinitely to allow verification of the logs.  !!
-------------- next part --------------
--- init-script	Thu Oct 18 13:15:09 2007
+++ mimedefang	Thu Oct 18 17:56:01 2007
@@ -1,7 +1,11 @@
 #!/bin/sh
 #
-# Generic start/stop script for MIMEDefang.  Should work on most
-# flavors of UNIX.
+# FreeBSD/NetBSD start/stop script for MIMEDefang.
+#
+# PROVIDE: mimedefang
+# REQUIRE: LOGIN
+# BEFORE: mail
+# KEYWORD: shutdown
 
 RETVAL=0
 prog='mimedefang'
@@ -169,6 +173,29 @@
     . /usr/local/etc/mimedefang/$prog.conf
 fi
 
+# BSD specific setup
+if [ -f /etc/rc.subr ]
+then
+    . /etc/rc.subr
+
+    name=$prog
+    rcvar=`set_rcvar`
+    # default to not enabled, enable in rc.conf
+    eval $rcvar=\${$rcvar:-NO}
+
+    load_rc_config $name
+
+    pidfile=$MXPID
+    procname=$PROGDIR/$prog-multiplexor
+    start_cmd="start_it"
+    stop_cmd="stop_it"
+    sig_reload="INT"
+    reread_cmd="reread_it"
+    # provide both "reload", the FreeBSD default, with a direct signal to
+    # the multiplexor, and "reread", the MIMEDefang default, using md-mx-ctrl
+    extra_commands="reload reread"
+fi
+
 # Make sure required vars are set
 SOCKET=${SOCKET:=$SPOOLDIR/$prog.sock}
 MX_SOCKET=${MX_SOCKET:=$SPOOLDIR/$prog-multiplexor.sock}
@@ -316,23 +343,7 @@
     rm -f $PID > /dev/null 2>&1
 }
 
-# See how we were called.
-case "$1" in
-  start)
-  start_it
-    ;;
-
-  stop)
-  stop_it $2
-    ;;
-
-  restart)
-    stop_it wait
-    start_it
-    RETVAL=$?
-    ;;
-
-  reread|reload)
+reread_it() {
 	if [ -x $PROGDIR/md-mx-ctrl ] ; then
 	    $PROGDIR/md-mx-ctrl -s $MX_SOCKET reread > /dev/null 2>&1
 	    RETVAL=$?
@@ -355,6 +366,33 @@
 		echo "Could not find process-ID of $prog-multiplexor"
 	    fi
 	fi
+}
+
+if type run_rc_command > /dev/null 2>&1
+then
+    # NetBSD/FreeBSD compatible startup script
+    run_rc_command "$1"
+    exit $RETVAL
+fi
+
+# See how we were called.
+case "$1" in
+  start)
+  start_it
+    ;;
+
+  stop)
+  stop_it $2
+    ;;
+
+  restart)
+    stop_it wait
+    start_it
+    RETVAL=$?
+    ;;
+
+  reread|reload)
+    reread_it
     ;;
 
   *)


More information about the MIMEDefang mailing list