UNIX command set for stop instances from a common location of a machine
In a development environment that consists of too many UNIX users. Each developers may have one or more WebLogic server instances for their application related System Testing. There is a need of restarting the server frequently. This task can be in two step process:
Identify the weblogic instance process id
Terminating the process
To stop the WebLogic instance they need to identify the process id that is initiated by this user using $LOGNAME.
ps -fu $LOGNAME
Now we need to filter the process list that initiated by Java command.
ps -fu $LOGNAME|grep java
The ppid can be collected into a variable by awk or nawk command line that extract second column.
PID=`more temp2|awk '{print $2}'`
And that PID can be the argument for the 'kill' command for terminate the instance .
Kill command can be given in two ways:
1.Graceful Kill
kill -15 pid
2. Forceful Kill: The terminal signal -9 indicates force stopping the process tree.
kill -9 $PID
Now the server has been stopped by kill command. To ensure that the java process exists in the process list or not.
Finally the completed script would be like this
#!/bin/bash
# This script is used to kill the WebLogic server instance
# Author: PCHN KISHORE
# Dated: 30-09-2010
# Updated : 2/21/2012
PID==`ps -fu $LOGNAME |grep java |grep -v grep|nawk '{print $2}'`
if [ $PID ]
then
kill -9 $PID
echo 'confirming...'
ps -fu $LOGNAME
else
echo "Server is already stopped"
fi
Note: This script will terminate only java processes.
This is a different war game, here is a shell script that makes developers team happy!! In a day there could be multiple times DB changes from one schema to other. Instead of going to WebLogic admin console, you can simply run this script it will automatically changes the required things in the Configuration file which is not really recommended way.
Here the major challenges for building this script are:
Datasources can be simple standalone datasource or multi-datasource.
User might entered wrong DB details
The datasource targeted to
Non-clustered (single instance)
Clustered
WebLogic Database “config.xml” allows only Encrypted password
The second challenge listed user may enter unknowingly wrong DB details then there is no need of changing configuration file. Here is the need of the validation of the given DB details, this can be perormed with WebLogic provided command utility dbping.
WebLogic given another powerful utility for security encryption purpose: weblogic.security.Encrypt
java weblogic.security.Encrypt <passwd>
The result can be stored into a variable for further refered in the script.
The new Database schema details can be replaced with the configuration repository with “sed” command for ex:
grep "jdbc/" /export/home/domains/wd$LOGNAME/config/config.xml|cut -d "/" -f 2-2|cut -d "<" -f 1-1|grep -v "MDS">$DOMAINDIR/dsfilenames
The above command moves all datasouce file names into a file dsfilenames.
MDS means multidatasource name. We need not change MDS file for pointing the datasouce to new database schema we only modify the datasouce files in the folder
$DOMAIN/config/jdbc
cd $DOMAINDIR
for i in $(more dsfilenames)
do
sed "s/<url>.*<\/url>/<url>jdbc:oracle:thin:@$ipport:$schema<\/url>/g" $DOMAINDIR/$i > temp.xml && mv temp.xml $DOMAINDIR/$i
sed "s/<value>.*<\/value>/<value>$username<\/value>/g" $DOMAINDIR/$i > temp.xml && mv temp.xml $DOMAINDIR/$i
sed "s@<password-encrypted>.*<\/password-encrypted>@<password-encrypted>$ENCPASS<\/password-encrypted>@g" $DOMAINDIR/$i > temp.xml && mv temp.xml $DOMAINDIR/$i
done
Regular expressions
This script used lots of regular expressions.
Finally please refer the attached complete script for changing the database schema.