# Deploying a RhoConnect Application ## Deploying On-Premise The [sinatra book](http://sinatra-book.gittr.com/) has some great [deployment documentation](http://sinatra-book.gittr.com/#deployment) that you should review before running your RhoConnect application in production. We recommend using the [phusion passenger](http://modrails.com/index.html) stack for deploying an on-premise RhoConnect application. Please refer to the [section on rack applications](http://modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_rack_based_ruby_application) for information on deploying a RhoConnect sinatra application. ## Deploying packaged RhoConnect software on Linux servers You can create RhoConnect production environment on Linux servers by installing software packages for Ubuntu and CentOS respectively. At this moment supported formats are Debian (deb) and Red Hat (rpm) packages. Every package provides the following components: * Ruby 1.9.3-p194 * Nginx HTTP server, release 1.2.x * Thin application server, release 1.3.1 * Redis data store, release 2.4.x * Latest RhoConnect gem with all required dependencies In addition, RPM package provides latest sqlite3 headers and binaries, because standard Cent OS (5.x) libraries for sqlite3 outdated. ### Getting the Packages To download the RhoConnect debian package, you first must add our repo to your list of sources. #### Steps for Debian-Based Linux Users Add the following line to the end of your /etc/apt/sources.list: :::text deb http://rhoconnect.s3.amazonaws.com/packages/deb rhoconnect main Once the repo is added apt-get needs to be updated: :::term $ sudo apt-get update Once that is done, it is time to install RhoConnect: :::term $ sudo apt-get install rhoconnect #### Steps for RedHat-Based Linux Users Vanilla CentOS distribution does not include some packages required by RhoConnect installer. To resolve dependencies you might wanted to use either [RPMForge](http://wiki.centos.org/AdditionalResources/Repositories/RPMForge) or [Extra Packages for Enterprise Linux (EPEL) ](http://fedoraproject.org/wiki/EPEL) repository. For example, to add rpmforge repository for CentOS 5.8 release and x86_64 architecture execute this command: :::term $ wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm; rpm -Uhv rpmforge* For CentOS 6.2 release: :::term $ wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm; rpm -Uhv rpmforge* If you'd rather prefer EPEL repo, then run one of :::term $ wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm $ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm Now you can create a file named rhoconnect.repo in the /etc/yum.repos.d/ directory: :::term $ sudo vim /etc/yum.repos.d/rhoconnect.repo Copy and paste these contents into the file. :::text [rhoconnect] name=Rhoconnect baseurl=http://rhoconnect.s3.amazonaws.com/packages/rpm enabled=1 gpgcheck=0 Once that is done, it is time to install RhoConnect: :::term $ sudo yum install rhoconnect ### Final Steps (After the installer is finished) Installer also created and configured RhoConnect rhoapp application in /opt/nginx/html directory. To test it you need to as a root user start redis, nginx, and thin servers: :::term $ sudo /etc/init.d/redis start $ sudo /etc/init.d/nginx start $ sudo /etc/init.d/thin start And verify that it's up and running by visiting application web console in your browser: http://servername ### Web and application servers configuration Installer compiled and configured Nginx as reverse proxy web server (/opt/nginx) with the following settings: * Nginx start-up script (/etc/init.d/nginx) * Nginx logrotate settings (/etc/logrotate.d/nginx) * Nginx configuration file (/opt/nginx/conf/nginx.conf) * virtual host template for rhoconnect application (/opt/nginx/conf/conf.d/rhoconnect.conf) Installer also configured Thin app server with the following configuration files: * Thin start-up script (/etc/init.d/thin) * Thin configuration file (/etc/thin/rhoapp.yml) Default setup of Nginx server is to deal with back-end servers (called "upstreams") that are running on UNIX domain sockets: :::text # /opt/nginx/conf/conf.d/rhoconnect.conf file upstream thin_cluster { server unix:/tmp/thin.0.sock; server unix:/tmp/thin.1.sock; #server unix:/tmp/thin.2.sock; #server unix:/tmp/thin.3.sock; } server { listen 80; root /opt/nginx/html/rhoapp/public; # <-- be sure to point to 'public' folder of your application! # ... } Thin application server runs as a cluster with /etc/thin/rhoapp.yml configuration file: :::yaml --- chdir: /opt/nginx/html/rhoapp environment: production timeout: 30 log: /opt/nginx/logs/thin.log pid: /var/run/thin.pid max_conns: 1024 max_persistent_conns: 512 require: [] wait: 30 socket: /tmp/thin.sock servers: 2 daemonize: true Configuration file is generated by this command: :::term $ thin config -C /etc/thin/rhoapp.yml -c /opt/nginx/html/rhoapp/ --socket /tmp/thin.sock --servers 2 --log /opt/nginx/logs/thin.log --pid /var/run/thin.pid -e production ## Deploying into J2EE environment In JRuby environment, there is an option to create the WAR container for the RhoConnect app and deploy it into the J2EE App Server. (see the corresponding 'rake' task for creating the WAR containers). Deploying the WAR container varies per J2EE App Server, for JBoss it is necessary to place the WAR file into the server's deploy directory. * Rhoconnect gem version >= 3.2.0 #### Create Rhoconnect application Create your Rhoconnect app and make sure that it's up and running in your development environment using thin: :::term $ cd your_rhoconnect_app $ bundle exec thin start #### Declare `Procfile` This step is optional, but it will give you more control and flexibility when application deployed on Heroku. Create in your rhoconnect project file named `Procfile`: :::term web: bundle exec thin start -p $PORT If your application is using resque worker, then you should specify it in the `Procfile` as well: :::term web: bundle exec thin start -p $PORT worker: bundle exec rake resque:work Now you can run your app locally :::term $ gem install foreman $ foreman start #### Deploy to Heroku Before moving your code to Git you need comment in your project's `Gemfile` declaration of `sqlite3` gem, because target Heroku server has no devel libraries required to build that gem. :::term $ git init $ git add . $ git commit -m ' ... ' $ heroku create --stack cedar $ heroku addons:add redistogo:nano $ git push heroku master $ heroku open #### Monitoring app on Heroku Use `heroku ps` to determine the number of processes that are executing. Use `heroku logs` to view an aggregated list of log messages from all process types. :::term $ heroku ps $ heroku logs #### Get connected with Rhodes client If you have rhodes client and wanted to sync it with rhoconnect app on Heroku, then set proper sync server URL in `rhoconfig.txt` file :::term syncserver = 'http://.herokuapp.com/application'