Tuesday, October 8, 2013

Install Memcache in Ubuntu


Install Memcache in Ubuntu

About Memcache

Memcache is a system that works to speed up virtual private servers by caching server information. The program allows you to allocate a specific amount of the server ram toward caching recently queried data for a certain amount of time. Once the data is requested again, memcache speeds up the process of retrieving it by displaying the cached information instead of generating the result from the database.

To setup you require the user to have root privileges.

Step 1 : It is good to update apt-get to make sure that all of the packages we download are up to date.

sudo apt-get update

Step 2 : Installing memcache service

sudo apt-get install memcached

Now you are ready to start using Memcache.


Step 3 : Confirm Memcache and see stats

After mem-cache is downloaded, you can check that it has been installed by searching for it:

root@sanjeeva:/home/sanjeeva# ps -e|grep memcache
20484 ?        00:00:00 memcached

root@sanjeeva:/home/sanjeeva# ps aux | grep memcache
memcache 20347  0.0  0.0  47376  1072 ?        Sl   23:17   0:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
root     20453  0.0  0.0   4384   840 pts/0    S+   23:22   0:00 grep --color=auto memcache


================================================================================
To Increase memory for memcache(d), open the /etc/memcached.conf and increase the -m parameter.

The default is 64M
# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m 64
================================================================================

Step 4 : Stop / Start / Restart Memcache
#sudo service memcached stop
#sudo service memcached start
#sudo service memcached restart


Friday, September 6, 2013

Apache Ant (Another Neat Tool) : Lesson 2


Apache Ant (Another Neat Tool) : Lesson 2

Ant provides a number of predefined data types.

1. File Set

Fileset data types represents a collection of files.
The Fileset data type is usually used as a filter to include and exclude files that match a particular pattern.

Example: selects all java files in the source folder except those that contain the word 'Stub'
<fileset dir="${src}" casesensitive="yes">
     <include name="**/*.java"/>
     <exclude name="**/*Stub*"/>
</fileset>

2. Pattern Set

A pattern set is a pattern that allows to easily filter files or folders based on certain patterns.
Patterns can be created using the following meta characters.

? - Matches one character only

* - Matches zero or many characters

** - Matches zero or many directories recursively

Example :
<patternset id="java.files.without.stubs">
    <include name="src/**/*.java"/>
    <exclude name="src/**/*Stub*"/>
</patternset>

<fileset dir="${src}" casesensitive="yes">
    <patternset refid="java.files.without.stubs"/>
</fileset>

3. File List

The File list data type is similar to the file set except that the File List contains explicitly named lists of files and do not support wild cards.

Another major difference between the file list and the file set data type is that the file list data type can be applied for files that may or may not exist yet.

Example :
<filelist id="config.files" dir="${webapp.src.folder}">
     <file name="applicationConfig.xml"/>
     <file name="faces-config.xml"/>
     <file name="web.xml"/>
     <file name="portlet.xml"/>
</filelist>

The webapp.src.folder attribute in the above example points to the web application's source folder of the project.

4.Filter Set

Using a Filter Set data type with the copy task, you can replace certain text in all files that match the pattern with a replacement value.

A common example is to append the version number to the release notes file, as shown in the example below

<copy todir="${output.dir}">
     <fileset dir="${releasenotes.dir}" includes="**/*.txt"/>
         <filterset>
             <filter token="VERSION" value="${current.version}"/>
         </filterset>
</copy>

* The output.dir attribute in the above example points to the output folder of the project.
* The releasenotes.dir attribute in the above example points to the release notes folder of the project.
* The current.version attribute in the above example points to the current version folder of the project.

The copy task, as the name suggests is used to copy files from one location to another.

5. Path

The path data type is commonly used to represent a classpath.
Entries in the path are separated using a semicolon or colon.
However, these characters are replaced a the run time by the running system's path separator character.

Example:
<path id="build.classpath.jar">
     <pathelement path="${env.J2EE_HOME}/${j2ee.jar}"/>
          <fileset dir="lib">
             <include name="**/*.jar"/>
          </fileset>
</path>

The env.J2EE_HOME attribute in the above example points to the environment variable J2EE_HOME.
The j2ee.jar attribute in the above example points to the name of the J2EE jar file in the J2EE base folder.


