From 6524d5c9010aeac2f05633c607bd13f47afad3da Mon Sep 17 00:00:00 2001 From: Paul P Komkoff Jr Date: Sep 14 2007 18:36:16 +0000 Subject: Add user and init scripts --- diff --git a/flow-capture.init b/flow-capture.init new file mode 100644 index 0000000..0931a32 --- /dev/null +++ b/flow-capture.init @@ -0,0 +1,112 @@ +#!/bin/sh +# +# flow-capture Capture traffic flow data +# +# chkconfig: - 90 10 +# description: Capture traffic flow data + +### BEGIN INIT INFO +# Provides: flow-capture +# Required-Start: $local_fs $network +# Required-Stop: $local_fs $network +# Default-Stop: 0 1 2 3 4 5 6 +# Short-Description: Capture traffic flow data +# Description: Capture traffic flow data +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +prog="flow-capture" +exec="/usr/bin/$prog" +config="/etc/sysconfig/$prog" +lockfile=/var/lock/subsys/$prog + +[ -e $config ] && . $config + +# Define the flow-tools username +FLOWTOOLS_USER="${FLOWTOOLS_USER:-flow-tools}" + +# Add pidfile +OPTIONS="-p /var/run/flow-capture.pid $OPTIONS" + +# Check that networking is up. +if [ "$NETWORKING" = "no" ] +then + exit 0 +fi + +start() { + [ -x $exec ] || exit 5 + [ -f $config ] || exit 6 + echo -n $"Starting $prog: " + # if not running, start it up here, usually something like "daemon $exec" + daemon --user=$FLOWTOOLS_USER $exec $OPTIONS + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping $prog: " + killproc $prog + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +reload() { + restart +} + +force_reload() { + restart +} + +rh_status() { + # run checks to determine if the service is running or use generic status + status $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + reload) + rh_status_q || exit 7 + $1 + ;; + force-reload) + force_reload + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}" + exit 2 +esac +exit $? diff --git a/flow-capture.sysconfig b/flow-capture.sysconfig new file mode 100644 index 0000000..33a3d07 --- /dev/null +++ b/flow-capture.sysconfig @@ -0,0 +1,2 @@ +# Change the source IP and port to what is used on your network +OPTIONS="-n 287 -N 0 -w /var/flow-tools -S 5 0/0/8818" diff --git a/flow-tools.spec b/flow-tools.spec index f6c4fa4..9137b60 100644 --- a/flow-tools.spec +++ b/flow-tools.spec @@ -1,15 +1,32 @@ +%bcond_without fedora + +%global uid 40 +%global username flow-tools +%global homedir %{_localstatedir}/%{name} +%global gecos "Network flow monitoring" + Version: 0.68.1 Name: flow-tools Summary: Tool set for working with NetFlow data -Release: 1%{?dist} +Release: 2%{?dist} Group: Applications/System License: BSD URL: http://code.google.com/p/%{name}/ Source0: http://%{name}.googlecode.com/files/%{name}-%{version}.tar.bz2 +Source1: flow-capture.init +Source2: flow-capture.sysconfig Requires: rrdtool-python BuildRequires: openssl-devel mysql-devel postgresql-devel zlib-devel BuildRequires: bison flex tcp_wrappers +BuildRequires: fedora-usermgmt-devel +%{?FE_USERADD_REQ} BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) +Requires(post): initscripts chkconfig +Requires(preun): initscripts chkconfig +Requires(postun): initscripts +Provides: group(%username) = %uid +Provides: user(%username) = %uid + %description Flow-tools is library and a collection of programs used to collect, @@ -56,13 +73,37 @@ rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install find $RPM_BUILD_ROOT -type f -name "*.la" -exec rm -f {} ';' mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/%{name} +install -d $RPM_BUILD_ROOT%{_initrddir} +install -m 0755 %SOURCE1 $RPM_BUILD_ROOT%{_initrddir}/flow-capture +install -d $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig +install -m 0644 %SOURCE2 $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/flow-capture %clean rm -rf $RPM_BUILD_ROOT -%post -p /sbin/ldconfig +%pre +%__fe_groupadd %uid -r %username &>/dev/null || : +%__fe_useradd %uid -r -s /sbin/nologin -d %homedir -M \ + -c '%gecos' -g %username %username &>/dev/null || : + +%post +/sbin/ldconfig +/sbin/chkconfig --add flow-capture -%postun -p /sbin/ldconfig +%preun +if [ $1 = 0 ]; then + /sbin/service flow-capture stop >/dev/null 2>&1 + /sbin/chkconfig --del flow-capture +fi + +%postun +/sbin/ldconfig +if [ "$1" -ge "1" ]; then + /sbin/service flow-capture condrestart >/dev/null 2>&1 || : +fi + +%__fe_userdel %username &>/dev/null || : +%__fe_groupdel %username &>/dev/null || : %files %defattr(-,root,root) @@ -76,7 +117,9 @@ rm -rf $RPM_BUILD_ROOT %dir %{_sysconfdir}/%{name}/sym/ %config(noreplace) %{_sysconfdir}/%{name}/cfg/* %config(noreplace) %{_sysconfdir}/%{name}/sym/* -%{_localstatedir}/%{name}/ +%config(noreplace) %{_sysconfdir}/sysconfig/flow-capture +%{_initrddir}/flow-capture +%attr(-,flow-tools,flow-tools) %{_localstatedir}/%{name}/ %dir %{_datadir}/%{name}/ %{_datadir}/%{name}/* @@ -86,6 +129,9 @@ rm -rf $RPM_BUILD_ROOT %{_includedir}/*.h %changelog +* Thu Sep 13 2007 Orion Poplawski - 0.68.1-2 +- Add user and init scripts + * Sun Aug 5 2007 Paul P Komkoff Jr - 0.68.1-1 - New upstream release