#!/bin/sh ####################################################################### # RCSIDENT("$SiLK: flowcap.init.d.in 6855 2007-04-11 16:04:07Z mwd $") ####################################################################### # flowcap start/control script # # /etc/init.d/flowcap # chkconfig: - 20 95 # description: Start flowcap program MYNAME=flowcap # Determine whether our name has an addendum BASENAME='s:\(.*/\)*\([^/]*\)$:\2:' SEDEXT1='s/\(.*\)\.init\.d$/\1/' SEDEXT2='s/\(.*\)\.sh$/\1/' SCRIPTNAME=`echo $0 | sed ${BASENAME} | sed ${SEDEXT1} | sed ${SEDEXT2}` PRETEST="\\(${MYNAME}\\)\\(-.*\\)*\$" SUFTEST="${MYNAME}\\(-.*\\)\$" PREFIX=`expr "x${SCRIPTNAME}" : "x${PRETEST}"` SUFFIX=`expr "x${SCRIPTNAME}" : "x${SUFTEST}"` if [ "x$PREFIX" != "x$MYNAME" ] ; then SUFFIX= fi if [ "x$SCRIPT_CONFIG_LOCATION" = "x" ] ; then prefix= SCRIPT_CONFIG_LOCATION=${prefix}/etc fi SCRIPT_CONFIG=${SCRIPT_CONFIG_LOCATION}/${MYNAME}${SUFFIX}.conf ####################################################################### if [ ! -f "${SCRIPT_CONFIG}" ] ; then echo "$0: ${SCRIPT_CONFIG} does not exist." exit 0 fi . "${SCRIPT_CONFIG}" if [ "x$ENABLED" = "x" ] ; then exit 0 fi check_empty() { if [ "x$2" = "x" ] ; then echo "$0: the \${$1} variable has not been set." exit 1 fi } check_dir() { check_empty "$1" "$2" if [ ! -d "$2" ] ; then if [ "${CREATE_DIRECTORIES}" = "yes" ] ; then mkdir -p "$2" || { echo "$0: Could not create $2" ; exit 1 ; } chown -h "${USER}" "$2" || { echo "$0: Could not chown $2 to ${USER}"; exit 1 ; } else echo "$0: the $2 directory does not exist." exit 1 fi else chown -h "${USER}" "$2" || { echo "$0: Could not chown $2 to ${USER}"; exit 1 ; } fi } RETVAL=0 PROG=flowcap PROG_PATH="${FLOWCAP_BIN}/${PROG}" PIDFILE="${PID_DIR}/${PROG}${SUFFIX}.pid" LOG_BASENAME="${PROG}${SUFFIX}" PROG_OPTIONS="" if [ ! -x "${PROG_PATH}" ] ; then echo "$0: could not find an executable ${PROG_PATH}." exit 1 fi check_empty "SENSOR_CONFIG" "${SENSOR_CONFIG}" check_dir "PID_DIR" "${PID_DIR}" PROG_OPTIONS="${PROG_OPTIONS} --pidfile=${PIDFILE} --sensor-configuration=${SENSOR_CONFIG}" if [ "x${SITE_CONFIG}" != "x" ] ; then PROG_OPTIONS="${PROG_OPTIONS} --site-config-file=${SITE_CONFIG}" fi case "${LOG_TYPE}" in syslog) LOG_EXTRA_OPTIONS="--log-destination=syslog" ;; legacy) check_dir "LOG_DIR" "${LOG_DIR}" LOG_EXTRA_OPTIONS="--log-directory=${LOG_DIR} --log-basename=${LOG_BASENAME}" ;; *) echo "$0: Unexpected LOG_TYPE ${LOG_TYPE}." echo "Set to \"legacy\" or \"syslog\"." exit 1 ;; esac PROG_OPTIONS="${PROG_OPTIONS} --log-level=${LOG_LEVEL} ${LOG_EXTRA_OPTIONS}" check_empty "MAX_FILE_SIZE" "${MAX_FILE_SIZE}" PROG_OPTIONS="${PROG_OPTIONS} --max-file-size=${MAX_FILE_SIZE}" if [ "x${SENSORS}" != "x" ] ; then PROG_OPTIONS="${PROG_OPTIONS} --sensors=${SENSORS}" fi if [ "x${TIMEOUT}" != "x" ] ; then PROG_OPTIONS="${PROG_OPTIONS} --timeout=${TIMEOUT}" fi check_empty "MODE" "${MODE}" case "${MODE}" in local) check_dir "DESTINATION_DIR" "${DESTINATION_DIR}" PROG_OPTIONS="${PROG_OPTIONS} --destination-directory=${DESTINATION_DIR}" if [ "x${FREESPACE_MIN}" != "x" ] ; then PROG_OPTIONS="${PROG_OPTIONS} --freespace-minimum=${FREESPACE_MIN}" fi if [ "x${FULLSPACE_MAX}" != "x" ] ; then PROG_OPTIONS="${PROG_OPTIONS} --space-maximum-percent=${FULLSPACE_MAX}" fi ;; server) check_empty "PORT" "${PORT}" check_dir "DISK_DIR" "${DISK_DIR}" check_empty "DISK_SPACE" "${DISK_SPACE}" PROG_OPTIONS="${PROG_OPTIONS} --fc-port=${PORT} --disk-directory=${DISK_DIR} --disk-space=${DISK_SPACE}" if [ "x${CLIENT_ADDR}" != "x" ] ; then PROG_OPTIONS="${PROG_OPTIONS} --client-address=${CLIENT_ADDR}" fi if [ "x${RAM_SPACE}" != "x" -a "x${RAM_SPACE}" != "x0" ] ; then check_dir "RAM_DIR" "${RAM_DIR}" PROG_OPTIONS="${PROG_OPTIONS} --ram-directory=${RAM_DIR} --ram-space=${RAM_SPACE}" fi ;; *) echo "$0: Unexpected MODE ${MODE}." echo "Set to \"local\" or \"server\"." exit 1 ;; esac # Check if $pid is running checkpid() { kill -0 $1 >/dev/null 2>&1 && return 0 return 1 } # Get the process id from the PIDFILE getPid() { RETVAL=1 if [ -f $PIDFILE ] ; then RETVAL=2 read pid < ${PIDFILE} if [ "X$pid" != "X" ] ; then RETVAL=3 # Found a pid if checkpid $pid ; then echo $pid RETVAL=0 fi fi fi echo "" return $RETVAL } status() { if [ $# -gt 0 ] ; then doEcho=0 else doEcho=1 fi # first check if the process is running pid=`getPid` RETVAL=$? if [ $doEcho -eq 1 ] ; then case "$RETVAL" in 0) echo "${PROG} is running with pid $pid" ;; 1) echo "${PROG} is stopped" ;; *) echo "${PROG} is dead but pid file exists" ;; esac fi return $RETVAL } start() { (status 'silent') pStat=$? if [ $pStat -eq 0 ] ; then status return 0 fi /bin/echo -n "Starting ${PROG}: " /bin/rm -f ${PIDFILE} 2> /dev/null if [ X`whoami` = "X${USER}" ] ; then ${PROG_PATH} $PROG_OPTIONS $EXTRA_OPTIONS & else su - ${USER} -c "${PROG_PATH} $PROG_OPTIONS $EXTRA_OPTIONS &" fi RETVAL=$? if [ "$RETVAL" -ne "0" ] ; then echo "[Failed]" else sleep 1 PID=`getPid` if [ "x$PID" = "x" ] ; then echo "[Failed]" RETVAL=1 else echo '[OK]' fi fi return $RETVAL } stop() { Pid=`getPid` if [ "X${Pid}" = "X" ] ; then echo "${PROG} not running" return 1 fi /bin/echo -n "Stopping ${PROG}: " /bin/kill -s INT $Pid # because rwflowpack waits to reap children, wait before testing echo WARNING sleeping for 10 seconds sleep 10 if checkpid $Pid && sleep 5 \ && checkpid $Pid && sleep 5 \ && checkpid $Pid then /bin/kill -s KILL $Pid sleep 1 fi (checkpid $Pid) RETVAL=$? [ "$RETVAL" -eq "1" ] && echo '[OK]' || echo '[FAILED]' /bin/rm -f ${PIDFILE} 2> /dev/null return $RETVAL } restart(){ (stop) (start) } case "$1" in start) (start) RETVAL=$? ;; stop) (stop) RETVAL=$? ;; restart) (restart) RETVAL=$? ;; status) (status) RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|status|restart}" RETVAL=1 ;; esac exit $RETVAL ####################################################################### # @OPENSOURCE_HEADER_START@ # # Use of the SILK system and related source code is subject to the terms # of the following licenses: # # GNU Public License (GPL) Rights pursuant to Version 2, June 1991 # Government Purpose License Rights (GPLR) pursuant to DFARS 252.225-7013 # # NO WARRANTY # # ANY INFORMATION, MATERIALS, SERVICES, INTELLECTUAL PROPERTY OR OTHER # PROPERTY OR RIGHTS GRANTED OR PROVIDED BY CARNEGIE MELLON UNIVERSITY # PURSUANT TO THIS LICENSE (HEREINAFTER THE "DELIVERABLES") ARE ON AN # "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY # KIND, EITHER EXPRESS OR IMPLIED AS TO ANY MATTER INCLUDING, BUT NOT # LIMITED TO, WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE, # MERCHANTABILITY, INFORMATIONAL CONTENT, NONINFRINGEMENT, OR ERROR-FREE # OPERATION. CARNEGIE MELLON UNIVERSITY SHALL NOT BE LIABLE FOR INDIRECT, # SPECIAL OR CONSEQUENTIAL DAMAGES, SUCH AS LOSS OF PROFITS OR INABILITY # TO USE SAID INTELLECTUAL PROPERTY, UNDER THIS LICENSE, REGARDLESS OF # WHETHER SUCH PARTY WAS AWARE OF THE POSSIBILITY OF SUCH DAMAGES. # LICENSEE AGREES THAT IT WILL NOT MAKE ANY WARRANTY ON BEHALF OF # CARNEGIE MELLON UNIVERSITY, EXPRESS OR IMPLIED, TO ANY PERSON # CONCERNING THE APPLICATION OF OR THE RESULTS TO BE OBTAINED WITH THE # DELIVERABLES UNDER THIS LICENSE. # # Licensee hereby agrees to defend, indemnify, and hold harmless Carnegie # Mellon University, its trustees, officers, employees, and agents from # all claims or demands made against them (and any related losses, # expenses, or attorney's fees) arising out of, or relating to Licensee's # and/or its sub licensees' negligent use or willful misuse of or # negligent conduct or willful misconduct regarding the Software, # facilities, or other rights or assistance granted by Carnegie Mellon # University under this License, including, but not limited to, any # claims of product liability, personal injury, death, damage to # property, or violation of any laws or regulations. # # Carnegie Mellon University Software Engineering Institute authored # documents are sponsored by the U.S. Department of Defense under # Contract F19628-00-C-0003. Carnegie Mellon University retains # copyrights in all material produced under this contract. The U.S. # Government retains a non-exclusive, royalty-free license to publish or # reproduce these documents, or allow others to do so, for U.S. # Government purposes only pursuant to the copyright license under the # contract clause at 252.227.7013. # # @OPENSOURCE_HEADER_END@ #######################################################################