WebSphere – Restart enterprise applications usign Jython Script

My jython script : restartApp.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
appName = sys.argv[0]
nodeName = 'w9Node'
serverName = 'WebSphere_Portal'
 
try:
   appMgr = AdminControl.queryNames('type=ApplicationManager,node='+nodeName+',process='+serverName+',*')
   appDetails = AdminControl.completeObjectName('type=Application,name='+appName+',*')
   print ''
 
  if len(appDetails) > 0:
    print '['+appName+'] is started lets stop'
    AdminControl.invoke(appMgr, 'stopApplication', appName)
 
except:
  print("Ignoring error - %s" % sys.exc_info())
 
print 'lets start ['+appName+']'
    AdminControl.invoke(appMgr, 'startApplication', appName)

Restart multiple app using jhyton script invoked by dos script :

1
2
3
4
5
6
7
8
9
10
11
12
@echo off
 
set baseCommand=C:\ibm\portal\AppServer\bin\wsadmin.bat -conntype SOAP -host localhost -port 10033 -user <youruser> -password <yourpassword> -lang jython -f restartApp.py
set cellName=wp9Celldev
 
set appName=app001-ear 
set "MYCOMMAND=%baseCommand% %appName% %cellName%"
call %MYCOMMAND%
 
set appName=app002-ear 
set "MYCOMMAND=%baseCommand% %appName% %cellName%"
call %MYCOMMAND%

step by step to Integrate https with ibm connections

1)  Verify where kdb and sth files are stored :

Was console: security -> SSL certificate and key management -> Key stores and certificates -> CMSKeyStore (verify path)

2) Open plugin xml and verify where store sth and kdb files  then copy from websphere path (1) .

Server Types-> Web servers > webserver1 > Plug-in properties -> Plug-in key store directory and file name
If not present:

-) Configure Ihs using ibm docs then open  Was console: servertypes / webServers / webservername -> plugin options-> copy kdb to plugin folder
-) Set default cert in kdb using ikeyman

3) Configure virtual host to use ssl :


LoadModule ibm_ssl_module modules/mod_ibm_ssl.so

<IfModule mod_ibm_ssl.c>
Listen 0.0.0.0:443

<VirtualHost *:443>
ServerName www.mydomain.com
SSLEnable
</VirtualHost>

</IfModule>

SSLDisable
Keyfile "<path used in plugin>\plugin-key.kdb"
SSLStashFile "<path used in plugin>\plugin-key.sth"


LoadModule was_ap22_module /opt/ibm/Plugins/bin/64bits/mod_was_ap22_http.so
WebSpherePluginConfig /opt/ibm/Plugins/config/webserver1/Plugin-cfg.xml

Start a IHS as daemon

This is my IHS script for Linux

#!/bin/sh
### BEGIN INIT INFO
# Provides: ibm-http
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop IBM HTTP Server
### END INIT INFO
#
# IBM HTTP This init.d script starts the IBM HTTP Server

# Find the name of the script
NAME=`basename $0`
ihs_Path=/opt/ibm/HTTPServer

IBMHTTPCTL="${ihs_Path}/bin/apachectl"

set -e
if [ ! -x ${ihs_Path}/bin/httpd ] ; then
echo "No IBM HTTP Server installed"
exit 0
fi

start() {
echo -n $"Starting ${NAME} service: "
$IBMHTTPCTL -k start; &gt; /dev/null
ret=$?
if [ $ret -eq 0 ]
then
echo "${NAME} Started."
else
echo "${NAME} Starting Failed!"
exit 1
fi
echo
}

stop() {
echo -n $"Stopping ${NAME} service: "
$IBMHTTPCTL -k stop &gt; /dev/null

ret=$?
if [ $ret -eq 0 ]
then
echo "${NAME} Stop Success."
else
echo "${NAME} Stop Failed!"
exit 1
fi
echo
}

graceful() {
echo -n $"graceful ${NAME} service: "
$IBMHTTPCTL -k graceful
ret=$?
if [ $ret -eq 0 ]
then
echo "graceful Success."
else
echo "graceful Failed!"
exit 1
fi
echo
}

restart() {
echo -n $"Restart ${NAME} service: "
$IBMHTTPCTL -k restart
ret=$?
if [ $ret -eq 0 ]
then
echo "restart Success."
else
echo "restart Failed!"
exit 1
fi
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
graceful)
graceful
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|graceful|restart}"
exit 1
esac
exit 0

Start a db2 instance as daemon

Just because I always have problem with db2 autostart I’ve decided to use this simply, fast and flexible script:


#!/bin/sh
### BEGIN INIT INFO
# Provides:          IBM-Db2-db2inst1
# Required-Start:    $local_fs $remote_fs $network $syslog sshd
# Required-Stop:     $local_fs $remote_fs $network $syslog sshd
# Default-Start:     3 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop IBM DB2 instance
### END INIT INFO
#
# IBM Db2 : This init.d script starts the db2inst1 instance

NAME=`basename $0`

instance_User=db2inst1



start() {
    echo -n $"Starting ${NAME} service: "
       $tds_start ; > /dev/null
	   su - $instance_User -c "db2start"  
    ret=$? 
    if [ $ret -eq 0 ]
    then
            echo "${NAME} Started."
    else
            echo "${NAME} Starting Failed!"
            exit 1
    fi
    echo
}

stop() {
    echo -n $"Starting ${NAME} service: "
       $tds_start ; > /dev/null
	   su - $instance_User -c "db2stop"  
    ret=$? 
    if [ $ret -eq 0 ]
    then
            echo "${NAME} Started."
    else
            echo "${NAME} Starting Failed!"
            exit 1
    fi
    echo
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;		
    *)
        echo $"Usage: $0 {start|stop}"
        exit 1
esac
exit 0

Db2 set online logs and enable autodelete for logs and backup

A simple script to set logs for online backup :

 


#!/bin/sh

#First of all create archive logs dir in the home path of the instance owner.
mkdir -p /$HOME/archiveLog

#Change log settings.
db2 UPDATE DB CFG FOR $1 USING logarchmeth1 "DISK:/data/archiveLog" logprimary 15 logsecond 15 logfilsiz 8000

#Backup Db.
db2 BACKUP DATABASE $1 TO "/backup/db2";

#Update log and backup retention (I set to 2).
db2 update db cfg for $1 using rec_his_retentn 2

#Enable auto delete.
db2 update db cfg for $1 using auto_del_rec_obj on

#I setup backup to maintain the last 2 backup.
db2 update db cfg for $1 using num_db_backups 2

You can copy and paste in a script named “setLogs” give grant and run by instance owner:

./setLogs DatabaseName