Monday, April 29, 2013

Script for Start, Stop, Status and Restart of Tomcat Server



Below script can be used for stop, start, restart and status checking. Change installed path according to environment.


#!/bin/ksh

export BASE=/home/programs/Servers/jakarta-tomcat-6.0.36/bin
prog=jakarta-tomcat-6.0.36

stat() {
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
echo Tomcat is currently running.
else
echo Tomcat is currently not running.
fi
}

case "$1" in
start)

if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
echo Tomcat seems to be running. Use the restart option.
else
$BASE/startup.sh 2>&1 > /dev/null
fi
stat
;;
stop)
$BASE/shutdown.sh 2>&1 > /dev/null
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
for pid in `ps auxwww|grep $prog|grep -v grep|tr -s ' '|cut -d ' ' -f2`
do
kill -9 $pid 2>&1 > /dev/null
done
fi
stat
;;
restart)

if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
for pid in `ps auxwww|grep $prog|grep -v grep|tr -s ' '|cut -d ' ' -f2`
do
kill -9 $pid 2>&1 > /dev/null
done
fi
$BASE/startup.sh 2>&1 > /dev/null
stat
;;
status)
stat
;;
*)
echo "Usage: tomcat start|stop|restart|status"
esac



Thanks,
Babu

Wednesday, April 10, 2013

Unix Basic Commands



 
Access Control
  • ·         exit - terminate a shell (see "man sh" or "man csh")
  • ·         logout - sign off; end session (C shell and bash shell only;)
  • ·         passwd - change login password
  • ·         rlogin - log in remotely to another UNIX system
  • ·         ssh - secure shell
  • ·         slogin - secure version of rlogin 
  • ·         yppasswd - change login password in yellow pages

Communications
  • ·         mail - send and receive mail
  • ·         mesg - permit or deny terminal messages and talk requests
  • ·         pine - send and receive mail
  • ·         talk - talk to another logged-in user
  • ·         write - write to another logged-in user

Programming Tools
  • ·         as - assembler, specific to each machine architecture
  • ·         awk - pattern scanning and processing language
  • ·         bc - online calculator
  • ·         cc - C compiler
  • ·         csh - C shell command interpreter
  • ·         dbx - source-level debugging program
  • ·         f77 - Fortran compiler
  • ·         gdb - GNU Project debugger
  • ·         gprof - display profile of called routines
  • ·         kill - kill a process
  • ·         ld - the UNIX loader
  • ·         lex - generate lexical analysis programs
  • ·         lint - check C source code
  • ·         make - maintain large programs
  • ·         maple - symbolic mathematics program
  • ·         math - symbolic mathematics program
  • ·         nice - run a command at low priority (see "man nice" or "man csh")
  • ·         nohup - run a command immune to hangups
  • ·         pc - Pascal compiler (xlp on ADS)
  • ·         perl - Popular script interpreter
  • ·         prof - display profile data
  • ·         python - Python programming language
  • ·         sh - Bourne shell command interpreter
  • ·         yacc - generate input parsing programs
  • ·         xcalc - graphical calulator under x

Documentation
  • ·         apropos - locate commands by keyword lookup
  • ·         find - locate file (i.e. find . -name *.tex -print)
  • ·         info - start the info explorer program
  • ·         man - find manual information about commands
  • ·         whatis - describe what a command is
  • ·         whereis - locate source, binary, or man page for a program
  • Editors

  • ·         emacs - screen-oriented text editor
  • ·         pico - screen-oriented text editor (renamed called nano)
  • ·         sed - stream-oriented text editor
  • ·         vi - full-screen text editor
  • ·         vim - full-screen text editor ("vi-improved")

File and Directory Management
·        
  •             cd - change working directory
  • ·         chmod - change the protection of a file or directory
  • ·         chown - change owner (or group) of a file or directory
  • ·         chgrp - change group of a file or directory
  • ·         cmp - compare two files
  • ·         comm - select/reject lines common to two sorted files
  • ·         cp - copy files
  • ·         crypt - encrypt/decrypt files (CCWF only)
  • ·         diff - compare the contents of two ASCII files
  • ·         file - determine file type
  • ·         grep - search a file for a pattern
  • ·         gzip - compress or expand files
  • ·         ln - make a link to a file
  • ·         ls - list the contents of a directory
  • ·         lsof - list of open files   
  • ·         mkdir - create a directory
  • ·         mv - move or rename files and directories
  • ·         pwd - show the full pathname of your working directory
  • ·         quota - display disk usage and limits
  • ·         rm - delete (remove) files
  • ·         rmdir - delete (remove) directories
  • ·         stat - status of file (i.e. last access)
  • ·         sync - flush filesystem buffers  
  • ·         sort - sort or merge files
  • ·         tar - create or extract archives
  • ·         tee - copy input to standard output and other files
  • ·         tr - translate characters
  • ·         umask - change default file protections
  • ·         uncompress - restore compressed file
  • ·         uniq - report (or delete) repeated lines in a file
  • ·         wc - count lines, words, and characters in a file

