Hi folk,
Right now, I'm working on a project where I have to do performance tests in J2EE applications with continually stopping and starting the application server.
I created a bash script based on a set of WAS command line for people with short memory, like me ;-)
I want to share the script that we use to facilitate our work.
I hope this helps.
#!/bin/sh
# Launch Websphere Application Server - HTTPServer
# Jorge Iglesias
# Note: Launch with root permission
if [ "$(whoami)" != 'root' ]; then
echo "You have no permission to run $0 as non-root user"
exit 1;
fi
# Define variables
WAS_DMGR=dmgr
WAS_SERVER_NODE=nodeagent
WAS_SERVER=server1
PATH_WAS=/opt/IBM/WebSphere/AppServer
PATH_WAS_DMGR_PROFILE=${PATH_WAS}/profiles/Dmgr01
PATH_WAS_SERVER_PROFILE=${PATH_WAS}/profiles/AppSrv01
LOG_WAS_DMGR=${PATH_WAS_DMGR_PROFILE}/logs/$WAS_DMGR/SystemOut.log
LOG_WAS_SERVER_NODE=${PATH_WAS_SERVER_PROFILE}/logs/$WAS_SERVER_NODE/SystemOut.log
LOG_WAS_SERVER=${PATH_WAS_SERVER_PROFILE}/logs/$WAS_SERVER/SystemOut.log
WAS_USER=wasadmin
WAS_PWD=passw0rd
PATH_HTTPSERVER=/opt/IBM/HTTPServer
# Funciones
OpenLogFile ()
{
# Check params:
# LOG_FILE: log file
# LOG_FILE_TITLE: log file title
proc=$(xlsclients -a | grep SystemOut.log)
if [ -z "${proc}" ]
then
{
TAIL_FILE="tail -f ${LOG_FILE}"
gnome-terminal --title "${LOG_FILE_TITLE}" -e "${TAIL_FILE}" &
}
fi
}
CloseLogFile ()
{
proc=$(xlsclients -a | grep gnome-terminal | grep SystemOut.log)
if [ ! -z "${proc}" ]
then
{
kill -9 `ps -eaf | grep gnome-terminal | grep SystemOut.log | awk '{ print $2 }'`
}
fi
}
InitServer ()
{
# Check params:
# TMP_CMD: command to exec
# TMP_FILE: pid file
echo "Starting server: $TMP_FILE"
# exists PID file?
if [ -f $TMP_FILE ]
then
{
PID=`cat $TMP_FILE`
echo "Server with PID:"$PID
echo "Restart server (y/n)?"
printf "> "
read quest
case $quest in
y)
StartServer;;
Y)
StartServer;;
N)
;;
n)
;;
esac
}
else
{
StartServer
}
fi
}
StartServer()
{
# Start server
# &, run background
# $TMP_CMD &
$TMP_CMD
IS_STARTED=0
while [ $IS_STARTED = 0 ]
do {
# wait one second
sleep 1
if [ -f $TMP_FILE ]
then
{
IS_STARTED=1
}
else
{
IS_STARTED=0
}
fi
}
done
}
StopServer ()
{
# Check params:
# TMP_CMD: command to exec
# TMP_FILE: pid file
echo "Stoping server: $TMP_FILE"
# exists PID file?
if [ -f $TMP_FILE ]
then
{
# Stop server
# &, run background
# $TMP_CMD &
$TMP_CMD
IS_STARTED=0
while [ $IS_STARTED = 0 ]
do {
# wait one second
sleep 1
if [ -f $TMP_FILE ]
then
{
IS_STARTED=0
}
else
{
IS_STARTED=1
}
fi
}
done
}
else
{
echo "Server stopped."
}
fi
}
SetStartDmgrParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_DMGR"
LOG_FILE=$LOG_WAS_DMGR
TMP_CMD=$PATH_WAS_DMGR_PROFILE/bin/startManager.sh
TMP_FILE=$PATH_WAS_DMGR_PROFILE/logs/$WAS_DMGR/$WAS_DMGR.pid
}
SetStartAppSrvNodeParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER_NODE"
LOG_FILE=$LOG_WAS_SERVER_NODE
TMP_CMD=$PATH_WAS_SERVER_PROFILE/bin/startNode.sh
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER_NODE/$WAS_SERVER_NODE.pid
}
SetStartAppSrvParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER"
LOG_FILE=$LOG_WAS_SERVER
TMP_CMD="$PATH_WAS_SERVER_PROFILE/bin/startServer.sh server1"
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER/$WAS_SERVER.pid
}
SetStopDmgrParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_DMGR"
LOG_FILE=$LOG_WAS_DMGR
TMP_CMD="$PATH_WAS_DMGR_PROFILE/bin/stopManager.sh -username $WAS_USER -password $WAS_PWD"
TMP_FILE=$PATH_WAS_DMGR_PROFILE/logs/$WAS_DMGR/$WAS_DMGR.pid
}
SetStopAppSrvNodeParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER_NODE"
LOG_FILE=$LOG_WAS_SERVER_NODE
TMP_CMD="$PATH_WAS_SERVER_PROFILE/bin/stopNode.sh -username $WAS_USER -password $WAS_PWD"
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER_NODE/$WAS_SERVER_NODE.pid
}
SetStopAppSrvParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER"
LOG_FILE=$LOG_WAS_SERVER
TMP_CMD="$PATH_WAS_SERVER_PROFILE/bin/stopServer.sh $WAS_SERVER -username $WAS_USER -password $WAS_PWD"
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER/$WAS_SERVER.pid
}
StartWebserver ()
{
echo "Start HTTPServer"
TMP_CMD="$PATH_HTTPSERVER/bin/apachectl -k start"
$TMP_CMD
}
StopWebserver ()
{
echo "Stop HTTPServer"
TMP_CMD="$PATH_HTTPSERVER/bin/apachectl -k stop"
$TMP_CMD
}
ExitProcess ()
{
# TODO
# Check StopServer
# TODO
# Check CloseLogFile
exit 1;
}
ShowMenu ()
{
# clear
echo ""
echo "-------------------------"
echo "* Process - Launch WAS Menu"
echo "1 - Start dmgr-nodeagent-server1-httpserver"
echo "2 - Start dmgr"
echo "3 - Start nodeagent"
echo "4 - Start server1"
echo "5 - Stop dmgr"
echo "6 - Stop nodeaget"
echo "7 - Stop server1"
echo "8 - Stop httpserver-server1-nodeagent-dmgr"
echo "-------------------------"
echo "10 - Start HTTPServer"
echo "11 - Stop HTTPServer"
echo ""
echo "99 - Exit"
printf "> "
read num
case $num in
1)
SetStartDmgrParams;
OpenLogFile;
InitServer;
SetStartAppSrvNodeParams;
OpenLogFile;
InitServer;
SetStartAppSrvParams;
OpenLogFile;
InitServer;
StartWebserver;;
2)
SetStartDmgrParams;
OpenLogFile;
InitServer;;
3)
SetStartAppSrvNodeParams;
OpenLogFile;
InitServer;;
4)
SetStartAppSrvParams;
OpenLogFile;
InitServer;;
5)
SetStopDmgrParams;
CloseLogFile;
StopServer;;
6)
SetStopAppSrvNodeParams;
CloseLogFile;
StopServer;;
7)
SetStopAppSrvParams;
OpenLogFile;
StopServer;;
8)
StopWebserver;
SetStopAppSrvParams;
CloseLogFile;
StopServer;
SetStopAppSrvNodeParams;
CloseLogFile;
StopServer;
SetStopDmgrParams;
CloseLogFile;
StopServer;;
10)
StartWebserver;;
11)
StopWebserver;;
99)
ExitProcess;;
esac
# back to menu
ShowMenu
}
ShowMenu
# Launch Websphere Application Server - HTTPServer
# Jorge Iglesias
# Note: Launch with root permission
if [ "$(whoami)" != 'root' ]; then
echo "You have no permission to run $0 as non-root user"
exit 1;
fi
# Define variables
WAS_DMGR=dmgr
WAS_SERVER_NODE=nodeagent
WAS_SERVER=server1
PATH_WAS=/opt/IBM/WebSphere/AppServer
PATH_WAS_DMGR_PROFILE=${PATH_WAS}/profiles/Dmgr01
PATH_WAS_SERVER_PROFILE=${PATH_WAS}/profiles/AppSrv01
LOG_WAS_DMGR=${PATH_WAS_DMGR_PROFILE}/logs/$WAS_DMGR/SystemOut.log
LOG_WAS_SERVER_NODE=${PATH_WAS_SERVER_PROFILE}/logs/$WAS_SERVER_NODE/SystemOut.log
LOG_WAS_SERVER=${PATH_WAS_SERVER_PROFILE}/logs/$WAS_SERVER/SystemOut.log
WAS_USER=wasadmin
WAS_PWD=passw0rd
PATH_HTTPSERVER=/opt/IBM/HTTPServer
# Funciones
OpenLogFile ()
{
# Check params:
# LOG_FILE: log file
# LOG_FILE_TITLE: log file title
proc=$(xlsclients -a | grep SystemOut.log)
if [ -z "${proc}" ]
then
{
TAIL_FILE="tail -f ${LOG_FILE}"
gnome-terminal --title "${LOG_FILE_TITLE}" -e "${TAIL_FILE}" &
}
fi
}
CloseLogFile ()
{
proc=$(xlsclients -a | grep gnome-terminal | grep SystemOut.log)
if [ ! -z "${proc}" ]
then
{
kill -9 `ps -eaf | grep gnome-terminal | grep SystemOut.log | awk '{ print $2 }'`
}
fi
}
InitServer ()
{
# Check params:
# TMP_CMD: command to exec
# TMP_FILE: pid file
echo "Starting server: $TMP_FILE"
# exists PID file?
if [ -f $TMP_FILE ]
then
{
PID=`cat $TMP_FILE`
echo "Server with PID:"$PID
echo "Restart server (y/n)?"
printf "> "
read quest
case $quest in
y)
StartServer;;
Y)
StartServer;;
N)
;;
n)
;;
esac
}
else
{
StartServer
}
fi
}
StartServer()
{
# Start server
# &, run background
# $TMP_CMD &
$TMP_CMD
IS_STARTED=0
while [ $IS_STARTED = 0 ]
do {
# wait one second
sleep 1
if [ -f $TMP_FILE ]
then
{
IS_STARTED=1
}
else
{
IS_STARTED=0
}
fi
}
done
}
StopServer ()
{
# Check params:
# TMP_CMD: command to exec
# TMP_FILE: pid file
echo "Stoping server: $TMP_FILE"
# exists PID file?
if [ -f $TMP_FILE ]
then
{
# Stop server
# &, run background
# $TMP_CMD &
$TMP_CMD
IS_STARTED=0
while [ $IS_STARTED = 0 ]
do {
# wait one second
sleep 1
if [ -f $TMP_FILE ]
then
{
IS_STARTED=0
}
else
{
IS_STARTED=1
}
fi
}
done
}
else
{
echo "Server stopped."
}
fi
}
SetStartDmgrParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_DMGR"
LOG_FILE=$LOG_WAS_DMGR
TMP_CMD=$PATH_WAS_DMGR_PROFILE/bin/startManager.sh
TMP_FILE=$PATH_WAS_DMGR_PROFILE/logs/$WAS_DMGR/$WAS_DMGR.pid
}
SetStartAppSrvNodeParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER_NODE"
LOG_FILE=$LOG_WAS_SERVER_NODE
TMP_CMD=$PATH_WAS_SERVER_PROFILE/bin/startNode.sh
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER_NODE/$WAS_SERVER_NODE.pid
}
SetStartAppSrvParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER"
LOG_FILE=$LOG_WAS_SERVER
TMP_CMD="$PATH_WAS_SERVER_PROFILE/bin/startServer.sh server1"
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER/$WAS_SERVER.pid
}
SetStopDmgrParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_DMGR"
LOG_FILE=$LOG_WAS_DMGR
TMP_CMD="$PATH_WAS_DMGR_PROFILE/bin/stopManager.sh -username $WAS_USER -password $WAS_PWD"
TMP_FILE=$PATH_WAS_DMGR_PROFILE/logs/$WAS_DMGR/$WAS_DMGR.pid
}
SetStopAppSrvNodeParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER_NODE"
LOG_FILE=$LOG_WAS_SERVER_NODE
TMP_CMD="$PATH_WAS_SERVER_PROFILE/bin/stopNode.sh -username $WAS_USER -password $WAS_PWD"
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER_NODE/$WAS_SERVER_NODE.pid
}
SetStopAppSrvParams ()
{
LOG_FILE_TITLE="Fichero de trazas: $WAS_SERVER"
LOG_FILE=$LOG_WAS_SERVER
TMP_CMD="$PATH_WAS_SERVER_PROFILE/bin/stopServer.sh $WAS_SERVER -username $WAS_USER -password $WAS_PWD"
TMP_FILE=$PATH_WAS_SERVER_PROFILE/logs/$WAS_SERVER/$WAS_SERVER.pid
}
StartWebserver ()
{
echo "Start HTTPServer"
TMP_CMD="$PATH_HTTPSERVER/bin/apachectl -k start"
$TMP_CMD
}
StopWebserver ()
{
echo "Stop HTTPServer"
TMP_CMD="$PATH_HTTPSERVER/bin/apachectl -k stop"
$TMP_CMD
}
ExitProcess ()
{
# TODO
# Check StopServer
# TODO
# Check CloseLogFile
exit 1;
}
ShowMenu ()
{
# clear
echo ""
echo "-------------------------"
echo "* Process - Launch WAS Menu"
echo "1 - Start dmgr-nodeagent-server1-httpserver"
echo "2 - Start dmgr"
echo "3 - Start nodeagent"
echo "4 - Start server1"
echo "5 - Stop dmgr"
echo "6 - Stop nodeaget"
echo "7 - Stop server1"
echo "8 - Stop httpserver-server1-nodeagent-dmgr"
echo "-------------------------"
echo "10 - Start HTTPServer"
echo "11 - Stop HTTPServer"
echo ""
echo "99 - Exit"
printf "> "
read num
case $num in
1)
SetStartDmgrParams;
OpenLogFile;
InitServer;
SetStartAppSrvNodeParams;
OpenLogFile;
InitServer;
SetStartAppSrvParams;
OpenLogFile;
InitServer;
StartWebserver;;
2)
SetStartDmgrParams;
OpenLogFile;
InitServer;;
3)
SetStartAppSrvNodeParams;
OpenLogFile;
InitServer;;
4)
SetStartAppSrvParams;
OpenLogFile;
InitServer;;
5)
SetStopDmgrParams;
CloseLogFile;
StopServer;;
6)
SetStopAppSrvNodeParams;
CloseLogFile;
StopServer;;
7)
SetStopAppSrvParams;
OpenLogFile;
StopServer;;
8)
StopWebserver;
SetStopAppSrvParams;
CloseLogFile;
StopServer;
SetStopAppSrvNodeParams;
CloseLogFile;
StopServer;
SetStopDmgrParams;
CloseLogFile;
StopServer;;
10)
StartWebserver;;
11)
StopWebserver;;
99)
ExitProcess;;
esac
# back to menu
ShowMenu
}
ShowMenu
No comments:
Post a Comment