1#!/bin/sh 2 3# 4# super_mediator start/control script 5# 6# 7# chkconfig: - 18 96 8# description: Control super_mediator as a live capture daemon 9# 10 11RETVAL=0 12 13MYNAME="super_mediator" 14 15# autoconf stuff 16prefix=@prefix@ 17 18# super_mediator.conf must be located in the SCRIPT_CONFIG_LOCATION directory to work. 19# Edit this line or set the SCRIPT_CONFIG_LOCATION environment variable if 20# super_mediator.conf is not located in the default location. 21if [ "x$SCRIPT_CONFIG_LOCATION" = "x" ] ; then 22 SCRIPT_CONFIG_LOCATION=@sysconfdir@ 23fi 24 25if [ "x$SM_STATEDIR" = "x" ] ; then 26 SM_STATEDIR=@localstatedir@ 27fi 28 29lockfile=/var/lock/subsys/super_mediator 30 31# Determine whether our name has an addendum 32BASENAME='s:\(.*/\)*\([^/]*\)$:\2:' 33SEDEXT1='s/\(.*\)\.init\.d$/\1/' 34SEDEXT2='s/\(.*\)\.sh$/\1/' 35SCRIPTNAME=`echo $0 | sed ${BASENAME} | sed ${SEDEXT1} | sed ${SEDEXT2}` 36PRETEST="\\(${MYNAME}\\)\\(-.*\\)*\$" 37SUFTEST="${MYNAME}\\(-.*\\)\$" 38PREFIX=`expr "x${SCRIPTNAME}" : "x${PRETEST}"` 39SUFFIX=`expr "x${SCRIPTNAME}" : "x${SUFTEST}"` 40 41if [ "x$PREFIX" != "x$MYNAME" ] ; then 42 SUFFIX= 43fi 44 45SCRIPT_CONFIG=${SCRIPT_CONFIG_LOCATION}/${MYNAME}${SUFFIX}.conf 46 47#Check if PIDFILE is defined in the super_mediator.conf 48PIDFILE=$(grep "^PIDFILE" ${SCRIPT_CONFIG} | cut -d " " -f 2- - | sed 's/\"//g') 49 50 51#If PIDFILE is not defined in configuration use default 52if [ "x$PIDFILE" = "x" ]; then 53 if [ -d ${SM_STATEDIR}/run/ ] ; then 54 PIDFILE=${SM_STATEDIR}/run/${MYNAME}.pid 55 elif [ -d /var/run ] ; then 56 PIDFILE=/var/run/${MYNAME}.pid 57 else 58 echo "Error. No directory for PID file" 59 echo "Tried ${SM_STATEDIR}/run and /var/run." 60 echo "Exiting." 61 exit 1 62 fi 63fi 64 65 66 67check_executable() 68{ 69 if [ ! -x $1 ] ; then 70 echo "$0: $1 is not executable or not found." 71 exit 1 72 fi 73} 74 75SMBIN=${prefix}/bin/super_mediator 76 77check_executable ${SMBIN} 78 79# verify we have a good configuration 80 81check_varempty() 82{ 83 if [ "x$2" = "x" ] ; then 84 echo "$0: the $1 parameter in ${SCRIPT_CONFIG} is not set." 85 exit 1 86 fi 87} 88 89# build the argument lists 90 91SMARGS="" 92 93SMARGS="$SMARGS -c ${SCRIPT_CONFIG} --pidfile ${PIDFILE} -d" 94 95checkpid() { 96 kill -0 $1 >/dev/null 2>&1 && return 0 97 return 1 98} 99 100getPid() { 101 if [ -f $PIDFILE ] ; then 102 RETVAL=2 103 read pid < ${PIDFILE} 104 if [ "x$pid" != "x" ] ; then 105 RETVAL=3 106 # Found a pid 107 if checkpid $pid ; then 108 echo $pid 109 RETVAL=0 110 fi 111 fi 112 fi 113 echo "" 114 return $RETVAL 115} 116 117start() { 118 /bin/echo -n "Starting ${MYNAME}: " 119 PID=`getPid` 120 if [ "x${PID}" != "x" ]; then 121 echo "" 122 echo "${MYNAME} is already running. PID: ${PID}" 123 return 1 124 fi 125 $SMBIN $SMARGS 126 RETVAL=$? 127 128 if [ "$RETVAL" -ne "0" ] ; then 129 echo "[Failed]" 130 else 131 sleep 1 132 PID=`getPid` 133 if [ "x$PID" = "x" ] ; then 134 echo "[Failed]" 135 RETVAL=1 136 else 137 touch $lockfile 138 echo '[OK]' 139 fi 140 fi 141 142 return $RETVAL 143} 144 145stop() { 146 PID=`getPid` 147 if [ "x${PID}" = "x" ] ; then 148 echo "${MYNAME} not running" 149 return 1 150 fi 151 /bin/echo -n "Stopping ${MYNAME}: " 152 /bin/kill -s INT $PID 153 sleep 1 154 (checkpid $PID) 155 RETVAL=$? 156 [ "$RETVAL" -eq "1" ] && echo '[OK]' || echo '[Failed]' 157 rm -f $lockfile 158 return $RETVAL 159} 160 161restart() { 162 stop 163 start 164} 165 166reload() { 167 restart 168} 169 170status() { 171 if [ $# -gt 0 ] ; then 172 doEcho=0 173 else 174 doEcho=1 175 fi 176 177 # first check if the process is running 178 PID=`getPid` 179 RETVAL=$? 180 181 if [ $doEcho -eq 1 ] ; then 182 case "$RETVAL" in 183 0) 184 echo "${MYNAME} is running with pid $PID" 185 ;; 186 1) 187 echo "${MYNAME} is stopped" 188 ;; 189 *) 190 echo "${MYNAME} is dead but ${YAF_PIDFILE} exists" 191 ;; 192 esac 193 fi 194 return $RETVAL 195} 196 197# See how we were called. 198case "$1" in 199 start) 200 start 201 RETVAL=$? 202 ;; 203 stop) 204 stop 205 RETVAL=$? 206 ;; 207 reload) 208 reload 209 RETVAL=$? 210 ;; 211 restart) 212 restart 213 RETVAL=$? 214 ;; 215 status) 216 status 217 RETVAL=$? 218 ;; 219 *) 220 echo $"Usage: $0 {start|stop|restart|status}" 221 RETVAL=1 222 ;; 223esac 224exit $RETVAL 225 226## ------------------------------------------------------------------------ 227## super_mediator 228## super_mediator daemon startup script 229## ------------------------------------------------------------------------ 230## Copyright (C) 2012-2013 Carnegie Mellon University. All Rights Reserved. 231## ------------------------------------------------------------------------ 232## Authors: Emily Sarneso, Dwight Beaver 233## ------------------------------------------------------------------------ 234## GNU General Public License (GPL) Rights pursuant to Version 2, June 1991 235## Government Purpose License Rights (GPLR) pursuant to DFARS 252.227-7013 236## ------------------------------------------------------------------------ 237