Tuesday, March 11, 2014

[SCRIPT] TOMCAT Service Script

#!/bin/bash
# apache-tomcat      
# chkconfig: 

# description:  Start up the Tomcat servlet engine.
# Source function library.

. /etc/init.d/functions

RETVAL=$?
CATALINA_HOME="/usr/local/apache-tomcat-6.0.37"
case "$1" in
start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
   echo $"Starting Tomcat"
           /bin/su -s /bin/bash tomcat $CATALINA_HOME/bin/startup.sh
        fi
;;
 stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
   echo $"Stopping Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
        fi
  ;;
 *)
  echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL


=========================
Based on tomcat uptime

#!/bin/bash
SERVER=`hostname -s | sed s/hostname//g`
TOMCAT_HOME=/usr/local/apache-tomcat
SHUTDOWN_WAIT=20
LOG_FILE=/mnt/esb/test/support/scripts/log/tomcat_restart.log
TIME_STAMP=`date +'%b %e %R '` "$@"

pid=`ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
pdays=`ps -eo pid,comm,etime | grep $pid |  grep -v grep |awk '{print $3}'`
export index=0
index=`expr index "$pdays" '-'`
uptime_days=${pdays:0:$index-1}

echo  "$TIME_STAMP Complete Uptime days of the process `ps -p $pid -o comm=` with pid=$pid is $uptime_days days" >> $LOG_FILE

if [ $uptime_days -ge 28 ]; then

  if [ -n "$pid" ]; then
    echo "$TIME_STAMP- Stoping Tomcat on $SERVER with pid=$pid" >> $LOG_FILE
      $TOMCAT_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
     count=0;
      until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
                 do
                       echo "$TIME_STAMP- waiting for processes with pid=$pid to exit" >> $LOG_FILE
                       sleep 1
                       let count=$count+1;
                  done

         if [ $count -gt $kwait ]; then
                    echo "$TIME_STAMP- killing processes with pid=$pid which didn't stop after $SHUTDOWN_WAIT seconds" >> $LOG_FILE
                    kill -9 $pid
         fi
                  else
     echo "$TIME_STAMP- Tomcat is not running" >> $LOG_FILE
 fi
echo "$TIME_STAMP- Starting Tomcat ..." >> $LOG_FILE
/etc/init.d/tomcat start
fi

[SCRIPT]Shutdown server in 10 minutes

#!/bin/bash

bash -c "nohup /sbin/shutdown -h 30" &
exit 0

ORACLE-XE installation

user@HOST:~$unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
Archive:  oracle-xe-11.2.0-1.0.x86_64.rpm.zip
   creating: Disk1/
   creating: Disk1/upgrade/
  inflating: Disk1/upgrade/gen_inst.sql 
   creating: Disk1/response/
  inflating: Disk1/response/xe.rsp  
  inflating: Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm 
user@HOST:~$ls -l
total 317872
-rw-r--r-- 1 user usersource   7277530 Nov 14 18:32 apache-tomcat-6.0.37.zip
-rw-r--r-- 1 user usersource   2318161 May  7  2013 bcprov-jdk15on-148.jar
drwxrwxr-x 4 user usersource      4096 Aug 29  2011 Disk1
-rw-r--r-- 1 user usersource 315891481 Nov 19 22:05 oracle-xe-11.2.0-1.0.x86_64.rpm.zip
-rw-r--r-- 1 user usersource      7426 May  7  2013 UnlimitedJCEPolicyJDK7.zip
user@HOST:~$cd Disk1/
user@HOST:~/Disk1$ls
oracle-xe-11.2.0-1.0.x86_64.rpm  response  upgrade
user@HOST:~/Disk1$rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
error: Failed dependencies:
    libaio >= 0.3.104 is needed by oracle-xe-11.2.0-1.0.x86_64
user@HOST:~/Disk1$rpm -Uvh oracle-xe-11.2.0-1.0.x86_64.rpm
error: Failed dependencies:
    libaio >= 0.3.104 is needed by oracle-xe-11.2.0-1.0.x86_64

root@HOST Disk1# ls -l
total 309892
-rw-rw-r-- 1 user usersource 317320273 Aug 29  2011 oracle-xe-11.2.0-1.0.x86_64.rpm
drwxr-xr-x 2 user usersource      4096 Aug 29  2011 response
drwxrwxr-x 2 user usersource      4096 Aug 29  2011 upgrade
root@HOST Disk1# rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
error: Failed dependencies:
    libaio >= 0.3.104 is needed by oracle-xe-11.2.0-1.0.x86_64
root@HOST Disk1# ls -l
total 309892
-rw-rw-r-- 1 user usersource 317320273 Aug 29  2011 oracle-xe-11.2.0-1.0.x86_64.rpm
drwxr-xr-x 2 user usersource      4096 Aug 29  2011 response
drwxrwxr-x 2 user usersource      4096 Aug 29  2011 upgrade
root@HOST Disk1# exit
user2@HOST:/home/user/Disk1$exit
user@HOST:~/Disk1$su
Password:
user@HOST:~/Disk1$
user@HOST:~/Disk1$su user2
Password:
user2@HOST:/home/user/Disk1$sudo su
root@HOST Disk1# yum install libaio-0.3.104
Loaded plugins: product-id, rhnplugin, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
rhel-x86_64-server-6                                                                                                    | 1.8 kB     00:00    
Setting up Install Process
No package libaio-0.3.104 available.
Error: Nothing to do
root@HOST Disk1# yum install libaio
Loaded plugins: product-id, rhnplugin, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package libaio.x86_64 0:0.3.107-10.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
 Package                     Arch                        Version                               Repository                                 Size
===============================================================================================================================================
Installing:
 libaio                      x86_64                      0.3.107-10.el6                        rhel-x86_64-server-6                       21 k

Transaction Summary
===============================================================================================================================================
Install       1 Package(s)

Total download size: 21 k
Installed size: 0 
Is this ok [y/N]: y
Downloading Packages:
libaio-0.3.107-10.el6.x86_64.rpm                                                                                        |  21 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : libaio-0.3.107-10.el6.x86_64                                                                                                1/1
  Verifying  : libaio-0.3.107-10.el6.x86_64                                                                                                1/1

Installed:
  libaio.x86_64 0:0.3.107-10.el6                                                                                                              

Complete!
root@HOST Disk1# rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
Preparing...                                                          ########################################### [100%]
   1:oracle-xe                                                        ########################################### [100%]
Executing post-install steps...
You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.

root@HOST Disk1# /etc/init.d/oracle-xe configure

Oracle Database 11g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 11g Express
Edition.  The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts.  Press to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:8081

Specify a port that will be used for the database listener [1521]:

Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of
different passwords for each database account.  This can be done after
initial configuration:
Confirm the password:

Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:

Starting Oracle Net Listener...Done
Configuring database...
Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.
root@HOST Disk1#
root@HOST Disk1# service oracle-xe status

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 19-NOV-2013 22:39:12

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date                19-NOV-2013 22:35:20
Uptime                    0 days 0 hr. 3 min. 52 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           XE
Listener Parameter File   /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/HOST/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=8081))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XE" has 1 instance(s).
  Instance "XE", status READY, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
  Instance "XE", status READY, has 1 handler(s) for this service...
The command completed successfully
root@HOST Disk1# su - oracle
-bash-4.1$ ps -ef | grep xe
oracle   28021     1  0 22:35 ?        00:00:00 /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr LISTENER -inherit
oracle   29031     1  0 22:37 ?        00:00:00 xe_pmon_XE
oracle   29033     1  0 22:37 ?        00:00:00 xe_psp0_XE
oracle   29035     1  0 22:37 ?        00:00:00 xe_vktm_XE
oracle   29039     1  0 22:37 ?        00:00:00 xe_gen0_XE
oracle   29041     1  0 22:37 ?        00:00:00 xe_diag_XE
oracle   29043     1  0 22:37 ?        00:00:00 xe_dbrm_XE
oracle   29045     1  0 22:37 ?        00:00:00 xe_dia0_XE
oracle   29047     1  0 22:37 ?        00:00:00 xe_mman_XE
oracle   29049     1  0 22:37 ?        00:00:00 xe_dbw0_XE
oracle   29051     1  0 22:37 ?        00:00:00 xe_lgwr_XE
oracle   29053     1  0 22:37 ?        00:00:00 xe_ckpt_XE
oracle   29055     1  0 22:37 ?        00:00:00 xe_smon_XE
oracle   29057     1  0 22:37 ?        00:00:00 xe_reco_XE
oracle   29059     1  0 22:37 ?        00:00:00 xe_mmon_XE
oracle   29061     1  0 22:37 ?        00:00:00 xe_mmnl_XE
oracle   29063     1  0 22:37 ?        00:00:00 xe_d000_XE
oracle   29065     1  0 22:37 ?        00:00:00 xe_s000_XE
oracle   29067     1  0 22:37 ?        00:00:00 xe_s001_XE
oracle   29069     1  0 22:37 ?        00:00:00 xe_s002_XE
oracle   29071     1  0 22:37 ?        00:00:00 xe_s003_XE
oracle   29182     1  0 22:37 ?        00:00:00 xe_vkrm_XE
oracle   29184     1  0 22:37 ?        00:00:00 xe_qmnc_XE
oracle   29198     1  0 22:37 ?        00:00:00 xe_cjq0_XE
oracle   29232     1  0 22:37 ?        00:00:00 xe_q000_XE
oracle   29234     1  0 22:37 ?        00:00:00 xe_q001_XE
oracle   29282 29253  0 22:39 pts/1    00:00:00 grep xe
-bash-4.1$ exit
logout

Fuse Installation

1)Before Creating Fabrics for both nodes add the below two jar files in this location /opt/FuseMQEnterprise-7.1.0/lib/ext.

c3p0-0.9.1.2.jar
ojdbc6.jar

2)Create Fabrics in Both ESB and MQ of ESB13 and ESB14 Machines

fabric:create --clean node-01 ESB and MQ
fabric:create --clean node-02 ESB and MQ

3)Join ESB and MQ Containers of node-01 into node-02

fabric:join --zookeeper-password admin HOST1:2181 (in node-02 ESB)
fabric:join --zookeeper-password admin HOST1:2181 (in node-02 MQ)

4)Create Ensemble for the containers

ensemble-add mq-root-node02 rt-root-node02

5)Create Children from any of the Console for both ESB's

container-create-child rt-root-node01 rt-application-node01
container-create-child rt-root-node02 rt-application-node02

6)Create Children from any of the Console for both MQ's

For MQ node01
container-create-child mq-root-node01 mq-broker1-node01
container-create-child mq-root-node01 mq-broker2-node01

For MQ node02
container-create-child mq-root-node02 mq-broker1-node02
container-create-child mq-root-node02 mq-broker2-node02

7)Find Zookeeper URL to add all containers into FMC

config:edit org.fusesource.fabric.zookeeper
config:proplist
example :
        service.pid = org.fusesource.fabric.zookeeper
        zookeeper.password = 3Aibuf25GTGr6Rc4
        zookeeper.url = HOST1:2182,HOST2:2181,HOST2:2182
        fabric.zookeeper.pid = org.fusesource.fabric.zookeeper
       
Add any of the URL's into FMC example 
Host:HOST2
Prot:2181
password:25GTGr6Rc4

You could See all the containers are joined into FMC

8)Stop All MQ children for both nodes from FMC.

stop mq-broker1-node01,mq-broker2-node01,mq-broker1-node02,mq-broker2-node02

9)Modify broker.xml from FMC

goto profiles tab click profile mq-base
goto config-files tab and open broker.xml
add below snippet to broker.xml 
        
 

modify 
below snippet
       
                

to
       
           
       


10)Add Boot Deligation Properties to children of MQ for both nodes

goto location where Fuse-MQ is installed in node1
goto instances you will find mq-broker1-node1,mq-broker2-node1
goto etc folder and open config.properties file
search for string org.osgi.framework.bootdelegation=
and append this string ",oracle.*,com.mchange.*" at the last and save

goto location where Fuse-MQ is installed in node2
goto instances you will find mq-broker1-node2,mq-broker2-node2
goto etc folder and open config.properties file
search for string org.osgi.framework.bootdelegation=
and append this string ",oracle.*,com.mchange.*" at the last and save

11)Create Network connection of brokers from any of karaf console

mq-create --group mq-network-broker1 --networks mq-network-broker2 --assign-container mq-broker1-node01,mq-broker1-node02 mq-broker-01
mq-create --group mq-network-broker2 --networks mq-network-broker1 --assign-container mq-broker2-node01,mq-broker2-node02 mq-broker-02

12)Now Start all the MQ Children from FMC

13)Install All as Services
From FMC
Add Feature wrapper to the profile fuse-esb-full
Add Feature wrapper to the profile mq-broker-01
Add Feature wrapper to the profile mq-broker-02

Node-01

Add profile fuse-esb-full to rt-application-node01
container-connect node rt-application-node01
wrapper:install -s DEMAND_START -n rt-application-node01 -d rt-application-node01 -D rt-application-node01
ln -s /opt/FuseMQEnterprise-7.1.0/instances/rt-application-node01/bin/rt-application-node01-service /etc/init.d/

container-connect node mq-broker1-node01
wrapper:install -s DEMAND_START -n mq-broker1-node01 -d mq-broker1-node01 -D mq-broker1-node01
ln -s /opt/FuseMQEnterprise-7.1.0/instances/mq-broker1-node01/bin/mq-broker1-node01-service /etc/init.d/

container-connect node mq-broker2-node01
wrapper:install -s DEMAND_START -n mq-broker2-node01 -d mq-broker2-node01 -D mq-broker2-node01

Node-02
Add profile fuse-esb-full to rt-application-node02
container-connect node rt-application-node02
wrapper:install -s DEMAND_START -n rt-application-node02 -d rt-application-node02 -D rt-application-node02
ln -s /opt/FuseMQEnterprise-7.1.0/instances/rt-application-node02/bin/rt-application-node02-service /etc/init.d/

container-connect node mq-broker1-node02
wrapper:install -s DEMAND_START -n mq-broker1-node02 -d mq-broker1-node02 -D mq-broker1-node02
ln -s /opt/FuseMQEnterprise-7.1.0/instances/mq-broker1-node02/bin/mq-broker1-node02-service /etc/init.d/

container-connect node mq-broker2-node02
wrapper:install -s DEMAND_START -n mq-broker2-node02 -d mq-broker2-node02 -D mq-broker2-node02
ln -s /opt/FuseMQEnterprise-7.1.0/instances/mq-broker2-node02/bin/mq-broker2-node02-service /etc/init.d/