Running Multiple instances of Tomcat

July 2nd, 2009

Hosting more than a single application in a single apache-tomcat server is not a new thing. It is a simple task. But many of us might be unaware of the potential danger we are putting ourselves by doing so, especially if each of the applications hosted are critical enough.

In such situation if a single application crashes, then it brings about a problem generally termed as “bad apple problem”. It results in the malfunctioning of other applications hosted in the same sever as well. Then comes the situation where running multiple instances of tomcat comes into play. Some of its main advantages are:

1. Avoid the bad apple problem.

2. Logs can be saved for each application individually.

3. Each application can be configured individually. ie. Update (upgrade/downgrade) of applications can be handled individually.

4. Stop/Start/Restart actions on one application can be performed without affecting tha other applications.

Now that we have known its importance, I’ll write about how to configure multiple instances of tomcat in a step by step manner.

Step 1:

Get binary distribution of apache-tomcat and install it.  I have used tomcat 6.x but it should work with lower versions as well. Lets suppose the installation directory is C:\Program Files\Apache Software Foundation\Tomcat 6.0.

Step 2:

Make a shared folder somewhere to place a few configurations files that can be used by all instances of tomcat we are going to make. eg. C:\tomcat-instances\shared. Under shared folder make a folder named conf.  Now copy server.xml and logging.properties from C:\~~\Tomcat 6.0\conf to C:\tomcat-instances\shared\conf.

Step 3:

In the next step we have to configure the server.xml. Modify Server.xml so that you can provide shutdown port, http port and host name in the runtime. Server port, http port and host name should be configured as shown below.

…………….

<Server port=“${shutdown.port}” shutdown=“SHUTDOWN”>

…………….

<Connector port=“${http.port}” protocol=“HTTP/1.1″
connectionTimeout=“20000″
redirectPort=“8443″ />

………………..

<Host name=“${host.name}” appBase=“webapps”
unpackWARs=“true” autoDeploy=“true”
xmlValidation=“false” xmlNamespaceAware=“false”>

Step 4: Now that we have configured server, it is time to add new instances of tomcat. Inside C:\tomcat-instances create a folder named application1. Create folders so that you have the folders structure as:

tomcat-instances
      - shared
            - conf
      - application1
            - conf
            - logs
            - webapps
            - work
            - temp

Step 5:

Now copy catalina.properties and web.xml from C:\~~\Tomcat 6.0\conf to C:\tomcat-instances\application1\conf folder.

Edit the catalina.properties and add the following lines

http.port=8081
shutdown.port=8006
host.name=localhost

The shared Server.xml takes the values of http port, shutdown port and host name from this catalina.properties. If you want to make another instance of tomcat, repeat from step 4 with application2. Make sure you give different addresses for http.port, shutdow.port. eg. 8082 and 8007 respectively. host.name can be localhost in both cases.

Step 6:

Copy the war(eg. ROOT.war of your web application) file of your application to C:\tomcat-instances\application1\webapps

Step 7:

Now the tomcat has been configured, it is time to install a new window service for the instance of tomcat just configured. You can use Tomcat Service Manager(TSM) for this. Run TSM and use the following details to create a service named Application1.

Service Name: Application1

Catalina Home: C:\Program Files\Apache Software Foundation\Tomcat 6.0

Catalina Base: C:\tomcat-instances\application1

Tomcat Config File: C:\tomcat-instances\shared\conf\Server.xml

Java Home: Your Java Installation directory

Other values are filled automatically by the TSM.

Step 8:

Now you are almost done. From the Service menu in TSM, click on install/update. This will install the service for you. After the service has been successfully installed, click on Service –> Start to start the service.

Step 9:

Congratulations!!! You are done. Now open your favourite browser and type http://localhost:8081. Your application should be running… eNjoy!!!!!

Sujan Programming , ,

√2 is irrational

July 1st, 2009

It is really fun proving something by contradiction. Here is an interesting example I want to share.