Reference : http://www.tutorialspoint.com

Apache Ant ( Another Neat Tool ) - Lesson 01


Apache Ant ( Another Neat Tool ) : Lesson 01

Apache Ant is a Java based build tool from Apache Software Foundation.
Ant's build files are written in XML.

Why do you need a build tool?

To automate the build and deployment we need a build tool. It is do the followings:
     - Compile code
     - Package the binaries
     - Deploy the binaries to the test server
     - Test your changes
     - Copy code from one location to another

Therefore, Apache Ant is a build and deployment tool that can be executed from a command line.

Features of Apache Ant -
* Ant is the most complete Java build and deployment tool available.
* Ant scripts are written using plain XML.
* Ant is good at automating complicated repetitive tasks.
* Ant comes with a big list of predefined tasks.
* Ant provides an interface to develop custom tasks.
* Ant can be easily invoked from the command line and it can integrate with free and commercial IDEs.

Installing Apache Ant -

Apache Ant is distributed under the Apache Software License, a fully-fledged open source license certified by the open source initiative.

1. Ensure that the JAVA_HOME environment variable is set to the folder where your JDK is installed.
2. Download the binaries from http://ant.apache.org
3. Unzip the zip file to a convenient location. (ex:- /usr/share/ )
4. Create a new environment variable called ANT_HOME that points to the Ant installation folder, in this case "/usr/share/ant".
5. Append the path to the Apache Ant batch file to the PATH environment variable.

To create the ANT_HOME, use followings :
    1. type command /$ sudo gedit /etc/environment
    2. Paste ANT_HOME="/usr/share/ant"
    3. Append to the PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$JAVA_HOME:$JRE_HOME:$ANT_HOME"
6. Verify the installation, use below commands and should see an output similar to:

sanjeeva@sanjeeva:/$ ant -version
Apache Ant(TM) version 1.8.2 compiled on December 3 2011

sanjeeva@sanjeeva:/$ $ANT_HOME
bash: /usr/share/ant: Is a directory

Build Files -

Ant's build file, build.xml should live in the project's base directory.
Although you are free to use other file names or place the build file in some other location.

All build files require the project element and at least one target element.

project element has three attributes :

name : The Name of the project. (Optional)
default : The default target for the build script. A project may contain any number of targets. This attribute specifies which target should be considered as the default. (Mandatory)
basedir: The base directory (or) the root folder for the project. (Optional)

target is a collection of tasks that you want to run as one unit.

Below example, we have a simple target to provide an informational message to the user.

<?xml version="1.0"?>
<project name="Hello World Project" default="info">
      <target name="info">
             <echo>Hello World - Welcome to Apache Ant!</echo>
      </target>
</project>

* Targets can have dependencies on other targets.

For example,
a deploy target may have a dependency on the package target,
the package target may have a dependency on the compile target and so forth.

Dependencies are denoted using the depends attribute.

For example:
<target name="deploy" depends="pacakge">
      ....
</target>
<target name="pacakge" depends="clean,compile">
      ....
</target>
<target name="clean" >
      ....
</target>

<target name="compile" >
      ....
</target>

The target element has the following attributes:

name : The name of the target (Required)
depends : Comma separated list of all targets that this target depends on. (Optional)
description : A short description of the target. (optional)
if : Allows the execution of a target based on the trueness of a conditional attribute. (optional)
unless : Adds the target to the dependency list of the specified Extension Point.
An Extension Point is similar to a target, but it does not have any tasks. (Optional)

Run a build file :

1. Save the below as build.xml.

<?xml version="1.0"?>
<project name="Hello World Project" default="info">
     <target name="info">
          <echo>Hello World - Welcome to Apache Ant!</echo>
     </target>
</project>

2. Open a terminal and navigate to the folder where the build.xml resides.

3. Type ant info Or ant and see the output.

sanjeeva@sanjeeva:~$ ant
Buildfile: /home/sanjeeva/build.xml
info:
[echo] Hello World - Welcome to Apache Ant!

BUILD SUCCESSFUL

Total time: 0 seconds

Property element

Ant uses the property element which allows you to specify properties.
This allows the properties to be changed from one build to another. or from one environment to another.

By default, Ant provides the following pre-defined properties that can be used in the build file;

ant.file : The full location of the build file.
ant.version : The version of the Apache Ant installation.
basedir : The basedir of the build, as specified in the basedir attribute of the project element.
ant.java.version : The version of the JDK that is used by Ant.
ant.project.name : The name of the project, as specified in the name atrribute of the project element
ant.project.default-target : The default target of the current project
ant.project.invoked-targets : Comma separated list of the targets that were invoked in the current project
ant.core.lib : The full location of the ant jar file
ant.home : The home directory of Ant installation
ant.library.dir : The home directory for Ant library files - typically ANT_HOME/lib folder.

In addition to the above, the user can define additional properties using the property element.

Example : shows how to define a property called “devname”:
<?xml version="1.0"?>
<project name="Hello World Project" default="info">
       <property name="devname" value="Sanjeeva Pathirana"/>
             <target name="info">
                    <echo>Apache Ant version is ${ant.version} </echo>
                    <echo>Developer is ${devname} </echo>
            </target>
</project>
 
[ Out put ] :
Buildfile: /home/sanjeeva/build.xml
info:
[echo] Apache Ant version is Apache Ant(TM) version 1.8.2 compiled on December 3 2011
[echo] Developer is Sanjeeva Pathirana

Ant Property files -

Storing the properties in a separate file allows you to reuse the same build file, with different property settings for different execution environment. For example, build properties file can be maintained separately for DEV, TEST and PROD environments.

The property file is named build.properties and is placed along side the build.xml file.

You could create multiple build properties file based on the deployment environments - such as build.properties.dev and build.properties.test

Example : shows the build.xml and an associated build.properties file

<?xml version="1.0"?>
<project name="Hello World Project" default="info">
        <property file="build.properties"/>
             <target name="info">
                  <echo>Apache Ant version is ${ant.version} </echo>
                  <echo>Developer is ${devname} </echo>
                  <echo>Build Version is ${buildversion} </echo>
             </target>
</project>

build.properties
# The Site Name
devname=Sanjeeva Pathirana
buildversion=3.3.2

Output -
Buildfile: /home/sanjeeva/build.xml
info:
[echo] Apache Ant version is Apache Ant(TM) version 1.8.2 compiled on December 3 2011
[echo] Developer is Sanjeeva Pathirana
[echo] Build Version is 3.3.2
BUILD SUCCESSFUL
Total time: 0 seconds

Thursday, August 29, 2013

Install Apache Tomcat 7 on Ubuntu


Install Apache Tomcat 7 on Ubuntu

This about installing Apache Tomcat7 on Ubuntu 12.04, follow the steps given below.

Note: Before this installation make sure java is installed in your machine.

Step 1. Download Tomcat 7 tar.gz binary distribution. ( http://tomcat.apache.org/download-70.cgi )

Step 2. Go to the location “Downloads” and unpack it.
cd /home/sanjeeva/Downloads
tar xvzf apache-tomcat-7.0.42.tar.gz

Step 3. Move to the share file location which is in your machine by using
sudo mv apache-tomcat-7.0.42/ /usr/share/tomcat7

Step 4. Check the installed java in your machine
echo $JAVA_HOME

Step 5. Open startup.sh and paste the JAVA_HOME & JRE_HOME
gedit /usr/share/tomcat7/bin/startup.sh

paste the below 2 lines as per your java home:
#!/bin/sh
JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386"
JRE_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386/jre"

Sometime this is not allow to edit the startup.sh, since it is having only the root permission. Therefore you have to log as a super user by entering “su” command and root password.
Once you logged change the permission on “startup.sh” and exit. Now you will able to edit that file.

Step 6. Open tomcat-users.xml and uncomment user and role entries there.
gedit /usr/share/tomcat7/conf/tomcat-users.xml

Add a manager-gui role and a user by adding following lines there.
<tomcat-users>
<role rolename="manager-gui"/>
…..
<user username="sanjeeva" password="tomcat" roles="manager-gui"/>

To start the tomcat
sh /usr/share/tomcat7/bin/startup.sh

Console out put wiil be
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME: /usr/lib/jvm/java-1.7.0-openjdk-i386
Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar

Then Check the http://127.0.0.1:8080

To shutdown the tomcat
sh /usr/share/tomcat7/bin/shutdown.sh