summaryrefslogtreecommitdiffstats
path: root/net-mgmt/ipacctd
diff options
context:
space:
mode:
authorskv <skv@FreeBSD.org>2005-02-21 17:22:38 +0000
committerskv <skv@FreeBSD.org>2005-02-21 17:22:38 +0000
commitbd81e3155c404ce62915e2c762b41fffb7b21649 (patch)
treebc74cc307324f51110a3ced3f7a6056d0229a276 /net-mgmt/ipacctd
parent7f89c32a8a3d606fad8e4453c44d37979cc6131e (diff)
downloadFreeBSD-ports-bd81e3155c404ce62915e2c762b41fffb7b21649.zip
FreeBSD-ports-bd81e3155c404ce62915e2c762b41fffb7b21649.tar.gz
Rewrite startup scripts to use RC_SUBR
Diffstat (limited to 'net-mgmt/ipacctd')
-rw-r--r--net-mgmt/ipacctd/Makefile6
-rw-r--r--net-mgmt/ipacctd/files/ipacctd.sh.in119
-rw-r--r--net-mgmt/ipacctd/files/ipacctd.sh.sample72
-rw-r--r--net-mgmt/ipacctd/pkg-plist1
4 files changed, 121 insertions, 77 deletions
diff --git a/net-mgmt/ipacctd/Makefile b/net-mgmt/ipacctd/Makefile
index 679bdb1..136a418 100644
--- a/net-mgmt/ipacctd/Makefile
+++ b/net-mgmt/ipacctd/Makefile
@@ -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>
diff --git a/net-mgmt/ipacctd/files/ipacctd.sh.in b/net-mgmt/ipacctd/files/ipacctd.sh.in
new file mode 100644
index 0000000..09ab801
--- /dev/null
+++ b/net-mgmt/ipacctd/files/ipacctd.sh.in
@@ -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"
diff --git a/net-mgmt/ipacctd/files/ipacctd.sh.sample b/net-mgmt/ipacctd/files/ipacctd.sh.sample
deleted file mode 100644
index 90e85c1..0000000
--- a/net-mgmt/ipacctd/files/ipacctd.sh.sample
+++ /dev/null
@@ -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
-
diff --git a/net-mgmt/ipacctd/pkg-plist b/net-mgmt/ipacctd/pkg-plist
index 5715a08..8acc7a3 100644
--- a/net-mgmt/ipacctd/pkg-plist
+++ b/net-mgmt/ipacctd/pkg-plist
@@ -1,5 +1,4 @@
sbin/ipacctd
-etc/rc.d/%%STARTUP_SCRIPT%%
%%PORTDOCS%%%%DOCSDIR%%/ru/README.ipacctd
%%PORTDOCS%%@dirrm %%DOCSDIR%%/ru
%%PORTDOCS%%@dirrm %%DOCSDIR%%
OpenPOWER on IntegriCloud