We are going to prove that square root of 2 is irrational. By contradiction, we start with the assumption that √2 is rational. And later we’ll prove that our assumption is wrong and hence √2 is irrational.

Proof:

1. √2 is rational.

2. We know for a rational number, there exist two integers a and b with common factors no other than 1. Hence,

√2 = a/b.

3. Squaring both sides (since x=y implies x2=y2), we get

2 = a2/b2

4. Multiplying both side by b2, we get

2b2 = a2

5. Here, b is an integer and hence b2 is also an integer. Any integer multiplied by 2 is even. Hence 2b2 is even which implies that a2 is even.

6. Since a2 is even, a is also even. (If square of an integer is even, the integer is also even).

7. Since a2 is even, there exists some integer c such that,

a = 2c

8. Now, we can write

2b2= 4c2
Hence, b2= 2c2

9. Since c is an integer, c2 is an integer and hence b2 is even.

10. Hence this proves that b is also even.

11. Now we have proved that both a and b are even . This means a and b have a common factor 2, other than 1.

12. Hence, the assumption √2 is rational is false and hence √2 is irrational.

This is it. Isn’t it interesting?

Sujan Education

Just Playing around

June 22nd, 2009

Sometimes playing around with nature is fun. There are many beautiful things around us and we fail to notice them. Someone has well said, “Beauty lies in the eyes of beholder”. Indeed it does. Everything around us is beautiful when our eyes are beautiful. I like to share some beautiful things that are around me and give pleasure to my eyes.

IMG_0977 IMG_0981

IMG_0974 IMG_0487

IMG_0942 IMG_0966

IMG_0961 IMG_0960

Sujan Nature, Photography

Documenting with LaTeX

June 20th, 2009

Recently I happened to learn to use LaTeX to create documents. I was amazed by the cool tool. While reading documents, I always used to wonder how would people create such complex mathematical equations. Thanks to LaTeX that made it so easy. I won’t go on much details about LaTeX. This is simply a type of language that you can use for documentation. It is widely used in universities as a tool for generating assignments. You can read further about it on LaTeX project. For those who haven’t started yet, let’s see how to document with LaTeX.

Where to Start?

Firstly, you need to have LaTeX distribution installed in your computer. You can find resources in LaTeX project. In my case, I downloaded and installed MikTeX, a LaTeX implementation for Windows. from here.

Now that you have LaTeX binaries, let’s start with creating some documents. All you need now is an editor. Download Winshell and install it.

What Next?

Now it is time for the go. Lets create a simple pdf file using LaTeX. Create a new Tex document called First.tex. Copy and paste the following code in the file and save it.

\documentclass{article}

\begin{document}

\section {First pdf document using LaTeX}

\subsection{First subtitle}

Some text in first title

\subsection{Second Subtitle}

Some other text in second title.

\end{document}

Now in the Winshell window, click on Execute –> PDFView and see the pdf document pop out in front of you. Congratulations!!

Using the LaTeX plugin for eclipse

If you are a developer, you might be happy to hear that you can use LaTeX plugin for eclipse. I have used TeXlipse plugin and found it really cool. Here are some steps to configure.

1. Install the TeXclipse plugin in your eclipse. You can get the installation direction here.

2. Once you have installed TeXclipse plugin, all you need to do is configure your eclipse for using LaTeX. You can follow the directions here.

3. Now you are on the move. Create a new document, build and preview it to see how well it works for you. If you have problems running, see the directions here.

Materials and References

Once you have been able to create documents using LaTeX, now you can use this to create several other type of documents including ps (post script) and dvi (device independent file format) formats. Here is a file that contains the symbols and their corresponding LaTeX tags. Hope it will help you well.

Happy documenting. Cheers!!

Sujan Documentation

Voyage de Kalinchowk

June 2nd, 2009

