-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_glassfish.sh
34 lines (31 loc) · 1.13 KB
/
check_glassfish.sh
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
#!/bin/sh
NAME=$1
# Make sure we have input
if [ -z $NAME ]; then
echo "UNKNOWN: No instance name given"
exit 3
fi
CACHEFILE=/var/cache/glassfish-list-instances
TEMPCACHEFILE=/var/cache/glassfish-list-instances-temp
CACHEDIRNAME=`dirname $CACHEFILE`
CACHEFILENAME=`basename $CACHEFILE`
if [ `find $CACHEDIRNAME -name $CACHEFILENAME -mmin 0.5 | wc -l` -eq 0 ]; then
# This can take a few seconds, let's use a semaphore to make sure no other process is doing this
if [ ! -f "${CACHEFILE}.lock" ]; then
touch "${CACHEFILE}.lock"
# Run the command to refresh the cache
su glassfish -c '/opt/glassfish-3.1.2.2/glassfish/bin/asadmin --port 8048 list-instances' > $TEMPCACHEFILE
mv -f $TEMPCACHEFILE $CACHEFILE
rm "${CACHEFILE}.lock"
fi
fi
FULLVALUE=`cat $CACHEFILE | grep -e "^${NAME}\b" | awk '{$1=""; print $0}'`
RUNNING=`echo $FULLVALUE | cut -c1-7`
# Do the actual check
if [ "${RUNNING}" = "running" ]; then
echo "OK: ${NAME} is$FULLVALUE"
exit 0
else
echo "CRITICAL: ${NAME} is not running!"
exit 2
fi