File Display and Printing
  • ·         cat - show the contents of a file; catenate files
  • ·         fold - fold long lines to fit output device
  • ·         head - show first few lines of a file
  • ·         lpq - examine the printer spooling queue
  • ·         lpr - print a file
  • ·         lprm - remove jobs from the printer spooling queue
  • ·         more - display a file, one screen at a time
  • ·         less - like more with more features
  • ·         page - like "more", but prints screens top to bottom
  • ·         pr - paginate a file for printing
  • ·         tail - show the last part of a file
  • ·         zcat - display a compressed file
  • ·         xv - show print, manipulate images
  • ·         gv - show ps and pdf files
  • ·         xpdf = shopw pdf files (use gv)

File Transfer
  • ·         ftp - transfer files between network hosts
  • ·         rsync -  fast and flexible sync between computers
  • ·         scp - secure version of rcp

Miscellaneous
  • ·         alias - define synonym commands
  • ·         chquota - change disk quota on ACITS UNIX systems
  • ·         chsh - change default login shell
  • ·         clear - clear terminal screen
  • ·         echo - echo arguments
  • ·         pbm - portable bitmap manipulation programs
  • ·         popd - pop the directory stack (C shell only)
  • ·         pushd - push directory on stack (C shell only)
  • ·         script - make typescript of terminal session
  • ·         setenv - set an environment variable (C shell only)
  • ·         stty - set terminal options

Networks
  • ·         netstat - show network status
  • ·         rsh - run shell or command on another UNIX system
  • ·         ssh - secure-shell version of rsh

Process Control
  • ·         bg - put suspended process into background
  • ·         fg - bring process into foreground
  • ·         jobs - list processes
  • ·         ^y - suspend process at next input request
  • ·         ^z - suspend current process

Status Information
  • ·         clock - determine processor time
  • ·         date - show date and time
  • ·         df - summarize free disk space
  • ·         du - summarize disk space used
  • ·         env - display environment
  • ·         finger - look up user information
  • ·         history - list previously issued commands
  • ·         last - indicate last login of users
  • ·         lpq - examine spool queue
  • ·         manpath - show search path for man pages
  • ·         printenv - print out environment
  • ·         ps - show process status
  • ·         pwd - print full pathname of working directory
  • ·         set - set shell variables (C shell, bash, or ksh)
  • ·         spend - lists year-to-date ACITS UNIX charges
  • ·         stty - set terminal options
  • ·         time - timing programs
  • ·         top - list  top  cpu processes
  • ·         uptime - show system load, how long system has been up
  • ·         w - show who is on system, what command each job is executing
  • ·         who - show who is logged onto the system
  • ·         whois - Internet user name directory service
  • ·         whoami - who owns the shell



Thanks,
Babu


Weblogic Monitoring Tool - InfraRED ( Open Source Tool )



What is  InfraRED Tool:

InfraRED provides statistics about various aspects of an application’s performance (Method timing, JDBC & SQL statistics, HTTP Response). It provides an end-to-end view to help in correlating all these metrics that are collected at different layers of the application. For example, you can use JBDC logging, p6spy or even Hibernate SQL logging to look at what SQL queries are executed, but InfraRED can give you a lot more information about those SQL queries and can also correlate these queries to the APIs in your application from which they were executed

InfraRED is free and open-source and easily you can integrate with your environment.

How to Install and Integrate with Application:

Following are the 3 basic steps to prepare the application for monitoring,

1.        Integration of InfraRED with the application.
2.        Addition of classpaths, configuration of datasource etc.
3.        Deployment of application and infrared.war and accessing InfraRED site.

Step 1:
Note: Ant Version 1.5 or higher needs to be used.

