1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-15 07:56:36 +00:00

Rewrite startup scripts to use RC_SUBR

This commit is contained in:
Sergey Skvortsov 2005-02-21 17:22:38 +00:00
parent 61291bd40b
commit ec55ae3aab
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=129500
4 changed files with 121 additions and 77 deletions

View File

@ -7,6 +7,7 @@
PORTNAME= ipacctd
PORTVERSION= 1.46
PORTREVISION= 1
CATEGORIES= net-mgmt
MASTER_SITES= ftp://ftp.wuppy.net.ru/pub/FreeBSD/local/ipacctd/ \
${MASTER_SITE_LOCAL:S!$!skv/!}
@ -14,8 +15,7 @@ MASTER_SITES= ftp://ftp.wuppy.net.ru/pub/FreeBSD/local/ipacctd/ \
MAINTAINER= skv@FreeBSD.org
COMMENT= IP accounting using divert socket
STARTUP_SCRIPT= ipacctd.sh.sample
PLIST_SUB= STARTUP_SCRIPT=${STARTUP_SCRIPT}
USE_RC_SUBR= ipacctd.sh
WRKSRC= ${WRKDIR}/${PORTNAME}
MAKE_ENV+= BINDIR="${PREFIX}/sbin"
@ -30,7 +30,5 @@ post-install:
@${MKDIR} ${DOCSDIR}/ru
@${INSTALL_DATA} ${WRKSRC}/README.ipacctd ${DOCSDIR}/ru
.endif
${INSTALL_SCRIPT} ${FILESDIR}/${STARTUP_SCRIPT} \
${PREFIX}/etc/rc.d/${STARTUP_SCRIPT}
.include <bsd.port.mk>

View File

@ -0,0 +1,119 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: ipacctd
# REQUIRE: NETWORKING SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable ipacctd:
#
#ipacctd_enable="YES"
#
# Also additional flags can be specified:
#
#ipacctd_flags="-v"
#
# See ipacctd(8) for flags.
#
# Enumerate all accounted interfaces in "ipacctd_rules":
#
#ipacctd_rules="xl0"
#
# ...and add related required "ipacctd_rule_*_flags"
# and optional "ipacctd_rule_*_pid" (equal to "/var/run/ipacctd.*" by default)
#
#ipacctd_rule_xl0_flags="-p 666"
#ipacctd_rule_xl0_pid="/var/run/ipacctd.xl0"
. %%RC_SUBR%%
name="ipacctd"
rcvar=`set_rcvar`
command="%%PREFIX%%/sbin/ipacctd"
start_cmd="start_cmd"
stop_cmd="stop_cmd"
poll_cmd="poll_cmd"
status_cmd="status_cmd"
start_cmd()
{
for rule in ${ipacctd_rules}; do
debug "start ipacctd rule ${rule}"
local rule_flags
eval rule_flags=\$ipacctd_rule_${rule}_flags
if [ -z "$rule_flags" ]; then
echo " you must define flags for ipacctd rule '${rule}'"
exit 1
fi
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -n "$rc_pid" ]; then
echo "${name} with rule=$rule already running? (pid=$rc_pid)."
exit 1
fi
${command} ${ipacctd_flags} ${rule_flags} -r ${pidfile}
done
}
stop_cmd()
{
for rule in ${ipacctd_rules}; do
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -z "$rc_pid" ]; then
if [ -n "$pidfile" ]; then
echo "${name} with rule=$rule not running? (check $pidfile)."
else
echo "${name} with rule=$rule not running?"
fi
exit 1
fi
echo "Stopping ${name} rule=${rule}."
kill -${sig_stop:-TERM} $rc_pid
wait_for_pids $rc_pid
done
}
poll_cmd()
{
for rule in ${ipacctd_rules}; do
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -n "$rc_pid" ]; then
wait_for_pids $rc_pid
fi
done
}
status_cmd()
{
for rule in ${ipacctd_rules}; do
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -n "$rc_pid" ]; then
echo "${name} rule=${rule} is running as pid $rc_pid."
else
echo "${name} rule=${rule} is not running."
fi
done
}
load_rc_config $name
: ${ipacctd_enable="NO"}
: ${ipacctd_rules=""}
: ${ipacctd_flags=""}
run_rc_command "$1"

View File

@ -1,72 +0,0 @@
#!/bin/sh
if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then
echo "$0: Cannot determine the PREFIX" >&2
exit 1
fi
# If there is a global system configuration file, suck it in.
if [ -r /etc/defaults/rc.conf ]; then
. /etc/defaults/rc.conf
source_rc_confs
elif [ -r /etc/rc.conf ]; then
. /etc/rc.conf
fi
ipacctd_enable=${ipacctd_enable:-YES}
ipacctd_program=${ipacctd_program:-${PREFIX}/sbin/ipacctd}
ipacctd_flags=${ipacctd_flags:-"-v"}
#ipacctd_log_base=${ipacctd_log_base:-/var/log/ipacct}
#ipacctd_log_ext=${ipacctd_log_ext:-%Y-%m-%d-%T}
ipacctd_rules="xl0 ppp0"
ipacctd_rule_xl0_flags=""
ipacctd_rule_xl0_pid="/var/run/ipacctd.xl0"
ipacctd_rule_ppp0_flags=""
ipacctd_rule_ppp0_pid="/var/run/ipacctd.ppp0"
case "$1" in
start)
case "${ipacctd_enable}" in
[Yy][Ee][Ss])
if [ -f ${ipacctd_program} ]; then
echo -n ' ipacctd ['
for rule in ${ipacctd_rules}; do
echo -n " ${rule}"
eval ipacctd_rule_flags=\$ipacctd_rule_${rule}_flags
if [ -z $ipacctd_rule_flags ]; then
echo " you must define flags for rule ${rule}"
exit 1
fi
eval ipacctd_rule_pid=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
${ipacctd_program} \
${ipacctd_flags} \
${ipacctd_rule_flags} \
-r ${ipacctd_rule_pid}
done
echo -n " ]"
fi
;;
esac
;;
stop)
for rule in ${ipacctd_rules}; do
eval ipacctd_rule_pid=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
kill `cat ${ipacctd_rule_pid}`
done
;;
*)
echo "Usage: `basename $0` {start|stop}" >&2
;;
esac
exit 0

View File

@ -1,5 +1,4 @@
sbin/ipacctd
etc/rc.d/%%STARTUP_SCRIPT%%
%%PORTDOCS%%%%DOCSDIR%%/ru/README.ipacctd
%%PORTDOCS%%@dirrm %%DOCSDIR%%/ru
%%PORTDOCS%%@dirrm %%DOCSDIR%%