`#!/bin/sh # $Id: peg.init.host,v 1.12 2009/01/21 21:18:49 anderson Exp $ # # peg This script takes care of starting and stopping # all relevant peg services from a central location # # The list of services to run are controlled by # /usr/local/etc/peg.conf # # chkconfig: 2345 99 10 # description: peg is standard performance metrics gathering tool \ # that reports any arbitrary numeric metrics to a storage service # # probe: true # # Source function library. # # For Solaris machines, this should only be installed on Solaris 5.8 and 5.9 # Solaris 5.10 is handled directly by SMF # 'dnl changequote(,)dnl  CONFIG=/usr/local/etc/peg.conf PEG=/usr/local/sbin/peg  ifelse(HOSTTYPE,SUN5,PIDFILE=/var/run/peg/peg.pid )dnl ifelse(HOSTTYPE,LINUX, # Import standard functions . /etc/rc.d/init.d/functions GREP=grep EGREP=egrep ,HOSTTYPE,SUN5, GREP=/usr/xpg4/bin/grep EGREP=/usr/xpg4/bin/egrep )dnl  # Source in local.defs [ -f /usr/local/lib/distrib/local.defs ] && \ . /usr/local/lib/distrib/local.defs PATH=${PATH}:/usr/local/sbin:/usr/local/bin:/usr/local/libexec dnl ifelse(HOSTTYPE,SUN5, PATH=/usr/xpg4/bin:${PATH} )dnl export PATH ifelse(HOSTOS,LINUX,  # Source networking configuration. [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network )dnl  # Check for the configuration file. If missing do not pass Go! [ -f $CONFIG ] || exit 0 RETVAL=0 prog="peg" user="monitor" # -P100 should be sufficient, if we are running more than # 100 persistent samples then we should increase this number. OPTIONS="-S/bin/ksh -P100" start() { # Start daemons. if pegstatus 1>/dev/null; then return 0; fi dnl ifelse(HOSTTYPE,LINUX,  if status $prog 1>/dev/null; then return 0; fi echo -n $"Starting $prog: " daemon --user $user $PEG RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/peg echo ,HOSTTYPE,SUN5,  # Start daemons mkdir -p /var/run/peg chown monitor:monitor /var/run/peg su - $user -c "$PEG --pidfile $PIDFILE" RETVAL=$? if [ 0 = $RETVAL ] ; then echo -e "\\033[71G[ OK ]"; else echo -e "\\033[71G[ ERROR ]"; fi )dnl  return $RETVAL } stop() { # Stop daemons. echo -n $"Stopping $prog: " dnl ifelse(HOSTTYPE,LINUX,  killproc peg RETVAL=$? echo echo -n $"Stopping remaining $prog processes:" # Kill any remaining $user owned processes su - $user -c "kill -15 -1" su - $user -c "kill -9 -1" echo_success ,HOSTTYPE,SUN5,  # Kill parent process and its children [ -f $PIDFILE ] && su - $user -c "kill `cat $PIDFILE`" RETVAL=$? if [ 0 = $RETVAL ] ; then echo -e "\\033[71G[ OK ]"; else echo -e "\\033[71G[ ERROR ]"; fi echo -n$"Stopping remaining $prog processes:" # Kill any remaining $user owned processes su - $user -c "kill -15 -1" su - $user -c "kill -9 -1" echo -e "\\033[71G[ OK ]"; )dnl ifelse(HOSTTYPE,LINUX,  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/peg )dnl  echo return $RETVAL } pegstatus() { dnl ifelse(HOSTTYPE,LINUX,  rhstatus $prog 2>/dev/null || status $prog 2>/dev/null RETVAL=$? return $RETVAL ,HOSTTYPE,SUN5,  [ -f $PIDFILE ] || RETVAL=1 ps -p `cat $PIDFILE` RETVAL=($? || $RETVAL) if [ 0 = $RETVAL ] ; then echo "$prog is running on `cat $PIDFILE`" else echo "$prog is stopped" fi return $RETVAL )dnl  } restart() { stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) pegstatus ;; restart) restart ;; dnl ifelse(HOSTTYPE,LINUX,  probe) if ! [ -f /var/run/$prog.pid ] ; then echo "restart"; exit 0; fi if ! pgrep -P `cat /var/run/$prog.pid` >/dev/null ; then echo "restart"; exit 0; fi; ;; condrestart) [ -f /var/lock/subsys/$prog ] && restart ;; ,HOSTTYPE,SUN5,  probe) if ps -p `cat /var/run/$prog.pid` >/dev/null ; then echo "restart"; exit 0; fi ;; )dnl *) echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|probe}" exit 1 esac exit $? dnl changequote(`,')dnl