From owner-freebsd-rc@FreeBSD.ORG Sat Jun 9 01:04:15 2012 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C16A0106564A for ; Sat, 9 Jun 2012 01:04:15 +0000 (UTC) (envelope-from sahil@tandon.net) Received: from cricket.hamla.org (cricket.hamla.org [206.251.255.31]) by mx1.freebsd.org (Postfix) with ESMTP id A8B488FC12 for ; Sat, 9 Jun 2012 01:04:15 +0000 (UTC) Received: from magic.hamla.org (cpe-68-174-134-215.nyc.res.rr.com [68.174.134.215]) by cricket.hamla.org (Postfix) with ESMTPSA id 88DA58A06C for ; Fri, 8 Jun 2012 21:04:08 -0400 (EDT) Date: Fri, 8 Jun 2012 21:04:06 -0400 From: Sahil Tandon To: freebsd-rc@freebsd.org Message-ID: <20120609010405.GA295@magic.hamla.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: clamav-milter 0.97.3 at cricket.hamla.org X-Virus-Status: Clean Subject: RESEND: [sahil@tandon.net: Request for review: mail/postfix-postfwd rc script] X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Sahil Tandon List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jun 2012 01:04:15 -0000 I suspect my last message was mangled in transit because of the way the attachment was included; trying again in-line. ----- Forwarded message from Sahil Tandon ----- Greetings, I haven't hacked on rc scripts in a while, and have made some non-negligible changes to the mail/postfix-postfwd script. I would be much obliged to anyone who could catch egregious mistakes, and also welcome style or "best practices" suggestions. No need to be gentle, and thanks in advance! :) Please Cc: me on any replies as I am not subscribed to this list. -- Sahil Tandon Index: files/postfwd.in =================================================================== RCS file: /home/pcvs/ports/mail/postfix-postfwd/files/postfwd.in,v retrieving revision 1.4 diff -u -u -r1.4 postfwd.in --- files/postfwd.in 14 Jan 2012 08:56:01 -0000 1.4 +++ files/postfwd.in 8 Jun 2012 00:43:08 -0000 @@ -9,9 +9,10 @@ # # postfwd_enable (bool): # Set to "NO" by default. -# Set it to "YES" to enable postfwd. -# postfwd_config (path): Set to %%PREFIX%%/etc/postfwd.conf -# by default. +# Set it to "YES" to enable postfwd. +# postfwd_config (path): +# Set to %%PREFIX%%/etc/postfwd.conf +# by default. # . /etc/rc.subr @@ -19,27 +20,45 @@ name=postfwd rcvar=postfwd_enable -command=%%PREFIX%%/bin/${name} -required_files=%%PREFIX%%/etc/${name}.conf -pidfile="/var/run/${name}.pid" +load_rc_config $name -stop_postcmd=stop_postcmd +: ${postfwd_enable="NO"} +: ${postfwd_config="%%PREFIX%%/etc/${name}.conf"} +: ${postfwd_flags="--shortlog --summary=600 --cache=600 --cache-rbl-timeout=3600 --cleanup-requests=1200 --cleanup-rbls=1800 --cleanup-rates=1200"} +: ${postfwd_pidfile="/var/run/${name}.pid"} -stop_postcmd() -{ - rm -f $pidfile -} +required_files=%%PREFIX%%/etc/${name}.conf +command=%%PREFIX%%/bin/${name} +command_args="-d -f ${required_files} --pidfile=${postfwd_pidfile} -i 127.0.0.1 -p 10040 -u nobody -g nobody" -load_rc_config "$name" +start_precmd="${name}_check" +status_cmd="${name}_status" +stop_cmd="${name}_stop" +stop_postcmd="${name}_postcmd" +extra_commands="reload" + +postfwd_check() { + if [ -f "${postfwd_pidfile}" ]; then + err 1 "${name} is already running." + fi +} -case "$postfwd_enable" in - [Yy][Ee][Ss] | 1 | [Oo][Nn] | [Tt][Rr][Uu][Ee]) ;; - *) echo "To make use of $name you must first set $rcvar=\"YES\" in /etc/rc.conf" ;; -esac +postfwd_status() { + postfwd_pid=`cat ${postfwd_pidfile} 2>/dev/null` + postfwd_run=`ps -U nobody | grep -m 1 ${postfwd_pid} 2>/dev/null` + if [ -n "${postfwd_pid}" -a -n "${postfwd_run}" ]; then + echo "$name is running as ${postfwd_pid}" + else + echo "$name is not running" + fi +} -: ${postfwd_enable="NO"} -: ${postfwd_config="%%PREFIX%%/etc/${name}.conf"} +postfwd_stop() { + ${command} -k --pidfile=${postfwd_pidfile} +} -command_args="--shortlog --summary=600 --cache=600 --cache-rbl-timeout=3600 --cleanup-requests=1200 --cleanup-rbls=1800 --cleanup-rates=1200 -d -f ${required_files} -i 127.0.0.1 -p 10040 -u nobody -g nobody" +postfwd_postcmd() { + rm -f ${postfwd_pidfile} +} run_rc_command "$1" ----- End forwarded message -----