19.5.5 Creating a shell script
Create the following shell script files to monitor the processes of the Administration Agent and to start and stop the Administration Agent and logical servers:
- In the (N number of) executing nodes
-
The shell script files that you must set in the executing nodes are described as follows. Note that you must use a common command in the N number of nodes.
-
Shell script file for monitoring the processes of the Administration Agent
-
Shell script file for starting the Administration Agent
-
Shell script file for stopping the Administration Agent and logical servers
-
- In the standby node (One node for recovery)
-
The shell script file that you must set in the standby node is described as follows. Note that you use a common command for the N number of executing nodes and pass the differences with the arguments of the command.
-
Shell script file for executing the recovery process
-
Each script is described as follows:
- Organization of this subsection
(1) Shell script file for monitoring the processes of the Administration Agent
An example of the shell script file for monitoring the processes of the Administration Agent (monitor.sh) is described as follows:
#!/bin/sh
LOGDIR=/home/manager/hamon/log
AA=/opt/Cosminexus/manager/bin/adminagent
logg()
{
echo `date '+[%Y/%m/%d %H:%M:%S]'`"[$$]: $1" \
>> ${LOGDIR}/adminagent.log 2>&1
}
logg "### $0: started. ###"
while true
do
CHECK=`ps -ef | grep $AA | grep -v grep`
if [ "$CHECK" = "" ]
then
logg "### $0: stop. ###"
exit 0
fi
sleep 10
doneIn this example, every 10 seconds, the shell script file monitors whether the processes of the Administration Agent exist.
(2) Shell script file for starting the Administration Agent
An example of the shell script file for starting the Administration Agent (start.sh) is described as follows:
#!/bin/sh
LOGDIR=/home/manager/hamon/log
MNGDIR=/opt/Cosminexus/manager
logg()
{
echo `date '+[%Y/%m/%d %H:%M:%S]'`"[$$]: $1" \
>> ${LOGDIR}/adminagent.log 2>&1
}
# start Administration Agent
logg "### $0: starting Administration Agent. ###"
$MNGDIR/bin/adminagentctl start
if [ $? -eq 0 ] ; then
logg "### $0: Administration Agent start normally. ###"
else
logg "### $0: Administration Agent cannot start. ###"
exit 1
fi
exit 0
(3) Shell script file for stopping the Administration Agent and logical servers
An example of the shell script file for stopping the Administration Agent and logical servers (stop.sh) is described as follows:
#!/bin/sh
LOGDIR=/home/manager/hamon/log
MNGDIR=/opt/Cosminexus/manager
logg()
{
echo `date '+[%Y/%m/%d %H:%M:%S]'`"[$$]: $1" \
>> ${LOGDIR}/adminagent.log 2>&1
}
# stop logical server
logg "### $0: stop logical servers. ###"
$MNGDIR/bin/mngsvrutil -m mnghost:28080 -u admin -p admin \
-t 172.16.12.31 -k host -s stop server
# stop Administration Agent
logg "### $0: stopping Administration Agent. ###"
$MNGDIR/bin/adminagentctl stop
exit 0The settings to be specified in the shell script file are described as follows.
-
Stopping the logical servers
Specify the settings for batch stop of the logical servers running on the same host. Use the mngsvrutil command for batch stop of logical servers.
The user name and password are passed as arguments. Describe these values in the client-machine definition file (.mngsvrutilrc) of the mngsvrutil command, and set appropriate access privileges to manage these values.
Specify the alias IP address in the -t option of the mngsvrutil command.
For the mngsvrutil command, see mngsvrutil (Management Server management command) in the uCosminexus Application Server Command Reference Guide. For the client-machine definition file (.mngsvrutilrc), see 8.2.14 .mngsvrutilrc (Client-side definition file of the mngsvrutil command) in the uCosminexus Application Server Definition Reference Guide.
-
Stopping the Administration Agent
Specify the settings for stopping the Administration Agent. Use adminagentctl stop to stop the Administration Agent.
For the adminagentctl command, see adminagentctl (start or stop Administration Agent) in the uCosminexus Application Server Command Reference Guide.
(4) Shell script file for executing the recovery process
An example of the shell script file for executing the recovery process for each J2EE server (recover.sh) is described as follows:
#!/bin/sh
LOGDIR=/home/manager/hamon/log
PATH=/opt/Cosminexus/CC/server/bin:/bin:/usr/bin:/home/manager/hamon/bin
LD_LIBRARY_PATH=/opt/DABroker/lib:/opt/Cosminexus/jdk/lib:/opt/Cosminexus/TPB/lib:/opt/Cosminexus/PRF/lib:/opt/Cosminexus/CTM/lib:/bin:/opt/HiRDB/client/lib:/opt/oracle/app/oracle/product/10.1.0/client_1/lib:/opt/oracle/app/oracle/product/10.1.0/client_1/lib/libclntsh.so.10.1:/opt/oracle/app/oracle/product/10.1.0/client_1/lib/libclntsh.so
export LD_LIBRARY_PATH
LOCKFILE=/var/lock/kosmi_recover.lock
SLEEP_TIME=60
RETRIES=30
STATUS_PATH=$3/otsstatus
cjlockfile()
{
counter=$2
TMP_LOCK_FILE=`dirname $3`/$$.lock
echo $$ > $TMP_LOCK_FILE
if [ -f $3 ]
then
kill -0 `cat $3` 2>/dev/null || rm -f $3
fi
until ln $TMP_LOCK_FILE $3 2>/dev/null
do
counter=`expr $counter - 1`
if [ $counter -le 0 ]
then
rm -f $TMP_LOCK_FILE
return 1
fi
sleep $1
done
rm -f $TMP_LOCK_FILE
return 0
}
logg()
{
echo `date '+[%Y/%m/%d %H:%M:%S]'`"[$$]: $1" \
>> ${LOGDIR}/adminagent.log 2>&1
}
if cjlockfile ${SLEEP_TIME} ${RETRIES} ${LOCKFILE}
then
logg "### $0: started for $1 ###"
cjstartrecover MyServer -p vbroker.se.iiop_tp.host=$2 \
-p ejbserver.distributedtx.ots.status.directory1=$STATUS_PATH \
-t 600
logg "### $0: ended. $? ###"
fi
rm -f $LOCKFILE
exit 0The settings to be specified in the shell script file are described as follows.
-
The information that is different for each executing node (alias name, alias IP address, and mount directory) and is required for the recovery process is passed with actcommand of the standby node of servers file, as an argument of the command.
-
You must explicitly specify environment variables such as LD_LIBRARY_PATH. For the environment variables, see 4.1.10 Environment variables in the uCosminexus Application Server System Setup and Operation Guide.
-
Use the cjlockfile function to execute the recovery process exclusively. This function provides a semaphore based on file lock. Specify the sleep time (in seconds) in the first argument, retry frequency in the second argument, and the lock file in the third argument. In this function, if the file specified in the third argument is locked, the system retries the acquisition of the file lock after waiting for the time period specified in the first argument. If the file lock cannot be acquired even after retrying for the number of times specified in the second argument, the recovery process fails. If the process for locking the file does not exist, the lock is cancelled.
-
Execute the recovery process for the J2EE server (MyServer) with jstartrecover.
-
In this sample, the timeout period is set to 600 seconds.
-
With the -p option of the cjstartrecover command, specify the status file directory of the executing node that has stopped, in the ejbserver.distributedtx.ots.status.directory1 key.
-
With the -p option of the cjstartrecover command, specify the alias IP address after node switching, in the vbroker.se.iiop_tp.host key.
-
With the -p option of the cjstartrecover command, overwrite a different property in each executing node that has stopped.
-
-
In case of a configuration with multiple J2EE servers, execute the cjstartrecover command only as many times as the number of J2EE servers. In such cases, properly modify the J2EE server name (MyServer) and the path of the OTS status file directory.
For the cjstartrecover command, see cjstartrecover (recover J2EE server transaction) in the uCosminexus Application Server Command Reference Guide. For the ejbserver.distributedtx.ots.status.directory1 and vbroker.se.iiop_tp.host keys, see 2.2.3 usrconf.properties (User property file for J2EE servers) in the uCosminexus Application Server Definition Reference Guide.