#!/bin/bash
###########################################
# Copyright (C) 2009 Patrick Lafontaine
# Contact: lafontaine.patrick@gmail.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
############################################
# Configuration variables
# environment specific values..
############################################
MW_HOME=/path/to/OracleBI
DOMAIN_HOME=$MW_HOME/user_projects/domains/domain
WL_HOME=$MW_HOME/wlserver_10.3
ORACLE_INSTANCE=$MW_HOME/instances/instance1
weblogicUser='WEBLOGIC'
weblogicPassword='YOUR_PASSWORD'
weblogicManagedServerName='bi_server'
weblogicAdminURL='t3://HOSTNAME:7001'
weblogicScriptPath=$DOMAIN_HOME/bin/
weblogicTimeoutError=240 # maximum time in second before raising an error while starting weblogic
# To kill the node manager, we need the path of its subprocess...
NodeManagerSubProcess=$MW_HOME/Oracle_BI/jdk/bin/java
###########################################
# Build the command lines with parameters for each script
###########################################
# Weblogic
weblogicScriptStart="nohup sh ${weblogicScriptPath}startWebLogic.sh -Dweblogic.management.username=$weblogicUser -Dweblogic.management.password=$weblogicPassword"
weblogicScriptStop=$weblogicScriptPath"stopWebLogic.sh $weblogicUser $weblogicPassword"
# Managed Weblogic
managedWeblogicScriptStart="nohup sh ${weblogicScriptPath}startManagedWebLogic.sh $weblogicManagedServerName $weblogicAdminURL -Dweblogic.management.username=$weblogicUser -Dweblogic.management.password=$weblogicPassword"
managedWeblogicScriptStop=$weblogicScriptPath"stopManagedWebLogic.sh $weblogicManagedServerName $weblogicAdminURL $weblogicUser $weblogicPassword"
#Oracle Instance
OracleInstanceScript=$ORACLE_INSTANCE/bin/opmnctl
OracleInstanceStatus="$OracleInstanceScript status -l"
OracleInstanceScriptStart="$OracleInstanceScript startall"
OracleInstanceScriptStop="$OracleInstanceScript stopall"
# Node Manager
NodeManagerScript=$WL_HOME/server/bin/startNodeManager.sh
NodeManagerScript="nohup sh $NodeManagerScript"
############################################
# Check if servers are already running
############################################
function check_running {
what=$1
ps aux | grep -ir "$what" | grep -v "grep -ir $what" > /dev/null
result=$?
if [ $result != 1 ]
then
echo "It looks like $what is still running! Operation is canceled.."
exit 1
fi
}
################################
# Start the services
################################
function start {
serviceName="$1"
serviceScript="$2"
valuetogrep="$3"
logfile="$4"
echo "Starting $serviceName"
if [ "$serviceName" != "OPMN" ]
then
cat /dev/null > $logfile
eval $serviceScript > $logfile 2>&1 &
tail $logfile | grep "$valuetogrep"
status=$?
elaspedTime=0
while [ $status = 1 ];
do
sleep 1
tail $logfile | grep "$valuetogrep"
status=$?
if [ "$status" != "$valuetogrep" ]
then
echo -n "."
((elapsedTime += 1))
if [ "$elapsedTime" = "$weblogicTimeoutError" ]
then
echo "$serviceName is taking too long to start."
echo " The operation is aborded. Look at $logfile to see if there is any error"
exit 1
fi
fi
done;
else
eval $OracleInstanceScriptStart
fi
echo "$serviceName started."
}
################################
# Stop the services
################################
function stop {
serviceName="$1"
serviceScript="$2"
echo "Stopping $serviceName"
eval $serviceScript
}
case "$1" in
start)
check_running "startWeblogic"
check_running "weblogicmanaged"
check_running "startnodemanager"
check_running "opmnctl"
start "Weblogic" "$weblogicScriptStart" "Server state changed to RUNNING" "/tmp/bistart.log"
start "NodeManager" "$NodeManagerScript" "Secure socket listener started on port" "/tmp/bistart.log"
start "Managed Weblogic" "$managedWeblogicScriptStart" "Server state changed to RUNNING" "/tmp/bistart.log"
start "OPMN" "$OracleInstanceScriptStart"
;;
stop)
stop "OPMN" "$OracleInstanceScriptStop"
stop "Managed Weblogic" "$managedWeblogicScriptStop"
stop "Weblogic" "$weblogicScriptStop"
pkill -TERM -f "$NodeManagerScript"
pkill -TERM -f "$NodeManagerSubProcess"
;;
status)
eval $OracleInstanceStatus
;;
*)
echo "Usage: $(basename $0) start|stop|status"
exit 1
esac
exit 0