Download the latest release of InfraRED and unzip it in a folder. This folder will henceforth be called infrared.home. Depending upon the application server / Web Server used and the format of distribution i.e. Ear/War, choose the set of targets from Table 1. Insert these targets in your build-script to integrate InfraRED with your application. (These xml snippets are also available in the file build-snippet.txt under scripts folder in the release zip).
Integration of InfraRED with the application is composed of following steps.
  • Instrumentation of application (Insertion of byte code to collect performance data).
  • Addition of relevant InfraRED jars in the appropriate location in the application.
  • Insertion of appropriate servlet filters, application life cycle listener and listener servlet in the application.
  • Addition of infrared properties file in the appropriate location.
Table 1
Weblogic SP3 (Ear)
<taskdef name="integrate" classname="net.sf.infrared.antTask.Integrate">
        <classpath>
            <pathelement location="${infrared.home}/infrared-antTask.jar"/>
            <pathelement location="${infrared.home}/dependency-jars/aspectjtools-1.2.jar"/>
        </classpath>
</taskdef>
<target name="integrateInfraRED">
     <integrate earFile="${Application.ear}" destEarFile = "${Instrumented.app.ear}"
                        infraredHome="${infrared.home}"    centralCollection="false" >
        <classpath>
             <pathelement location="${weblogic.jar.path}"/>
             <!-- path of dependency classes/jars -->
        </classpath>
    </integrate>
</target>
Weblogic SP3 (War)
<taskdef name="integrate" classname="net.sf.infrared.antTask.Integrate">
        <classpath>
            <pathelement location="${infrared.home}/infrared-antTask.jar"/>
            <pathelement location="${infrared.home}/dependency-jars/aspectjtools-1.2.jar"/>
        </classpath>
</taskdef>
<target name="integrateInfraRED">
    <integrate webWar="${Application.war}" destWebWar="${Instrumented.app.war}" infraredHome="${infrared.home}">
      <classpath>
         <pathelement location="${weblogic.jar.path}"/>
         <!--path of dependency classes/jars -->
      </classpath>
    </integrate>
</target>
JBoss (Ear)
<taskdef name="integrate" classname="net.sf.infrared.antTask.Integrate">
        <classpath>
            <pathelement location="${infrared.home}/infrared-antTask.jar"/>
            <pathelement location="${infrared.home}/dependency- jars/aspectjtools-1.2.jar"/>
        </classpath>
</taskdef>
<target name="integrateInfraRED">
    <integrate earFile="${Application.ear}" destEarFile = "${Instrumented.app.ear}" infraredHome="${infrared.home}"
               centralCollection="true|false" appserver="jboss" applicationName="${app-name}" portNumber="${port-number}">
        <classpath>
         <pathelement location="${javax.servlet.jar}"/>
         <pathelement location="${jboss.j2ee.jar}"/>
                <!--path of dependency classes/jars -->
        </classpath>
    </integrate>
</target>
JBoss (War)
<taskdef name="integrate" classname="net.sf.infrared.antTask.Integrate">
        <classpath>
            <pathelement location="${infrared.home}/infrared-antTask.jar"/>
            <pathelement location="${infrared.home}/dependency-jars/aspectjtools-1.2.jar"/>
        </classpath>
</taskdef>
<target name="integrateInfraRED">
    <integrate webWar="${Application.war}" destWebWar="${Instrumented.app.war}"
            infraredHome="${infrared.home}" appserver="jboss" portNumber="${port-number}">
        <classpath>
         <pathelement location="${javax.servlet.jar}"/>
         <pathelement location="${jboss.j2ee.jar}"/>
            <!--path of dependency classes/jars -->
        </classpath>
    </integrate>
</target>
Tomcat (War)
<taskdef name="integrate" classname="net.sf.infrared.antTask.Integrate">
        <classpath>
            <pathelement location="${infrared.home}/infrared-antTask.jar"/>
            <pathelement location="${infrared.home}/dependency-jars/aspectjtools-1.2.jar"/>
        </classpath>
</taskdef>
<target name="integrateInfraRED">
    <integrate webWar="${Application.war}" destWebWar="${Instrumented.app.war}"
            infraredHome="${infrared.home}" appserver="tomcat" portNumber="${port-number}">
        <classpath>
            <!--path of dependency classes/jars -->
        </classpath>
    </integrate>
</target>