Yet another hike and yet another time for adventure. It was a cold Saturday morning. With enthusiasm and excitement to visit Kalinchowk, one of the rarely visited, yet beautiful and probably the bests of the hiking spots in considerable distance from Kathmandu, we got gathered at about 6:20 AM in old buspark. We were feeling safe for RK Wagle had already bought tickets for us the day before. At about 6:45 AM, our micro set off for Charikot. Admiring the natural beauty along the way, we kept moving. From near "Kharidhunga", the bus driver pointed to a very high hill with a nose like shape (which we later named "Nake Dada") and said that you guys have to walk through across that hill to climb a hill even steeper than that. WOW! The journey was going to be adventurous. We had lunch at "Mude", about 30 kms short of Charikot, the headquarters of Dolkha. The driver dropped us at "Makaibari" at about 11:30 AM telling that this could be the best place to start for Kalinchowk.

clip_image002IMG_5234IMG_5265 IMG_5291

N ow the real hike began. We took some photos and with great energy we started walking. We were heavily bagged with almost all stuffs we needed. We had plenty of water, food to eat (noodles, biscuits, cookies, chocolates)We nearly missed our way to Deurali which we corrected by asking some locals. We reached Deurali at about 12:20. We refilled our water bottles and kept moving through the jungle. The next house we cited was at 1:40. We met a a group of people who were returning back from Kalinchowk. We refreshed ourselves with a rest, some food (noodles and beaten rice) given by the group and a some "Chyang" and kept moving through the jungle again. We were about to reach "Gairi" (around 3:10) when it suddenly started raining. We were lucky enough to find a house nearby and entered there for shelter. There we had our noodles cooked, yak sukuti fried and chayang made. We also bought some churpi and it was me who cut it into pieces.

IMG_5304 IMG_5398 IMG_5436 IMG_5502

The rain stopped and we started moving at around 4. We kept asking how far we are from our destination to every next person we met on the way only to find that the answer is never accurate. As we moved on, guys started becoming tired. We took rest frequently in the excuse of photography, the biggest being the one taken near the buldozer we found in our way. Now we were approaching near Nake dada. We cursed pointing to that hill for this was the hill we had to cross to get to our destination. Now we had already gained a great altitute and the only vegetation we could see was the beautiful flower "Rhododendron", our national flower. Initially we were interested to pick a few of the flowers but later it all became a common thing. Wading through the forest of colourful(red, white and pink) Guras and appraising the beauty, we kept moving. Finally at around, 6:24 PM, we were fortuned to see the first view of our final destination, the hill where "Kalinchowk Bhagawati" resided.

IMG_5522 IMG_5526 IMG_5523 IMG_5554

As we were approaching "Kuri", we saw beautiful pasture. "It was all green". We forgot all the pain we had handled walking all the way through. Now we had almost reached our destination and we were proud hikers. Subash, Wagle, Uttam and I were the last guys to reach the spot. We couldn’t resist ourselves laying down in the green grass and looking at the beautiful sky in the cool temperature of about 2 degree centigrade. By the time we reached Kuri, guys had already booked the hotel and found our shelter for the day. We warmed ourselves by sitting around a fire and having tea made with Yak’s milk. Later, Ligaj, Uttam, Subash and me lit fire by ourselves in the road and enjoyed "LT" with Sukuti of Chauri and beautiful Nepali songs we sang. Wagle was having difficult time with his head. We cut the biggest Cock of "Kuri" and enjoyed our dinner.

IMG_5552 IMG_5562 IMG_5580 IMG_5610

The other day, we woke up early in the morning and headed towards the Kalinchowk Bhagwati temple, which was located at the top of the hill in front of us. After walking for about an hour, we reached the top of the hill. Satisfied with the voyage we made, we enjoyed the panaromic view from the top, worshipped, took some photos and headed back to Kuri. After having lunch we marched off to Makaibari at about 9:40 AM. We reached Makaibari at about 1. LIfe got hard as last 3 buses to Kathmandu didn’t stopped to pick us up. Later, we went to Charikot in a bus and luckily we found a private micro bus which would return back to Ktm. After roaming for about an hour in Charikot, we returned back happily in the micro bus and finally reached Kathmandu at about 8 PM. WOW!! We completed yet another wonderful hike and added a story to tell…

IMG_5568 IMG_5631 IMG_5589 IMG_5515

Sujan Adventure, Travelling

Had a bad day !!!!

March 23rd, 2009

I was out for lunch. I remembered that I had to go to Nepal Finance, Kamaladi to get the certificates of shares my dad and mum had won. The share numbers were 20 each. I reached Nepal Finance, which was by the side of main road. I saw no parking areas near and I had a short task which would hardly take 5 minutes. I didn’t thought that those 5 minutes would be proved such expensive. I placed my bike in a corner of the road and headed inside the finance company. There I had to wait for a couple of minutes until a customer was done with his task. But I realized he had a lot of certificates to take and I requested him to give 2 minutes for my task and he agreed. I submitted the photocopies of citizenships of my mum and dad. The officer insisted that she needed a copy of my ID as well. I came out to make a photocopy of my driving licence. When I went down to the road, I found there were some people were talking about traffic police taking their bikes in truck. To my dissapointment, I couldn’t find my bike there. Gosh, what a bad day. 5 minutes had never been that unlucky to me. I realized my bike was in the truck, roaming around the city.

I was somewhat angry with the traffic police, somewhat with the finance company for not having a parking place and somewhat with myself, for I should have anticipated that thing to happen. Nevertheless, there was no use thinking of it and I moved in search of photocopy centre. As expected, there was no electricity in that area. I had no bike to find some other places and no time to walk in search of other photocopies centres. Dissapointed, I returned back. I requested the officer in the finance company to allow me take the certificates without submitting a copy of my ID but she denied. I could understand that she was bound by the company policy and she well understood what situation I was in. She kind of felt pity on me because of what has just happened and forwarded me to her senior. I requested him showing the original citizenship cards of my parents. He agreed to give the certificate and I returned back happy. I called Ligaj expecting him to come to pick me up. But later I realized that I was wasting his time. I told, I’ll come by foot.

On the way, many things kept playing in my mind. Was that my mistake? Was that the mistake of the finance company? Was the traffic office being very rude at me? I always used to think that rules are rules and they should apply to all. As a matter of fact, parking in road was against the rule and I deserved punishment. Now, my concern is, would these make the traffic system of Ktm better? Are they really trying hard to make things better? Or was that theirs easy way to make money? The other thing is, am I to be sure that the bike was taken by the traffic, or was it stolen?

Sujan Wish it never happened

How do Search Engines Work?

February 4th, 2009

Search engines do not really search the World Wide Web directly. Each one searches a database of web pages that it has harvested and cached. When you use a search engine, you are always searching a somewhat stale copy of the real web page. When you click on links provided in a search engine’s search results, you retrieve the current version of the page.

Search engine databases are selected and built by computer robot programs called spiders. These “crawl” the web, finding pages for potential inclusion by following the links in the pages they already have in their database. They cannot use imagination or enter terms in search boxes that they find on the web.

If a web page is never linked from any other page, search engine spiders cannot find it. The only way a brand new page can get into a search engine is for other pages to link to it, or for a human to submit its URL for inclusion. All major search engines offer ways to do this.

After spiders find pages, they pass them on to another computer program for “indexing.” This program identifies the text, links, and other content in the page and stores it in the search engine database’s files so that the database can be searched by keyword and whatever more advanced approaches are offered, and the page will be found if your search matches its content.

Many web pages are excluded from most search engines by policy. The contents of most of the searchable databases mounted on the web, such as library catalogs and article databases, are excluded because search engine spiders cannot access them. All this material is referred to as the “Invisible Web” — what you don’t see in search engine results.

 

Courtesy: UC Berkeley - Teaching Library Internet Workshops

Technology

Unit Testing with Flex 3.0

February 4th, 2009

I had heard a lot about Test Driven Development(TDD). I wanted to know what TDD was and wanted to employ the same in the development of my flex project. I searched as found an article by Neil Webb. He has nicely explained about starting the TDD in flex.

This link may be helpful to those who want to apply TDD in flex applications.

Unit testing and Test Driven Development (TDD) for Flex and ActionScript 3.0

