Subject: Re: pkgsrc rc.d scripts
To: Johnny C. Lam <lamj@stat.cmu.edu>
From: Greg A. Woods <woods@weird.com>
List: tech-pkg
Date: 05/14/2001 17:33:23
[ On Monday, May 14, 2001 at 15:21:15 (-0400), Johnny C. Lam wrote: ]
> Subject: pkgsrc rc.d scripts
>
> What's our preference for rc.d-style scripts? In
> databases/postgresql-server/files/pgsql.sh, the script is a
> self-contained script that obeys /etc/rc.conf directives and accepts
> all the usual rc.d command (start, stop, etc.)
I wrote the following for Squid and it works on 1.5T and 1.3.3:
#! /bin/sh
#
# $NetBSD$
#
# PROVIDE: squid
# REQUIRE: DAEMON
# KEYWORD: shutdown
SQUID_CONF_DIR="@SQUID_CONF_DIR@"
SQUID_LOG_DIR="@SQUID_LOG_DIR@"
conf_file="${SQUID_CONF_DIR}/squid.conf"
name="squid"
command="@PREFIX@/sbin/${name}"
pidfile="/var/run/${name}.pid"
required_files="${conf_file} ${SQUID_CONF_DIR}/squid-mime.conf"
start_cmd="@PREFIX@/sbin/RunCache ${conf_file} &"
stop_cmd="stop_nicely"
kill_command="${command} -k shutdown"
reload_cmd="${command} -k reconfigure"
#### end of configuration section ####
# older systems even with /etc/rc.d need this....
#
stop_nicely ()
{
if [ -f ${pidfile} ] ; then
DAEMON_PID=`sed 1q ${pidfile}`
echo -n "Stopping ${name}"
${kill_command}
if [ ${DAEMON_PID} -ne 0 ]; then
echo -n '['
while kill -0 ${DAEMON_PID} >/dev/null 2>&1; do
sleep 2
echo -n '.'
done
echo '] Stopped.'
fi
fi
}
if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ] ; then # i.e. is this NetBSD's new startup?
. /etc/rc.subr
. /etc/rc.conf
start_precmd="checkyesno squid"
stop_precmd=${start_precmd}
reload_precmd=${start_precmd}
extra_commands="reload"
if type load_rc_config > /dev/null 2>&1 ; then
load_rc_config $name
fi
run_rc_command "$1"
else # old NetBSD, Solaris, Linux, etc...
case $1 in
start)
if [ -x ${command} -a -f ${conf_file} ] ; then
eval ${start_cmd} && echo -n " ${name}"
fi
;;
stop)
${stop_cmd}
;;
reload)
if [ -f ${pidfile} ] ; then
${reload_cmd}
fi
;;
*)
echo "Usage: $0 {start|stop|reload}" 1>&2
exit 64
;;
esac
fi
--
Greg A. Woods
+1 416 218-0098 VE3TCP <gwoods@acm.org> <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>