#!/bin/sh

# $FreeBSD: ports/mail/noattach/files/noattach.in,v 1.2 2012/11/17 05:59:07 svnexp Exp $

# Start or stop noattach

# PROVIDE: noattach
# REQUIRE: DAEMON
# BEFORE: mail
# KEYWORD: shutdown
#

# Define these noattach_* variables in one of these files:
#	/etc/rc.conf
#	/etc/rc.conf.local
#	/etc/rc.conf.d/noattach
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#
# noattach_flags Flags to noattach

noattach_enable=${noattach_enable:-"NO"}      # Enable noattach
noattach_pidfile=${noattach_pidfile:-"/var/run/noattach.pid"} # Path to pidfile
noattach_socket=${noattach_socket:-"/var/run/noattach"} # Path to socket

. /etc/rc.subr

name="noattach"
rcvar="noattach_enable"
command="/usr/local/libexec/${name}"
required_files="/usr/local/etc/noattach.patterns"
start_precmd="noattach_prestart"
stop_postcmd="noattach_poststop"
reload_cmd="noattach_reload"
extra_commands="reload"

noattach_prestart() {
	/bin/rm -f "${pidfile}" "${noattach_socket}"
}

noattach_poststop() {
	/bin/rm -f "${pidfile}" "${noattach_socket}"
}

noattach_reload() {
	kill -USR1 `head -1 "${pidfile}"`
}

load_rc_config $name
pidfile="${noattach_pidfile}"
command_args="-p local:${noattach_socket} ${noattach_flags}"

run_rc_command "$1"