Try the TDD and find out its power. Personally, I have found this to be a great process to develop bug-free applications.

Cheers!!

Flex

An immortal love…..

January 30th, 2009

(A girl and guy were speeding over 100 mph on a motorcycle)
Girl: Slow down. Im scared.
Guy: No this is fun.
Girl: No its not. Please, its to scary!
Guy: Then tell me you love me.
Girl: Fine, I love you. Slow down!
Guy: Now give me a BIG hug.

(Girl hugs him)
Guy: Can u take my helmet off and put it on? Its bugging me.

In the paper the next day: A motorcycle had crashed into a building because of break failure. Two people were on the motorcycle, but only one survived.

The truth was that halfway down the road, the guy realized that his breaks broke, but he didn’t want to let the girl know. Instead, he had her say she loved him, felt her hug one last time, then had her wear his helmet so she would live even though it meant he would die.

I read this post somewhere in the web. The story was short and heart-touching. The lessons to be learnt are too long. Lets discuss them here..

Love

A trip to Shivapuri….a day to remember

January 26th, 2009

May, the 2nd, 2007

I would say this was the first hike I ever made with my friends. Santosh, Nischal, Shiraj, Janesh(JD) and I made a wonderful team. We set off for journey at about 8 in the morning. By 9:15, we had reached the base of Shivapuri national park. With lots of enthusiasm, we got off the microbus and started heading towards the park.

We were very hungry and in a good hunting mood. After searching for a while, we found a hotel where we could eat dal-bhat-tarkari(DBT) along with CHICKEN ROAST. The CR was so good that we carried some with us. It was almost 10:30 when we finished eating one of the best DBT. We bought the tickets and entered inside the park. We were very excited and in a real hiking mood. We entered the forest and continued to walk through the road. “Walking straight away through the road” was interesting but could have been better. We tried something different. After walking for some distance, we decided we need some rest and sat down for a while. Every one of us had our own style of taking rest. We climbed up to the Gumba and had some photographs there. The most interesting thing we had there was a couple of cups of special drink, special because it was free.

After being somewhat refreshed, we climbed down and kept walking until we saw the grand “Tare Bhir”. We all had the same feeling but it was Santosh who spoke out, “Let’s climb that hill”. WOW, what an offer it was. Everyone agreed as if it was a preplan. We started climbing straight up. The hard-to-climb rocks were challenging us and we were ready to face the challenge, including Shiraj who was having a soft of problem with his stomach (guess what….?). We started the journey, which I would say, was adventurous. We thought we were the first hikers to climb that hill, which may or may not be the truth. Hands on hands, we were supporting each other in climbing the hill. Shiraj was getting weak but he accompanied. The rocks were getting stiffer as we elevated. At a point, the place was so steep that we could only see the ground meters down. We kept strong to the bushes and kept climbing. There was no room for slippery legs. The more we climbed up, the more adventurous the journey became. Thanks for a packet of biscuit that was providing Shiraj the energy to push forward. The approaching top was motivating us to climb more and the increasing difficulty was deteriorating our spirit. We were only about 20 meters shy of the top, when Shiraj declared he can’t continue. We could not force him as we know he was not fit and finally decided that we’ll complete the mission some other day.

Actually, the fun we had that day had already been memorable. We sat down and started eating the CR (Chicken Roast) that we had bought with us. They tasted fabulous. We then climbed down the hill and returned back via another path. The return path was even more interesting. We passed across “Salla Ghari”. Nischal glorified the moment by several jokes and advising us different postures for photographs in the beautiful “Salla Ghari”. We returned playing with the “Sallako Ful”.

Looking down the slippery slope full of pine leaves, Janesh proposed “Guys, Let’s slide down”. It was the start of next interesting event. We slid down the slope. (Later, I found that the pocket of my pant was torn). We reached to the forest behind the NMC. Janesh left us from there and rest of us took micro to return back.

The day was full of events. It was a real hike and to say the truth, it set the true  meaning of hiking, at least to me.

Adventure