Skip to content

Linux Hints and Tips

Matt Hampel edited this page Feb 12, 2017 · 4 revisions

Deploying the OBA apps in Tomcat web server (Linux)

The below details are specific to deploying OneBusAway in a Linux environment. For more complete instructions on deploying OneBusAway (including to a Windows environment), please see the main Developers Guide.

Assumptions: Build dependencies have been met including the following libraries:

On Ubuntu 12.04 LTS, this can be accomplished via:

    user@ubuntu:~$ sudo apt-get install tomcat6 git openjdk-6-jdk mysql-server

And then retrieving and installing apache-maven-3.0.x.tar.gz (http://maven.apache.org/download.cgi - installation instruction under: Unix-based Operating Systems Linux, Solaris and Mac OS X)

For user environment variables to run java commands and start tomcat for example:

  • I open my ~/.bashrc and paste this code at the end of the file (make sure they are valid values on yours.)
JAVA_OPTS="-Djava.awt.headless=true -Xss8120M -XX:MaxPermSize=9560m"
JRE_HOME=/usr/lib/jvm/java-1.6.0-openjdk/jre
export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.5
export M2=$M2_HOME/bin
export MAVEN_OPTS="-Xms1256m -Xmx1512m"
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
export PATH=$M2:$JAVA_HOME/bin:JAVA_OPTS:JRE_HOME:$PATH
  • The procedure goes like this:
    user@ubuntu:~/src$ git clone git@github.com:OneBusAway/onebusaway-application-modules.git
    user@ubuntu:~src$ cd onebusaway-application-modules
  • You only need the following 2 commands if you want version 1.1.11. Default is 1.1.12 snap-shot (both works)
    user@ubuntu:~src$ git tag -l
    user@ubuntu:~src$ git checkout tags/onebusaway-application-modules-1.1.11
  • Build it (it takes a some time to finish, mvn/maven will look at the configuration pom file and go to work for you. If you have issue with "clean" you may want to check directory permission)
    user@ubuntu:~src/onebusaway-application-modules$ mvn clean install
  • Deploy it (stop tomcat first before you deploy)
    user@ubuntu:~src/onebusaway-application-modules$ sudo cp onebusaway-combined-webapp/target/onebusaway-combined-webapp-1.x.x-full.war /var/lib/tomcat6/webapps/ROOT.war
  • The following command will create ROOT dir in webapps dir and explode the war file.
    user@ubuntu:~src/onebusaway-application-modules$ sudo su -
    root@ubuntu:/root$ cd /var/lib/tomcat6/webapps && mkdir ROOT && cd ROOT && jar xvf ../ROOT.war
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- Define your bundle path.  You can also do this externally with a "bundlePath" System property -->
    <bean class="org.onebusaway.container.spring.SystemPropertyOverrideConfigurer">
        <property name="order" value="-2" />
        <property name="properties">
            <props>
                <!--I think it is best to make tomcat6 the owner of the directory bundle-->
                <prop key="bundlePath">/home/dungle/src/gtfs-data/bundle</prop>
            </props>
        </property>
    </bean>
</beans>
  • Then makes sure tomcat can read this directory, and that ServiceAlerts.xml is writeable!
    root@ubuntu:~src$ chown -R tomcat6:tomcat6 <bundleDir> (mine as above is: /home/dung/src/gtfs-data/bundle/org_onebusaway_transit_data")
    root@ubuntu:~src$ chmod 744 <bundleDir>/ServiceAlerts.xml (/home/dung/src/gtfs-data/bundle/ServiceAlerts.xml")
  • Here is how I created my bundle. Pay close attention to the current directory and classpath switch making sure you have similar locations for the packages to be found (I still have error with Java's Stackoverflow - not sure how to fix it. I had to use windows machine to created it instead.)

This uses .class file (method 1):

~/src/onebusaway-application-modules/onebusaway-transit-data-federation-builder$ java -Xss8192M  -classpath .:target/* org.onebusaway.transit_data_federation.bundle.FederatedTransitDataBundleCreatorMain /home/dungle/src/gtfs-data/cal-gtfs-shape.zip /home/dungle/src/gtfs-data/bundle/

This uses .jar file (method 2):

~/src/onebusaway-application-modules/onebusaway-transit-data-federation-builder/target$ java -Xss8192M -jar onebusaway-transit-data-federation-builder-1.1.12-SNAPSHOT-withAllDependencies.jar /home/dungle/src/gtfs-data/cal-gtfs-shape.zip /home/dungle/src/gtfs-data/bundle/

If you are not sure what < bundleDir > is follow this to create them: https://github.com/OneBusAway/onebusaway-application-modules/wiki/Developer-Guide#building-a-transit-data-bundle

MySql/postgres Databases

*(optional - OBA also uses the database to cache data, store user info, API keys, etc, so to set it up to use MySQL for this, you’d include something like this: https://groups.google.com/forum/#!topic/onebusaway-developers/aBYCzSRaqvo)

*OneBusAway can work with any database that supports JDBC. See the next section below for Hsql instructions

  • Create a MySql database (notice we are no longer root)
    user@ubuntu:~src$ mysql -u root
    mysql> create database onebusaway_xwiki_prod;
    mysql> create database onebusaway_users;
    mysql> quit;
  • Please consider creating an xwiki user, and a onebusaway user, and granting them privileges here

  • Ensure the db connection information is in the above data-sources.xml and that the mysql connector jdbc jar is in the lib directory of tomcat

hsql database

*(I am not sure if this is required.)

Lastly Run webapp server

  • Start up tomcat
    user@ubuntu:~src$ sudo /etc/init.d/tomcat start
  • view the logs to ensure a sucessful statup
    user@ubuntu:~src$ sudo less /var/log/tomcatX/catalina.out

Below is one other example of a developer attempts to successfully deploy straight from Windows to Linux (Optional)

  • Assuming you have successfully built and run and deployed (2 basic web version .wars files - one is onebusaway-webapp.war the other is onebusaway-transit-data-federation-webapp.war) on Windows machine with tomcat6/7 as web server and you now want to deploy your .war files to Linux server with tomcat6/7 as web server.

  • I have only worked with 2 basic web version .wars files - one is onebusaway-webapp.war the other is onebusaway-transit-data-federation-webapp.war (both required for a basic web application of oba)

  • my oba version is 1.1.12-SNAPSHOT so it will work on both java6 or java7. I set up java6 & tomcat6 on ubuntu 12.04.

  • so deploy/copy the 2 .war files to /var/lib/tomcat6/webapps/ (it does not work yet :)

  • remember there is back end database for the application, i use embedded oracle database embedded HSQLDB. So you need to copy this database (you created when deployed on Windows and just reuse it do not need to create again) to the exact location path/directory on Linux, for example on Windows I have it like this: C:\Program2\gtfs\bundle and on Linux I have it like this: /Program2/gtfs/bundle (PLEASE also make sure Linux directory /Program2/gtfs/subdirs are owned by tomcat6.), you will need all db directory such as: bundle, bundle_api, bundle_fed, bundle_webapp. If you've done this on Windows in previous section (https://github.com/OneBusAway/onebusaway-application-modules/wiki/Developer-Guide#choosing-a-database), you sure know what they are . again I assume you have successfully done this on Windows and copy db dirs to Linux.

  • Now you can go ahead start your tomcat server and your webapp .war files will get picked up and try it out to see if it works such as http://localhost:8080/onebusaway-webapp/ or http://localhost:8080/onebusaway-webapp/where/standard/

  • BUT it does not work yet in my case i got lots of errors. The errors are so big and messy to post them all in here. So please look at the 3 files for these errors, location: /var/lib/tomcat6/logs and names: catalina.2014-04-15.log catalina.out and localhost.2014-04-15.log - look at all of them. I am puzzled by it and all error messages are related but so hideous and misleading such as "SEVERE: Error listenerStart" this not really the problem but the side effect, and warnings you can ignore, and "Error creating bean with name 'mbeanExporter' defined in class path resource [org/onebusaway/container/application-context.xml]" again it is side effect, and etc ... bunch of errors. But a little surprised that tomcat started and some webapps runs accept the one that provide database and connection to database onebusaway-transit-data-federation-webapp, and I use tomcat manager web interface to try to start it and and monitoring the 3 logs i saw memory error OutOfMemory or you can search the log for the word Memory that tells me to increase the memory for tomcat so i went here http://ubuntuforums.org/showthread.php?t=1069289 learnt to set tomcat java memory in /etc/default/tomcat6 file at the end adding a line JAVA_OPTS="-Djava.awt.headless=true -Xmx5120M -XX:MaxPermSize=5560m" Now it works! (it takes a little time to load data depending on your data size, i recommend to use small data set to test to save headache). * If by adding JAVA_OPTS="-Djava.awt.headless=true -Xmx5120M -XX:MaxPermSize=5560m" to /etc/default/tomcat6 and you still have memory error such as stackoverflow, then try adding JAVA_OPTS="-Xms1024m -Xmx1144m -server -Xss2144m -XX:PermSize=1024m -XX:MaxPermSize=2144m" to your profile .bashrc in your home directory. You can check your JAVA_OPTS setting by typing env command on linux ubuntu.