Sunday, February 17, 2013

How to Run Jaggery.js App in Heroku Cloud

Jaggery.js is a server  side javascript framework for writing front-end ,communication ,server side logic and persistence in pure javascript.I felt that there
is no public cloud hosting service available for hosting jaggery apps for free(Other than i have attempted to run a jaggery server on famous platform as a service Heroku.In this post i am going to describe how to run a jaggery app on Heroku.

Pre-request for running apps in Heroku cloud.

1.The app should be written in supported languages(Ruby, Node.js, Clojure, Java, Python, and Scala).
2.All the java apps should be pushed to git as Maven project  
3.Heroku only allow apps to open port that is given by a system variable PORT.
4.App should bind to the port within 60s.
5.App should not store anything to file for long term persistence.
6.Data base details will be given by a system variable DATABASE_URL.

So the challenge is to make the Jaggery server to obey above rules.

Jaggery server is actually a WSO2 carbon server.Which is actually a java it should run in Heroku.To run a WSO2 Carbon app we have to set the JAVA_HOME.
But in Heroku during application launch java will be added to system path but JAVA_HOME will not be set .I have added following to WSO2 Carbon startup script to set the JAVA_HOME .

export JAVA_HOME=$(which java |xargs  readlink -f  | sed "s:bin/java::");
echo "Setting JAVA_HOME to $JAVA_HOME "

 Next thing is, i have to create a Maven project that should build a Jaggery server and copy Jaggery app into deployment folder.There are no Jaggery server dependency that i can get it as a zip file.But fortunately all the required dependencies for building a Jaggery server from a Carbon server are available.
I was able to create a Maven project that can build a jaggery server form carbon server.
The usual way of running java apps in Heroku, is specifying the launch command in Procfile.Procfile for the above Maven project looks like following

web: sh server/heroku-run/jaggery-1.0-SNAPSHOT/bin/

This means the Maven project has to unzip the built Jaggery server into heroku-run folder of server Maven module.

Now the a Maven project is ready that can build a Jaggery server and has a Procfile to launch the Jaggery server.But in order to start the server  I have to make sure that the Jaggery server opens only one port.
Jaggery server will open altogether 6 ports by default.Following are the ports and how i disable those ports.

1.http/https:These ports are opened by tomcat connectors.I need to make sure only one port to be i disabled the https connector in JAGGERY_HOME/carbon/repository/conf/tomcat/catalina-server.xml

2.jmx(2 ports):There is a configuration to not to start the jmx server.The file name is CARBON_HOME/repository/conf/etc/jmx.xml

3.Zookeeper server(opens one port):To disable Zookeeper  there should be a property(start_zk_server=false) in /carbon/repository/conf/etc/zoo.cfg

4.jmx remote (opened by tomcat):To disable this
should not be set.

Finally the port number in tomcat connector has to be set to the port number in PORT system variable provided by Heroku.All the configuration files in jaggery server can accept java system variable in the form of ${SYSTEM_VARIABLE}.To set that system variable we have to pass -DSYSTEM_VARIABLLE=value in start up script.In this way the value in PORT system variable can be passed to tomcat connector configuration.

The same way the information in DATABASE_URL(database url,username,password and database name) system variable should be passed to JAGGERY_HOME/carbon/repository/conf/datasources/master-datasources.xml.

The Maven project can be found in Github here

Follows are steps to run your Jaggary app in Heroku.

0.Register in and install Heroku tool
1.git clone
2.heroku create
3.heroku addons:add heroku-postgresql:dev
4.heroku config
5.heroku pg:promote HEROKU_POSTGRESQL_RED_URL
6.Insall postgresql (
apt-get install postgresql
7.heroku pg:psql
\i /home/heroku-jaggeryjs-app-runner/dbscript/postgresql.sql
8.add your Jaggery app to apps/ROOT directory
9.git add .
10.git commit -m "adding initial project"
11.git push  heroku master
12.heroku logs -t
Access my app here


  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me..
    I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai .
    or Javascript Training in Chennai.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai