Sunday, 18 November 2012

starting apache tomcat from command line

Download required version of tomcat(am using apache-tomcat 7.0.42 for eccount) from tomcat archive.
Unzip and put it somewhere like /usr/apache tomcat 7.0/

[STEP 1] check the CATALINA_BASE
prayag@prayag:/usr/apache tomcat 7.0/bin$ ls -l
total 616
-rw-rw-r-- 1 prayag prayag  27145 May 11  2012 bootstrap.jar
-rw-rw-r-- 1 prayag prayag  12246 May 11  2012 catalina.bat
-rwxrwxr-x 1 prayag prayag  18317 May 11  2012 catalina.sh
-rw-rw-r-- 1 prayag prayag   2495 May 11  2012 catalina-tasks.xml
-rw-rw-r-- 1 prayag prayag  23546 May 11  2012 commons-daemon.jar
-rw-rw-r-- 1 prayag prayag 199453 May 11  2012 commons-daemon-native.tar.gz
-rwxrwxr-x 1 prayag prayag   1930 May 11  2012 configtest.sh
-rw-rw-r-- 1 prayag prayag   1342 May 11  2012 cpappend.bat
-rw-rw-r-- 1 prayag prayag   2111 May 11  2012 digest.bat
-rwxrwxr-x 1 prayag prayag   1624 May 11  2012 digest.sh
-rw-rw-r-- 1 prayag prayag   3300 May 11  2012 setclasspath.bat
-rwxrwxr-x 1 prayag prayag   3991 May 11  2012 setclasspath.sh
-rw-rw-r-- 1 prayag prayag   2111 May 11  2012 shutdown.bat
-rwxrwxr-x 1 prayag prayag   1563 May 11  2012 shutdown.sh
-rw-rw-r-- 1 prayag prayag   2112 May 11  2012 startup.bat
-rwxrwxr-x 1 prayag prayag   1956 May 11  2012 startup.sh
-rw-rw-r-- 1 prayag prayag  34126 May 11  2012 tomcat-juli.jar
-rw-rw-r-- 1 prayag prayag 241274 May 11  2012 tomcat-native.tar.gz
-rw-rw-r-- 1 prayag prayag   3636 May 11  2012 tool-wrapper.bat
-rwxrwxr-x 1 prayag prayag   4666 May 11  2012 tool-wrapper.sh
-rw-rw-r-- 1 prayag prayag   2116 May 11  2012 version.bat
-rwxrwxr-x 1 prayag prayag   1567 May 11  2012 version.sh

[STEP 2] allow permission to scripts
prayag@prayag:/usr/apache tomcat 7.0/bin$ sudo chmod 775 *.sh

[STEP 3] configure environment path
export CATALINA_HOME=/usr/apache tomcat 7.0

[STEP 4] update $CATALINA_BASE/conf/tomcat-users.xml to allow access to gui access 
<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users>
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
-->
<!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
-->

  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>

  <user username="tomcat" password="tomcat" roles="tomcat, manager-gui, manager-script"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="prayag" password="prayag" roles="manager-gui"/>

</tomcat-users>


[STEP 5] start server
prayag@prayag:/usr/apache tomcat 7.0/bin$ ./startup.sh 
Using CATALINA_BASE:   /usr/apache tomcat 7.0/
Using CATALINA_HOME:   /usr/apache tomcat 7.0/
Using CATALINA_TMPDIR: /usr/apache tomcat 7.0//temp
Using JRE_HOME:        /home/prayag/jdk1.6.0_23/
Using CLASSPATH:       /usr/apache tomcat 7.0//bin/bootstrap.jar:/usr/apache tomcat 7.0//bin/tomcat-juli.jar


[STEP 6] check tomcat processId
There we go !!!
prayag@prayag:/usr/apache tomcat 7.0/bin$ ps aux | grep tomcat
prayag    2858  2.0  2.0 425216 37240 pts/0    Sl   17:59   0:01 /home/prayag/jdk1.6.0_23//bin/java -Djava.util.logging.config.file=/usr/apache tomcat 7.0//conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/apache tomcat 7.0//endorsed -classpath /usr/apache tomcat 7.0//bin/bootstrap.jar:/usr/apache tomcat 7.0//bin/tomcat-juli.jar -Dcatalina.base=/usr/apache tomcat 7.0/ -Dcatalina.home=/usr/apache tomcat 7.0/ -Djava.io.tmpdir=/usr/apache tomcat 7.0//temp org.apache.catalina.startup.Bootstrap start
prayag    2883  0.0  0.0   4624   844 pts/0    S+   18:00   0:00 grep --color=auto tomcat

Check the ports tomcat is listening on (processId 2858)
prayag@prayag:~$ sudo netstat -lnp | grep 2858
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      5132/java       
tcp6       0      0 :::8009                 :::*                    LISTEN      5132/java       
tcp6       0      0 :::8080                 :::*                    LISTEN      5132/java

For windows users
C:/>netstat -a -n | findstr :8080

[STEP 7] Login http://localhost:8080/manager/html/
Download the build artifacts (war), If TeamCity CI is being used, or prepare *.war to be deployed.

Or, for teamcity CI simply copy *.war from latest build at /home/.BuildServer/system/artifacts/eccount-server/

eg.

ls -lt /home/.BuildServer/system/artifacts/eccount-server/478
build.properties
ROOT.war


After logging in to http://localhost:8080/manager/html/, upload the *.war (which will be copied to /webapps)

If you simply want to use tomcat docker, go to https://github.com/docker-library/tomcat


References
How to define BASEDIR env variable for Tomcat configuration,
http://www.coderanch.com/t/85334/Tomcat/define-BASEDIR-env-variable-Tomcat

Deploying on tomcat,
http://www.manydesigns.com/en/portofino/portofino3/3_1_x/installation-guide/deploying-on-tomcat

what port is tomcat 6 running on, http://askubuntu.com/a/143818/37643

No comments:

Post a Comment