From c09b5d0db1147df277adb44ef8e8c818c5cce2c0 Mon Sep 17 00:00:00 2001 From: demon Date: Mon, 6 Feb 2006 12:24:19 +0000 Subject: Install rcNG script to run mrtg in daemon mode. Submitted by: Jan Srzednicki --- net-mgmt/mrtg/Makefile | 11 ++++++++ net-mgmt/mrtg/files/mrtg_daemon.sh.in | 30 +++++++++++++++++++++ net-mgmt/mrtg/pkg-install | 49 +++++++++++++++++++++++++++++++++++ net-mgmt/mrtg/pkg-plist | 1 + 4 files changed, 91 insertions(+) create mode 100644 net-mgmt/mrtg/files/mrtg_daemon.sh.in create mode 100644 net-mgmt/mrtg/pkg-install (limited to 'net-mgmt') diff --git a/net-mgmt/mrtg/Makefile b/net-mgmt/mrtg/Makefile index d777ccd9391c..c51019375be4 100644 --- a/net-mgmt/mrtg/Makefile +++ b/net-mgmt/mrtg/Makefile @@ -30,6 +30,9 @@ CONFIGURE_ARGS= --with-gd-lib=${LOCALBASE}/lib \ USE_PERL5= YES MAKE_ENV+= PERL=${PERL} +USE_RC_SUBR= mrtg_daemon.sh +SUB_LIST+= PERL=${PERL} + GNU_CONFIGURE= YES CONFIGURE_ENV= PERL=${PERL} @@ -50,6 +53,9 @@ RUN_DEPENDS+= ${SITE_PERL}/IO/Socket/INET6.pm:${PORTSDIR}/net/p5-IO-INET6 post-patch: ${RM} ${WRKSRC}/lib/mrtg2/BER.pm ${WRKSRC}/lib/mrtg2/SNMP_*.pm +pre-install: + @PKG_PREFIX=${PREFIX} ${SH} ${PKGINSTALL} ${PKGNAME} PRE-INSTALL + do-install: ${MKDIR} -m 755 ${PREFIX}/etc/mrtg ${MKDIR} -m 755 ${DATADIR} @@ -70,12 +76,17 @@ do-install: done post-install: + @PKG_PREFIX=${PREFIX} ${SH} ${PKGINSTALL} ${PKGNAME} POST-INSTALL .if !defined(BATCH) @${ECHO} "" @${ECHO} "############################################################################" @${ECHO} "# Please create a MRTG config file in ${PREFIX}/etc/mrtg #" @${ECHO} "# A configuration file can be automatically generated with cfgmaker #" @${ECHO} "# A sample configuration file is installed as mrtg.cfg.sample #" + @${ECHO} "# #" + @${ECHO} "# To enable MRTG in daemon mode, put the following to your /etc/rc.conf or #" + @${ECHO} "# /etc/rc.conf.local file: #" + @${ECHO} "# mrtg_daemon_enable=\"YES\" #" @${ECHO} "############################################################################" .endif diff --git a/net-mgmt/mrtg/files/mrtg_daemon.sh.in b/net-mgmt/mrtg/files/mrtg_daemon.sh.in new file mode 100644 index 000000000000..467b13c7fd19 --- /dev/null +++ b/net-mgmt/mrtg/files/mrtg_daemon.sh.in @@ -0,0 +1,30 @@ +#!/bin/sh +# +# $FreeBSD$ + +# +# PROVIDE: mrtg_daemon +# REQUIRE: DAEMON +# KEYWORD: FreeBSD + +. %%RC_SUBR%% + + +name="mrtg_daemon" +rcvar=`set_rcvar` + +load_rc_config $name + +: ${mrtg_daemon_enable="NO"} +: ${mrtg_daemon_pidfile="/var/run/mrtg/mrtg.pid"} +: ${mrtg_daemon_user="mrtg"} +: ${mrtg_daemon_config="%%PREFIX%%/etc/mrtg/mrtg.cfg"} + +: ${mrtg_daemon_flags="--pid-file $mrtg_daemon_pidfile --lock-file /var/run/mrtg/lockfile --confcache-file /var/run/mrtg/confcache --user $mrtg_daemon_user --group $mrtg_daemon_user --daemon $mrtg_daemon_config"} + +command="%%PREFIX%%/bin/mrtg" +command_interpreter="%%PERL%%" +pidfile=${mrtg_daemon_pidfile} + +run_rc_command "$1" + diff --git a/net-mgmt/mrtg/pkg-install b/net-mgmt/mrtg/pkg-install new file mode 100644 index 000000000000..5aee623c9c0e --- /dev/null +++ b/net-mgmt/mrtg/pkg-install @@ -0,0 +1,49 @@ +#!/bin/sh +# $FreeBSD$ +# + +case "$2" in + +PRE-INSTALL) + USER=mrtg + GROUP=${USER} + UID=279 + GID=${UID} + + if ! pw groupshow "${GROUP}" 2>/dev/null 1>&2; then + if pw groupadd ${GROUP} -g ${GID}; then + echo "Added group \"${GROUP}\"." + else + echo "Adding group \"${GROUP}\" failed..." + exit 1 + fi + fi + + if ! pw usershow "${USER}" 2>/dev/null 1>&2; then + if pw useradd ${USER} -u ${UID} -g ${GROUP} -h - \ + -s "/sbin/nologin" -d "/nonexistent" \ + -c "MRTG daemon"; \ + then + echo "Added user \"${USER}\"." + else + echo "Adding user \"${USER}\" failed..." + exit 1 + fi + fi + ;; + +POST-INSTALL) + rundir=/var/run/mrtg + + if [ ! -d "$rundir" ]; then + mkdir -p $rundir + echo "Created directory: ${rundir}" + fi + + chown -R mrtg:mrtg $rundir + chmod 0700 $rundir + ;; + +esac + +exit 0 diff --git a/net-mgmt/mrtg/pkg-plist b/net-mgmt/mrtg/pkg-plist index ebfb6449cc41..1f4ce619a48b 100644 --- a/net-mgmt/mrtg/pkg-plist +++ b/net-mgmt/mrtg/pkg-plist @@ -80,3 +80,4 @@ etc/mrtg/mrtg.cfg.sample @dirrm etc/mrtg %%PORTDOCS%%@dirrm %%DOCSDIR%% @dirrm %%DATADIR%% +@unexec rmdir /var/run/mrtg -- cgit