Dependency Jars/Classes - Application Ear/War may depend on external jar or classes required to build it, but which are not packaged with the application Ear/War. Such jars or classes needed for running the integrateInfraRED target can be specified under the classpath element. For example, if you are using Weblogic, since weblogic.jar is not part of the application and is required for building the application, it can be specified under the classpath element.
InfraRED has defined an Ant Task – Integrate which integrates InfraRED with the given application for gathering performance data. The various attributes of this ant task are explained here. Set the attribute values in the targets accordingly. Include any optional attributes in the integrate task as required.

Table 2
Attribute
Description
Optional/Mandatory
earFile
Name of the application ear file with fully qualified path.
Optional (Either of earFile or webWar should be defined)
destEarFile
Name of the integrated ear file with the fully qualified path. Integrated Ear will be created in this location with this given name.
Mandatory if earFile has been defined
webWar
Name of the application war file with fully qualified path.
Optional (Either of earFile or webWar should be defined)
destWebWar
Name of the integrated war file with the fully qualified path. Integrated War will be created in this location with this given name.
Mandatory if webWar has been defined
infraredHome
Folder where the Infrared zip has been unzipped.
Mandatory
appserver
Name of the app server - "weblogic | jboss | tomcat", default value: "weblogic"
Optional. If not specified, will default to "weblogic"
applicationName
Name of the application. This will be used to name the instance of the application. In case of Weblogic, this is queried from the MBean. Since MBean is not available in JBoss, this property has to be specified. In case of Wars, instance name is picked up from the <display-name> node in the web.xml
Relevant only if appserver=jboss and Ear is the format of distribution.
portNumber
The port number on which you will run your application. This will be used to name the instance of the application. In case of Weblogic, this is queried from the MBean. Since MBean is not available in JBoss, this property has to be specified.
Relevant only if appserver=jboss and Ear is the format of distribution.
centralCollection
Collection Strategy for the performance data. InfraRED provides 2 collection strategies – remote and local. Multiple application instances on one or more servers/clustered applications can be integrated with InfraRED and the performance data can be collected centrally in one place. This central point of performance data collection shall be remote to the applications in this case. Alternatively, the performance data may be collected locally. Valid values for this attribute are true/false. True implies remote collection strategy where the data is collected centrally.
Optional. Valid values for this attribute are true/false. Default value: "false".

centralServer
In case, you want to deploy infrared.war on a different machine and collect data there.
Optional. Default value: "localhost".
AppInfLibJars
For Weblogic Appserver application, if you want to instrument jars present in the APP-INF/lib dir of your application, then list them (comma separated) in this property.
Optional. Useful only for Weblogic.
instrument
As explained in the beginning, Integrate task instruments the application as part of the overall integration of InfraRED with the application. Set this property to false, to perform the InfraRED integration without instrumentation of the classes. This can be used when AspectWerkz is used for load time weaving of the application.
Optional. Valid Values - true|false. Default value: "true"
aspectPath
If you have created your own aspect classes and advices, give the path of the jar containing those classes. Default Value: ${infrared.home}/infrared-generic-aspects.jar
Optional
fork
Determines whether the instrumentation of classes needs to be forked. Possible values true/false. Default - false.
Optional. Default - false

Run the integrateInfraRED target to integrate InfraRED with the application.
After running the above ant Task, you will find an aspected-ear (or war) created at the position specified.

Step 2:

After the STEP 1 is complete, you will see an aspected ear/war created. This is the InfraRED integrated application you need to deploy. But before you start your server and deploy the application, follow steps in table 3.
Table 3
Weblogic SP3
1.        Copy infrared-bootstrap.jar, \dependency-jars\p6Spy.jar and \dependency-jars\aspectjrt-1.2.jar from the infrared release, to a folder (typically in your ${bea-home}\weblogic81\server\ext folder) and include these three jars in your Weblogic server’s classpath. To do this, include these three jars in the classpath specified in the startWebLogic.cmd file.
2.        Copy spy.properties file (from %INFRARED_HOME%\setup) in a folder (say, bea-home\weblogic81\server\ext\spy) and include this directory in your Weblogic-server’s classpath, i.e. include this directory in the classpath specified in the startWebLogic.cmd file.
3.        Make a P6Spy connection pool:
o    For XA-connection Pool (supported only for Oracle XA Connection):
§  Create a new connection pool choosing the other option in the driver list.
§  Specify net.sf.infrared.bootstrap.jdbc.oracle.InfraREDOracleXADataSource as the driver.
§  The url jdbc:oracle:oci:@<db tns name> for oracle 8i oci driver
§  Make sure real driver property in spy.properties is set to oracle.jdbc.driver.OracleDriver
o    For normal JDBC Connection Pool:
§  Create a new connection pool choosing the other option in the driver list
§  Specify com.p6spy.engine.spy.P6SpyDriver as the driver.
§  Specify the Url for the connection. For e.g. the Url for oracle 8i oci driver will bejdbc:oracle:thin:@<db tns name>
§  Make sure real driver property in spy.properties is set to the correct driver. For e.g., for oracle 8i oci driver real driver property should be set to oracle.jdbc.driver.OracleDriver
4.        Point your data-source to the newly created connection-pool.
Jboss
1.        Copy infrared-bootstrap.jar, \dependency-jars\p6Spy.jar and \dependency-jars\aspectjrt-1.2.jar from the infrared release, to folder %JBOSS_HOME%/server/default/lib, which will put these jars in classpath.
2.        Copy spy.properties file (from %INFRARED_HOME%\setup) to folder%JBOSS_HOME%/server/default/conf. Folder, %JBOSS_HOME%/server/default/conf is in classpath by default.
3.        Make a P6Spy connection pool:
o    For XA-connection Pool / Normal JDBC Connection Pool
Take oracle-xa-ds.xml for XA-Connection pool and oracle-da.xml for normal jdbc connection pool from%JBOSS_HOME%/docs/examples/jca directory and make following entries,
<local-tx-datasource>
      <jndi-name>jndi-name</jndi-name>
      <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
      <driver-class>com.p6spy.engine.spy.P6SpyDriver</driver-class>
      <user-name>user-name</user-name>
      <password>pswd</password>
      <exception-sorter-class-name> fully-qualified-class-name</exception-sorter-class-name>
 </local-tx-datasource>
o    Put oracle-xa-ds.xml in %JBOSS_HOME%/server/default/deploy directory.
Tomcat
1.        Copy infrared-bootstrap.jar, \dependency-jars\p6Spy.jar and \dependency-jars\aspectjrt-1.2.jar from the infrared release, to folder %TOMCAT_HOME%/common/lib/, which will put these jars in classpath.
2.        Copy spy.properties file (from %INFRARED_HOME%\setup) to folder %TOMCAT_HOME%\conf. Folder, and modify the file %TOMCAT_HOME%\bin\setclasspath.bat to set this folder in classpath. Append ;%TOMCAT_HOME%\conf; to the CLASSPATH element.
3.        Modify server.xml to use p6spy driver. Replace the value of parameter 'driverClassName' tocom.p6spy.engine.spy.P6SpyDriver

STEP 3:
Based on the choice of centralized collection take the following steps
Table 4
centralCollection=true (For Wars, centralCollection=true by default)
1.        Deploy the aspected ear/war on your application server and run it as you would usually do.
2.        Deploy infrared.war on the central server where you would like centralized collection to happen.
3.        Access the performance statistics using infrared-ui at following URL:http://localhost:7001/infrared
centralCollection=false
1.        Deploy the aspected ear/war on your application server and run it as you would usually do. If centralCollection=false was chosen then infrared.war will be the part of your ear/war. And infrared.war will get deployed as part of your application.
2.        Access the performance statistics using infrared-ui at following URL:http://localhost:7001/<application-context>/infrared    




Some of Screenshots from Tool Monitoring UI:


Performance Summary:



Summary of JDBC Modules :




Prepare Statements Summary:


Call Trace for 5 last invoked requests are shown on this page. Preparation and execution times for Sql queries executed in each invocation are also shown.



Merged Call trace for the API can be seen here. Call trace also lists the Sql query called in the call trace. Top 5 most expensive and most frequent queries for this call trace are shown below it.



HTTP Response:




Average response time taken by the application and total hits to the application can be seen on this page.

Snapshot of Performance Stats:


Snap shot of the performance statistics can be saved at any point of time and can be loaded from this page.


Configuration Changes UI:



InfraRED properties can be configured from this page for local collection strategy.


Above Complete Tool Details collected from InfraRED  Official Website .
For more details Visit http://infrared.sourceforge.net


Thanks.
Babu