fis-gtm/sr_unix_cm/gtcm_run.gtc

119 lines
3.6 KiB
Bash

#!/bin/sh
#################################################################
# #
# Copyright 2001, 2012 Fidelity Information Services, Inc #
# #
# This source code contains the intellectual property #
# of its copyright holder(s), and is made available #
# under a license. If you do not know the terms of #
# the license, please stop and do not read further. #
# #
#################################################################
# gtcm_run - This script is used to start an invidiaul GTCM server
# Usually this is called from gtmstart script
#
# If the GTCM_RESTART environment variable is set to 1, this script will
# restart the server if some event causes it to stop running.
#
# set maximum number of failures per period in minutes
arch=ARCH
maxfails=5
period=10
server=${GTCM_SERVER-GTMDIST/gtcm_server}
logdir=$gtm_dist/log
cwd=`pwd`
restart=${GTCM_RESTART-0}
echo=ECHO
options=
service=omi
fails=0
if [ $# -lt 1 ]
then
$echo "$0: You must specify command-line options to $server."
exit 1
fi
while [ $# -ne 0 ]
do
case $1 in
-service)
shift
service=$1
logdir=${logdir}/${service}
;;
*)
options="$options $1" ;;
esac
shift
done
# In case, instead of running gtmstart, this script is run directly to start gtcm server,
# $logdir may not be present, so create it
if [ ! -d $logdir ]
then
$echo "GT.M/GT.CM logging directory ($logdir) does not exist, creating it..."
mkdir -p $logdir
fi
oldservcnt=`ps -ea|grep gtcm_server |wc -l`
$echo
t0=`date '+%j %H %M' | awk '{ print $1 * 60 * 24 + $2 * 60 + $3 }'`
while [ $fails -le $maxfails ]
do
$echo "Starting server: \"$server $*\" on `date`."
startstatus=1
$server -service $service $options >> $logdir/gtcm_server.log$fails 2>&1
sleep 1
newservcnt=`ps -ea|grep gtcm_server | wc -l `
if [ $newservcnt -gt $oldservcnt ]
then
startstatus=0
fi
if [ -r $cwd/core ]
then
if `strings $cwd/core | egrep 'image_id=gtcm_server.*-service '$service >/dev/null 2>&1`
then
corename=`date "+core_${service}%m%d%H%M%S"`
$echo "core file in $cwd has been generated by GT.CM"
$echo "core file moved to $logdir/$corename"
mv $cwd/core $logdir/$corename
fi
fi
# abort if we gave no restart option or current try of starting gtcm server is successful
if [ $startstatus -eq 0 ]
then
$echo
$echo "**********************************************************************"
$echo "$0, service $service started on `date`"
$echo "**********************************************************************"
$echo
exit 1
else
if [ $restart -eq 0 ]
then
$echo "**********************************************************************"
$echo " service: $service failed to start"
$echo "**********************************************************************"
$echo "Please look into $gtm_dist/log/gtcm_server.erlg file and syslog messages."
exit 1
fi
fi
echo "(restart is enabled) Retry to start service: $service"
t1=`date '+%j %H %M' | awk '{ print $1 * 60 * 24 + $2 * 60 + $3 }'`
delta=`expr $t1 - $t0`
fails=`expr $fails + 1`
if [ $delta -gt $period -o $delta -lt 0 ]
then
fails=1
t0=$t1
fi
sleep 10
done
$echo "ABORT: more than $maxfails failures in $period minutes."
$echo "Please look into $gtm_dist/log/gtcm_server.erlg file and syslog messages."