556 lines
13 KiB
Bash
Executable File
556 lines
13 KiB
Bash
Executable File
#!/sbin/sh
|
|
#
|
|
# Start or Stop the Performance Co-Pilot Daemon(s)
|
|
#
|
|
# $Id: etc_init.d_pcp,v 2.69 1999/11/11 06:08:01 nathans Exp $
|
|
#
|
|
|
|
# Some degree of paranoia here ...
|
|
PATH=/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/pcp/bin
|
|
export PATH
|
|
|
|
IS_ON=/sbin/chkconfig
|
|
PMCD=/usr/etc/pmcd
|
|
OLDPMCD=/var/pcp/lib/pmcd
|
|
PMCDWAIT=/usr/pcp/bin/pmcd_wait
|
|
PMPOST=/usr/pcp/bin/pmpost
|
|
PMCDOPTS=/etc/config/pmcd.options
|
|
PMLOGOPTS=/etc/config/pmlogger.options
|
|
PMLOGCTRL=/var/pcp/config/pmlogger/control
|
|
RUNDIR=${PCP_LOGDIR-/var/adm/pcplog}
|
|
DKPROBE=/usr/pcp/bin/dkprobe
|
|
PMLOGGER=/usr/pcp/bin/pmlogger
|
|
PMCHECK=/usr/pcp/bin/cron.pmcheck
|
|
prog=/etc/init.d/`basename $0`
|
|
PCPLOCAL=/var/pcp/etc/local
|
|
MAIL=/usr/sbin/Mail
|
|
|
|
tmp=/var/tmp/$$
|
|
status=1
|
|
trap "rm -f $tmp.* ; exit \$status" 0 1 2 3 15
|
|
|
|
# determine real name for localhost
|
|
#
|
|
LOCALHOSTNAME="localhost"
|
|
[ -x /usr/bsd/hostname ] && LOCALHOSTNAME=`/usr/bsd/hostname`
|
|
LOGDIR=${PCP_LOGDIR-/var/adm/pcplog}/$LOCALHOSTNAME
|
|
|
|
if $IS_ON verbose
|
|
then # For a verbose startup and shutdown
|
|
ECHO=echo
|
|
REBUILDOPT=''
|
|
else # For a quiet startup and shutdown
|
|
ECHO=:
|
|
REBUILDOPT=-s
|
|
fi
|
|
|
|
id=`id | sed -e "s/(.*//" -e "s/.*=//"`
|
|
if [ "$id" != 0 ]
|
|
then
|
|
echo "$prog:"'
|
|
Error: You must be root (uid 0) to start or stop the Performance Co-Pilot PMCD.'
|
|
exit
|
|
fi
|
|
|
|
_pmcd_logfile()
|
|
{
|
|
default=$RUNDIR/pmcd.log
|
|
nawk <$PMCDOPTS '
|
|
BEGIN { logf = "'$default'" }
|
|
$1 == "-l" { if (NF > 1) logf = $2 }
|
|
END { print logf }'
|
|
}
|
|
|
|
_no_libirixpmda()
|
|
{
|
|
logger -p user.alert -t PCP "pmcd: $1 missing"
|
|
echo \
|
|
'Error: Cannot find '"$1"'
|
|
PMCD will start but will not export any IRIX metrics.'
|
|
}
|
|
|
|
_no_lib64_pcp()
|
|
{
|
|
logger -p user.alert -t PCP "pmcd: /usr/lib64/libpcp.so.2 missing"
|
|
echo \
|
|
'Error: Cannot find /usr/lib64/libpcp.so.2 , cannot start PMCD.
|
|
|
|
You should use inst(1)/swmgr(1) to ensure that the pcp_eoe.sw64.lib
|
|
subsystem is installed.'
|
|
exit
|
|
}
|
|
|
|
_reboot_setup()
|
|
{
|
|
# Set up libirixpmda link so that pmcd will find it
|
|
# Only needed for 5.3, but removed for all OSs first as previous
|
|
# releases created it
|
|
#
|
|
rm -f /var/pcp/lib/libirixpmda.so /var/pcp/lib/mips_*.libirixpmda.so
|
|
|
|
# also remove the PCP 1.3 copy of pmcd if it is still around
|
|
#
|
|
[ -f $OLDPMCD ] && rm -f $OLDPMCD
|
|
|
|
irix_version=`/sbin/uname -r`
|
|
irix_obj=`/usr/pcp/bin/pmobjstyle`
|
|
|
|
if [ "$irix_obj" = mips_64 -a ! -f /usr/lib64/libpcp.so.2 ]
|
|
then
|
|
_no_lib64_pcp
|
|
fi
|
|
|
|
case $irix_version
|
|
in
|
|
5.3) if [ ! -f /usr/lib/pcp/libirixpmda.so ]
|
|
then
|
|
_no_libirixpmda /usr/lib/pcp/libirixpmda.so
|
|
echo \
|
|
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
|
|
to ensure that IRIX patch 2825 (or a successor) is installed.
|
|
'
|
|
else
|
|
ln -s /usr/lib/pcp/libirixpmda.so /var/pcp/lib/mips_o32.libirixpmda.so
|
|
fi
|
|
;;
|
|
6.2)
|
|
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
|
|
then
|
|
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
|
|
echo \
|
|
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
|
|
to ensure that IRIX patch 2826 (or a successor) is installed.
|
|
'
|
|
fi
|
|
;;
|
|
6.3)
|
|
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
|
|
then
|
|
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
|
|
echo \
|
|
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
|
|
to ensure that IRIX patch 2827 (or a successor) is installed.
|
|
'
|
|
fi
|
|
;;
|
|
6.4)
|
|
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
|
|
then
|
|
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
|
|
echo \
|
|
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
|
|
to ensure that IRIX patch 2828 (or a successor) is installed.
|
|
'
|
|
fi
|
|
;;
|
|
6.5)
|
|
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
|
|
then
|
|
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
|
|
echo \
|
|
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
|
|
to ensure that the pcp_eoe.sw.eoe subsystem from the IRIX 6.5 CD set
|
|
is installed.
|
|
'
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
# base directories and house-keeping for pmlogger instances
|
|
#
|
|
if [ ! -d /var/tmp/pmlogger ]
|
|
then
|
|
mkdir /var/tmp/pmlogger
|
|
else
|
|
rm -rf $tmp.ent $tmp.pid
|
|
here=`pwd`
|
|
cd /var/tmp/pmlogger
|
|
rm -f primary vcr
|
|
ps -ef | grep pmlogger | grep -v grep | nawk '{ print $2 }' \
|
|
| sed -e 's/[ ]*//g' | sort >$tmp.pid
|
|
ls [0-9]* 2>&1 | sed -e '/\[0-9]\*/d' \
|
|
| sed -e 's/[ ][ ]*//g' | sort >$tmp.ent
|
|
# remove entries without a pmlogger process
|
|
rm -f `comm -23 $tmp.ent $tmp.pid`
|
|
rm -f $tmp.ent $tmp.pid
|
|
cd $here
|
|
fi
|
|
chmod 1777 /var/tmp/pmlogger
|
|
|
|
[ ! -d $LOGDIR ] && mkdir -p $LOGDIR
|
|
|
|
# Rebuild PMNS?
|
|
#
|
|
PMNSDIR=/var/pcp/pmns
|
|
if [ -d $PMNSDIR -a -f $PMNSDIR/.NeedRebuild ]
|
|
then
|
|
if [ -x $PMNSDIR/Rebuild ]
|
|
then
|
|
$ECHO "Performance Co-Pilot rebuilding PMNS ..."
|
|
here=`pwd`
|
|
cd $PMNSDIR
|
|
./Rebuild -du $REBUILDOPT
|
|
[ $? -eq 0 ] && rm -f .NeedRebuild
|
|
cd $here
|
|
fi
|
|
fi
|
|
|
|
# Update /etc/magic?
|
|
#
|
|
MAGICDIR=/var/pcp/config/magic
|
|
if [ -d $MAGICDIR -a -f $MAGICDIR/.NeedUpdate ]
|
|
then
|
|
if [ -x $MAGICDIR/update-magic ]
|
|
then
|
|
$ECHO "Performance Co-Pilot updating /etc/magic entries ..."
|
|
here=`pwd`
|
|
cd $MAGICDIR
|
|
./update-magic
|
|
[ $? -eq 0 ] && rm -f .NeedUpdate
|
|
cd $here
|
|
fi
|
|
fi
|
|
}
|
|
|
|
_pmda_setup()
|
|
{
|
|
# Auto-Install PMDAs?
|
|
#
|
|
PMDADIR=/var/pcp/pmdas
|
|
if [ -d $PMDADIR ]
|
|
then
|
|
here=`pwd`
|
|
cd $PMDADIR
|
|
for file in */.NeedInstall
|
|
do
|
|
[ "$file" = '*/.NeedInstall' ] && break
|
|
pmda=`dirname $file`
|
|
if [ -d "$pmda" -a -f "$pmda/.NeedInstall" ]
|
|
then
|
|
cd $pmda
|
|
$ECHO "Performance Co-Pilot installing $pmda PMDA ..."
|
|
$PMPOST "PMDA setup: automated install: $pmda"
|
|
./Install </dev/null >/dev/null
|
|
rm -f .NeedInstall
|
|
cd $PMDADIR
|
|
fi
|
|
done
|
|
cd $here
|
|
fi
|
|
}
|
|
|
|
_start_pmcheck()
|
|
{
|
|
if [ ! -z "$PMCD_WAIT_TIMEOUT" ]
|
|
then
|
|
wait_option="-t $PMCD_WAIT_TIMEOUT"
|
|
else
|
|
wait_option=''
|
|
fi
|
|
|
|
if $PMCDWAIT $wait_option
|
|
then
|
|
$PMCHECK >$tmp.pmcheck 2>&1
|
|
if [ -s $tmp.pmcheck ]
|
|
then
|
|
$PMPOST "$PMCHECK failed in /etc/init.d/pcp, mailing output to root"
|
|
$MAIL -s "$PMCHECK failed in /etc/init.d/pcp" root <$tmp.pmcheck
|
|
fi
|
|
rm -f $tmp.pmcheck
|
|
else
|
|
status=$?
|
|
$PMPOST "$PMCDWAIT failed in /etc/init.d/pcp: exit status: $status"
|
|
echo "$PMCDWAIT: exit status: $status" | $MAIL -s "$PMCDWAIT failed in $prog" root
|
|
fi
|
|
}
|
|
|
|
_start_pmlogger()
|
|
{
|
|
[ ! -d /var/tmp/pmlogger ] && mkdir /var/tmp/pmlogger
|
|
chmod 1777 /var/tmp/pmlogger
|
|
|
|
if [ -x $PMCHECK ]
|
|
then
|
|
if fgrep -s 'getopts l: c' $PMCHECK
|
|
then
|
|
# this is the PCP 1.3 version that is not reliable ...
|
|
# better to warn and not start the primary logger than
|
|
# die mysteriously trying
|
|
echo "$prog:"'
|
|
Warning: Performance Co-Pilot installation is incomplete (the script
|
|
"'$PMCHECK'" appears to be from an earlier PCP
|
|
distribution) and the PCP archive logger(s) cannot be started.
|
|
You should install the pcp.sw.base subsystem from the PCP 2.0
|
|
(or later) distribution, else
|
|
# /sbin/chkconfig pmlogger off'
|
|
return
|
|
fi
|
|
# $PMCHECK uses /var/pcp/config/pmlogger/control
|
|
# and so can start everything that is needed
|
|
$ECHO "Performance Co-Pilot starting archive loggers ..."
|
|
if [ ! -f $PMLOGCTRL ]
|
|
then
|
|
echo "$prog:"'
|
|
Error: PCP archive logger control file '$PMLOGCTRL'
|
|
is missing! Cannot start any Performance Co-Pilot archive logger(s).'
|
|
return
|
|
fi
|
|
if grep '^LOCALHOSTNAME[ ]*y[ ]' $PMLOGCTRL >/dev/null
|
|
then
|
|
:
|
|
elif grep "^$LOCALHOSTNAME[ ]*y[ ]" $PMLOGCTRL >/dev/null
|
|
then
|
|
:
|
|
else
|
|
echo "$prog"'
|
|
Info: Initializing default PCP archive logger control for the primary
|
|
logger in the file /var/pcp/config/pmlogger/control - see
|
|
cron.pmcheck(1) for details.
|
|
This is a once only initialization after a PCP upgrade.'
|
|
if [ -f $PMLOGOPTS ]
|
|
then
|
|
# only consider lines non-commented lines
|
|
# get rid of -P option
|
|
# ensure multiple lines concat onto 1 line
|
|
options=`sed <$PMLOGOPTS 2>/dev/null \
|
|
-e '/^#/d' \
|
|
-e 's/^/ /' \
|
|
-e 's/$/ /' \
|
|
-e 's/ -P / /g' \
|
|
-e 's/^ //' \
|
|
-e 's/ $//' \
|
|
| tr '\012' ' ' `
|
|
else
|
|
options=''
|
|
fi
|
|
[ -z "$options" ] && options="-c config.default"
|
|
ex - $PMLOGCTRL <<End-of-File
|
|
g/^#LOCALHOSTNAME[ ]*y[ ]/d
|
|
g/^# local primary logger/d
|
|
\$a
|
|
|
|
# local primary logger
|
|
# /etc/init.d/pcp added this default configuration
|
|
# on `date`
|
|
LOCALHOSTNAME y n /var/adm/pcplog/LOCALHOSTNAME $options
|
|
.
|
|
w!
|
|
q
|
|
End-of-File
|
|
fi
|
|
|
|
# filter out the cmd-options, comments and blank lines
|
|
# all the rest should be environment variable settings
|
|
sed -e '/^-/d' -e '/^#/d' -e '/^[ ]*$/d' \
|
|
$PMCDOPTS >$tmp.opts 2>/dev/null
|
|
if [ -s $tmp.opts ]
|
|
then
|
|
# source the variables
|
|
eval `cat $tmp.opts` >$tmp.eval 2>&1
|
|
if [ -s $tmp.eval ]
|
|
then
|
|
$PMPOST "failure in processing $PMCDOPTS in /etc/init.d/pcp: `cat $tmp.eval`"
|
|
fi
|
|
fi
|
|
|
|
_start_pmcheck &
|
|
|
|
return
|
|
else
|
|
echo "$prog:"'
|
|
Warning: Performance Co-Pilot installation is incomplete (at least the
|
|
script "'$PMCHECK'" is missing) and the PCP archive
|
|
logger(s) cannot be started.
|
|
You should install the pcp.sw.base subsystem from the PCP 2.0
|
|
(or later) distribution and consult cron.pmcheck(1), else
|
|
# /sbin/chkconfig pmlogger off'
|
|
fi
|
|
}
|
|
|
|
# Use /etc/pmcd.conf to find and kill pipe/socket PMDAs created by PMCD.
|
|
# (First join up continued lines in config file)
|
|
#
|
|
_killpmdas()
|
|
{
|
|
if [ ! -f /etc/pmcd.conf ]
|
|
then
|
|
echo "$prog:"'
|
|
Warning: PMCD control file "/etc/pmcd.conf" is missing, cannot identify PMDAs
|
|
to be terminated.'
|
|
return
|
|
fi
|
|
for pmda in `nawk </etc/pmcd.conf '
|
|
/\\\\$/ { printf "%s ", substr($0, 0, length($0) - 1); next }
|
|
{ print }' \
|
|
| nawk '
|
|
$1 ~ /^#/ { next }
|
|
tolower($3) == "pipe" && NF > 4 { print $5; next }
|
|
tolower($3) == "socket" && NF > 5 { print $6; next }' \
|
|
| sort -u`
|
|
do
|
|
# Give each PMDA 2 seconds after a SIGTERM to die, then SIGKILL
|
|
killall -k 2 -TERM `basename $pmda` &
|
|
done
|
|
wait
|
|
}
|
|
|
|
_shutdown()
|
|
{
|
|
# Send pmcd a SIGTERM, which is noted as a pending shutdown.
|
|
# When finished the currently active request, pmcd will close any
|
|
# connections and then exit.
|
|
# Wait for pmcd to terminate, make sure any agents pmcd has
|
|
# created are dead.
|
|
#
|
|
killall -TERM pmcd
|
|
$ECHO "Waiting for PMCD to terminate ...\c"
|
|
gone=0
|
|
for i in 1 2 3 4 5 6
|
|
do
|
|
sleep 3
|
|
ps -ef | egrep "($PMCD)|($OLDPMCD)" | grep -v grep >$tmp.tmp 2>&1
|
|
if [ ! -s $tmp.tmp ]
|
|
then
|
|
gone=1
|
|
break
|
|
fi
|
|
|
|
# If they don't go in 15 seconds, SIGKILL and sleep 1 more time
|
|
# to allow any clients reading from PMCD sockets to fail so that
|
|
# socket doesn't end up in TIME_WAIT or somesuch.
|
|
#
|
|
if [ $i = 5 ]
|
|
then
|
|
$ECHO
|
|
echo "Process ..."
|
|
cat $tmp.tmp
|
|
echo "$prog: Warning: Forcing PMCD to terminate!"
|
|
killall -KILL pmcd
|
|
else
|
|
$ECHO ".\c"
|
|
fi
|
|
done
|
|
$ECHO
|
|
_killpmdas
|
|
if [ $gone != 1 ] # It just WON'T DIE, give up.
|
|
then
|
|
echo "Process ..."
|
|
cat $tmp.tmp
|
|
echo "$prog: Warning: PMCD won't die!"
|
|
exit
|
|
fi
|
|
$PMPOST "stop pmcd from /etc/init.d/pcp"
|
|
}
|
|
|
|
case "$1" in
|
|
'start')
|
|
ps -ef | egrep "($PMCD)|($OLDPMCD)" | grep -v grep >$tmp.tmp 2>&1
|
|
[ -s $tmp.tmp ] && _shutdown
|
|
|
|
# PMCD and PMDA messages should go to stderr, not the GUI notifiers
|
|
#
|
|
unset PCP_STDERR
|
|
|
|
_reboot_setup
|
|
|
|
if [ -d /hw/rdisk ]
|
|
then
|
|
# assume this is a system with the hardware graph support,
|
|
# so dkprobe is not required
|
|
:
|
|
else
|
|
# touch all the disks so that libirixpmda sees them
|
|
[ -x $DKPROBE ] && $DKPROBE
|
|
fi
|
|
|
|
if [ -x $PMCD ]
|
|
then
|
|
if $IS_ON pmcd
|
|
then
|
|
if [ ! -f /etc/pmcd.conf ]
|
|
then
|
|
echo "$prog:"'
|
|
Error: PMCD control file "/etc/pmcd.conf" is missing, cannot start PMCD.'
|
|
exit
|
|
fi
|
|
cd $RUNDIR
|
|
|
|
# salvage the previous versions of any PMCD and PMDA logfiles
|
|
#
|
|
for log in pmcd `sed -e '/^#/d' -e '/\[access\]/q' -e 's/[ ].*//' </etc/pmcd.conf`
|
|
do
|
|
if [ -f $log.log ]
|
|
then
|
|
rm -f $log.log.prev
|
|
mv $log.log $log.log.prev
|
|
fi
|
|
done
|
|
|
|
$ECHO "Performance Co-Pilot starting PMCD (logfile is `_pmcd_logfile`) ..."
|
|
|
|
|
|
# only consider lines which start with a hyphen
|
|
# get rid of the -f option
|
|
# ensure multiple lines concat onto 1 line
|
|
OPTS=`sed <$PMCDOPTS 2>/dev/null \
|
|
-e '/^[^-]/d' \
|
|
-e 's/^/ /' \
|
|
-e 's/$/ /' \
|
|
-e 's/ -f / /g' \
|
|
-e 's/^ //' \
|
|
-e 's/ $//' \
|
|
| tr '\012' ' ' `
|
|
|
|
if [ `uname -r | tr -c '.\012[0-9]' ' ' | sed -e 's/ .*//' | nawk -F. '{ print $1*100+$2 }'` -ge 605 ]
|
|
then
|
|
# IRIX6.5 or later
|
|
/sbin/suattr -C CAP_SETGID+ip -c "$PMCD $OPTS"
|
|
else
|
|
$PMCD $OPTS
|
|
fi
|
|
|
|
$PMPOST "start pmcd from /etc/init.d/pcp"
|
|
|
|
_pmda_setup
|
|
|
|
if [ -x $PMLOGGER ]
|
|
then
|
|
if $IS_ON pmlogger
|
|
then
|
|
_start_pmlogger
|
|
else
|
|
# forced removal of primary symlink
|
|
rm -f /var/tmp/pmlogger/primary
|
|
fi
|
|
fi
|
|
|
|
# site-local customisations after PCP startup
|
|
#
|
|
[ -x $PCPLOCAL ] && $PCPLOCAL start
|
|
|
|
else
|
|
if [ "$0" = "/etc/init.d/pcp" ]
|
|
then
|
|
echo "$prog:"'
|
|
Warning: Performance Co-Pilot collector (PMCD) is disabled. To enable:
|
|
# /sbin/chkconfig pmcd on'
|
|
fi
|
|
fi
|
|
fi
|
|
status=0
|
|
;;
|
|
|
|
'stop')
|
|
# site-local customisations before PCP shutdown
|
|
#
|
|
[ -x $PCPLOCAL ] && $PCPLOCAL stop
|
|
_shutdown
|
|
status=0
|
|
;;
|
|
|
|
*)
|
|
echo "Usage: /etc/init.d/pcp {start|stop}"
|
|
;;
|
|
esac
|
|
|