1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
| #!/usr/bin/env bash
#
# zenoss This shell script takes care of starting and stopping zenmon.
#
# chkconfig: 2345 80 30
# description: Zenoss is a monitoring program written by Zenoss, Inc.
#
#############################################################################
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2007, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#############################################################################
# Attempt to set ZENHOME if it is not already set, or bogus
# by calculating it relative to the executing command
if [ -z "$ZENHOME" -o ! -d "$ZENHOME" ] ; then
# Resolve links: $0 may be a link to zenoss's home.
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/.."
ZENHOME="`pwd -P`"
export ZENHOME
cd "$SAVED"
fi
if [ `id -u` -eq 0 ] ; then
USERNAME=`ls -l $ZENHOME/var/Data.fs | awk '{ print $3 }'`
if [ "$USERNAME" = "root" -o -z "$USERNAME" ] ; then
echo Unable to determine the right user to run zenoss
exit 1
fi
chown -R $USERNAME $ZENHOME/var
chown -R $USERNAME $ZENHOME/log
exec su - $USERNAME $0 $@
fi
DAEMON_FILTER="*"
ONLY_RUNNING=0
while getopts "f:r" opt; do
case $opt in
f)
# apply action to daemons matched by filter
DAEMON_FILTER="$OPTARG"
;;
r)
# apply action to only running daemons
ONLY_RUNNING=1
;;
\?)
echo "Invalid option -$OPTARG" >&2
exit 1
;;
esac
shift `expr $OPTIND - 1`
done
. $ZENHOME/bin/zenfunctions
WEBSERVERCTL=$(${ZENHOME}/bin/zenglobalconf -p webserverctl)
if [ -z "${WEBSERVERCTL}" ]; then
WEBSERVERCTL=zopectl
fi
CATSERVICE=${ZENHOME}/bin/zencatalogservice
C=
if [ ! -f $ZENHOME/etc/DAEMONS_TXT_ONLY ] ; then
if [ -f $CATSERVICE ] ; then
C="$C zencatalogservice"
fi
C="$C zeneventserver"
C="$C ${WEBSERVERCTL}"
C="$C zenhub"
C="$C zenjobs"
C="$C zeneventd"
C="$C zenping"
C="$C zensyslog"
C="$C zenstatus"
C="$C zenactiond"
C="$C zentrap"
C="$C zenmodeler"
#C="$C zenrender"
C="$C zenperfsnmp"
C="$C zencommand"
C="$C zenprocess"
C="$C zenrrdcached"
#C="$C zenmail"
ZPD=`$ZENHOME/bin/zenpackdaemons --list`
C="$C $ZPD"
fi
if [ -f "$ZENHOME/etc/daemons.txt" ]
then
D=`cat $ZENHOME/etc/daemons.txt`
# add to daemon list without new lines
for DD in $D
do
C="$C $DD"
done
fi
reverse() {
args=
for i
do
args="$i $args"
shift
done
echo $args
}
# are we interested in only running daemons?
if [ $ONLY_RUNNING = "1" ]; then
C=`zenoss status | grep "pid=" | awk '{ print $2 }'`
fi
#filter the daemons
DLIST=""
for DAEMON in ${C}
do
if echo $DAEMON | grep -E "$DAEMON_FILTER" 1>/dev/null; then
DLIST="$DLIST $DAEMON"
fi
done
C="$DLIST"
CMDS=$C
FUNC=$CMD
issue() {
# To properly conform to LSB standards and be used under Linux-HA or RHCS
# we need to exit with a proper non-zero code when there is a problem with
# the service. We'll take the naive approach of responding with the highest
# and most likely worse condition of any of the configured daemons.
HIGHESTCODE=0
for cmd in $CMDS
do
echo -n "Daemon: $cmd "
# Special status handling for zeoctl and zopectl because the stock
# scripts exit with a code of 0 no matter what state they're in.
if [ $FUNC == "status" -a \( $cmd == "zeoctl" -o $cmd == "zopectl" \) ]
then
PIDFILE="${ZENHOME}/var/Z2.pid"
[ $cmd == 'zeoctl' ] && PIDFILE="${ZENHOME}/var/ZEO.pid"
if running; then
echo program running\; pid=$PID
CODE=0
else
echo not running
if [ -f $PIDFILE ]; then
rm -f $PIDFILE
CODE=1
else
CODE=3
fi
fi
else
$ZENHOME/bin/$cmd "$FUNC"
CODE=$?
fi
if [ $CODE -gt $HIGHESTCODE ]; then
HIGHESTCODE=$CODE
fi
done
return $HIGHESTCODE
}
xissue() {
# To properly conform to LSB standards and be used under Linux-HA or RHCS
# we need to exit with a proper non-zero code when there is a problem with
# the service. We'll take the naive approach of responding with the highest
# and most likely worse condition of any of the configured daemons.
HIGHESTCODE=0
XFUNC=$FUNC
if [ $FUNC == "xstatus" ]; then
XFUNC="status"
fi
echo "Status | PID | Daemon "
echo "-------------------------------------------------------------------"
for cmd in $CMDS
do
# Special status handling for zeoctl and zopectl because the stock
# scripts exit with a code of 0 no matter what state they're in.
if [ $XFUNC == "xstatus" -a \( $cmd == "zeoctl" -o $cmd == "zopectl" \) ]
then
PIDFILE="${ZENHOME}/var/Z2.pid"
[ $cmd == 'zeoctl' ] && PIDFILE="${ZENHOME}/var/ZEO.pid"
if running; then
printf "Running %8d $cmd\n" $PID
CODE=0
else
echo "Stopped $cmd"
if [ -f $PIDFILE ]; then
rm -f $PIDFILE
CODE=1
else
CODE=3
fi
fi
else
CMD_OUTPUT=`$ZENHOME/bin/$cmd $XFUNC`
CODE=$?
CMD_PID=`echo "${CMD_OUTPUT}" | grep pid | awk -F\= '{ print $2 }'`
if [ $CMD_PID ]
then
printf "Running %8d $cmd\n" $CMD_PID
else
echo "Stopped $cmd"
fi
fi
if [ $CODE -gt $HIGHESTCODE ]; then
HIGHESTCODE=$CODE
fi
done
return $HIGHESTCODE
}
EXITCODE=4
case "$FUNC" in
start)
issue
EXITCODE=$?
;;
stop)
CMDS=`reverse $CMDS`
issue
EXITCODE=$?
rm -f $ZENHOME/var/.*watchdog-*
;;
restart)
CMDS=`reverse $CMDS`
FUNC=stop
issue
CMDS=`reverse $CMDS`
FUNC=start
issue
EXITCODE=$?
;;
status)
issue
EXITCODE=$?
;;
xstatus)
xissue
EXITCODE=$?
;;
list)
for i in $CMDS
do
echo $i
EXITCODE=0
done
;;
*)
echo $"Usage: $0 {start|stop|restart|status|xstatus|list}"
exit 1
esac
exit $EXITCODE |
Partager