Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

Deploying a RhoConnect Application

Deploying On-Premise

The sinatra book has some great deployment documentation that you should review before running your RhoConnect application in production.

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-p374

  • Nginx HTTP server, release 1.2.x

  • Thin application server, release 1.3.1

  • Redis data store, release 2.6.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:

deb http://rhoconnect.s3.amazonaws.com/packages/deb rhoconnect main

Once the repo is added apt-get needs to be updated:

$ sudo apt-get update

Once that is done, it is time to install RhoConnect:

$ 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 or Extra Packages for Enterprise Linux (EPEL) repository.

For example, to add rpmforge repository for CentOS 5.8 release and x86_64 architecture execute this command:

$ 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:

$ 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

$ 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:

$ sudo vim /etc/yum.repos.d/rhoconnect.repo

Copy and paste these contents into the file.

[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:

$ 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:

$ 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

Configuration of web and application servers

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:

# /opt/nginx/conf/conf.d/rhoconnect.conf file

upstream thin_cluster {
  least_conn;
  server unix:/tmp/thin.0.sock;
  server unix:/tmp/thin.1.sock;
  # Add additional copies if need more Thin servers
  #server unix:/tmp/thin.2.sock;
  #server unix:/tmp/thin.3.sock;
}

server {
  listen      80;
  # Be sure to point to 'public' folder of your application!
  root  /opt/nginx/html/rhoapp/public;
  # ...

}

Thin application server runs as a cluster with /etc/thin/rhoapp.yml configuration file:

---
chdir: /opt/nginx/html/rhoapp
environment: production
timeout: 30
log: /var/log/thin/thin.log
pid: /var/run/thin/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:

$ thin config -C /etc/thin/rhoapp.yml -c /opt/nginx/html/rhoapp/ --socket /tmp/thin.sock --servers 2 --log /var/log/thin/thin.log --pid /var/run/thin/thin.pid -e production

Development and deployment of RhoConnect applications

Packaged software does not setup automatically path to installed ruby bins and gems, so you need do it manually. Add necessary bins to the path(s) of the users who will be using this software. You may also wish to add these items to your bash scripts (i.e. ~/.profile on Ubuntu; ~/.bash_profile on CentOS) to automatically add them upon login.

export PATH=/opt/rhoconnect/bin:$PATH

Deploying a rhoconnect app

To deploy and develop your rhoconnect app on nginx and thin servers

a) Copy your rhoconnect project (lets name it as your_rhoconnect_app) to default location to /opt/nginx/html directory

b) Set up for it nginx owner

$ cd /opt/nginx/html
$ sudo chown -R nginx:nginx your_rhoconnect_app/

c) Make sure that your app is bundled properly

$ cd your_rhoconnect_app
$ sudo /opt/rhoconnect/bin/bundle install

d) Configure Nginx virtual host for your rhoconnect application. For that edit the file /opt/nginx/conf/conf.d/rhoconnect.conf, so that it reflects your specifications (root directive)

# ...
server {
  listen      80;
  # Be sure your app have 'public' folder and root directive
  # point to it!
  root  /opt/nginx/html/your_rhoconnect_app/public;
  # ...
}

e) Edit Thin /etc/thin/rhoapp.yml configuration file directly

---
chdir: /opt/nginx/html/your_rhoconnect_app
# ...

or as root user generate a new one

$ env PATH=/opt/rhoconnect/bin:$PATH thin config -C /etc/thin/your_rhoconnect_app.yml \
-c /opt/nginx/html/your_rhoconnect_app/ \
--socket /tmp/thin.sock --servers 2 --log /var/log/thin/thin.log \
--user nginx --group nginx \
--pid /var/run/thin/thin.pid -e production

f) As root user restart Nginx, and Thin servers

/etc/init.d/nginx restart
/etc/init.d/thin restart

Deploying multiple RhoConnect apps

Note: Deploying multiple RhoConnect apps on nginx has not yet been tested. Perform these steps only if you are experienced with nginx.

To deploy and develop two RhoConnect applications on nginx and thin servers, refer to the nginx documentation on nginx server blocks to see how to configure an nginx sever for multiple host names.

For each RhoConnect app, you need to set up its own redis instance. Refer to the redis quick start documentation.

If you have questions on setting this up, contact your system administrator.

Monitoring and Logging

For monitoring and troubleshooting purposes visit web console of your app and look at log files in /opt/nginx/logs.

Also you can use RhoConnect /opt/nginx/html/rhoapp application as a template and modify it as you wanted.

Note: You should pay attentions to situations, if you have already Ruby installed on system level. Avoid usage of system gems in your application. It might lead to unpredictable results, if ruby versions are different. Either set up path to RhoConnect binaries for root user, or install required gems as sudo /opt/rhoconnect/bin/gem install gem_name

Deploying RhoConnect Redis and Push packages on Linux servers

RhoConnect Redis

RhoConnect Redis is a packaged Redis server for RhoConnect development and production environment on Linux servers. rhoconnect-redis package might be useful if you want to deploy Redis on separate server.

The package compiles from sources latest stable Redis release (2.4.15) and installs it to /opt/rhoconnect directory with the following settings:

  • Redis server configuration file (/opt/rhoconnect/etc/redis.conf)

  • log files located in /var/log/redis directory

  • start-up scripts in /etc/init and /etc/init.d directories

Steps for Debian-Based Linux Users

Add the following line to the end of your /etc/apt/sources.list.

deb http://rhoconnect-repo.s3.amazonaws.com/packages/deb rhoconnect-repo main

Then update the repo list and install RhoConnect Redis.

$ sudo apt-get update
$ sudo apt-get install rhoconnect-redis

When Redis server is successfully installed, start it using the following command.

$ sudo start rhoconnect-redis

Steps for RedHat-Based Linux Users

Create a file named rhoconnect-repo.repo in the /etc/yum.repos.d/ directory.

$ sudo nano /etc/yum.repos.d/rhoconnect-repo.repo

Copy and paste these contents into the file.

[rhoconnect-redis]
name=Rhoconnect Redis
baseurl=http://rhoconnect-repo.s3.amazonaws.com/packages/rpm
enabled=1
gpgcheck=0

Once that is done, install the RhoConnect Push service.

$ sudo yum install rhoconnect-redis

You can start a redis server using the following command.

$ sudo /etc/init.d/redis start

RhoConnect Push Service

You can create a RhoConnect Push production environment on Linux servers by installing prepackaged software for Ubuntu (12.x) and CentOS (5.x/6.x). In a few clicks, you will have installed on your Linux server.

  • Node.js with Npm package manager

  • RhoConnect Push service

  • Upstart script to start, stop, and control Push service (for Ubuntu and CentOS 6.x)

  • /etc/init.d/rhoconnect-push init script to start, stop, and restart Push service (CentOS 5.x)

Prerequisites:

* Python 2.6 or 2.7

Steps for Debian-Based Linux Users

Add the following line to the end of your /etc/apt/sources.list.

deb http://rhoconnect-repo.s3.amazonaws.com/packages/deb rhoconnect-repo main

Then update the repo list and install RhoConnect Push.

$ sudo apt-get update
$ sudo apt-get install rhoconnect-push

Steps for RedHat-Based Linux Users

Node.js requires python 2.6 which is not available for CentOS 5 stock version. For this flavor of linux you need to manually install EPEL repo and install python26 RPM out of it:

$ wget http://mirror.chpc.utah.edu/pub/epel/5/i386/epel-release-5-4.noarch.rpm
$ rpm -i epel-release-5-4.noarch.rpm 
$ yum install python26

Now create a file named rhoconnect-repo.repo in the /etc/yum.repos.d/ directory.

$ sudo nano /etc/yum.repos.d/rhoconnect-repo.repo

Copy and paste the following contents into the file.

[rhoconnect-push]
name=Rhoconnect Push Service
baseurl=http://rhoconnect-repo.s3.amazonaws.com/packages/rpm
enabled=1
gpgcheck=0

Once that is done, install the RhoConnect Push service.

$ sudo yum install rhoconnect-push

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.

Deploying on Heroku Cedar

Prerequisites

Create Rhoconnect application

Create your Rhoconnect app and make sure that it’s up and running in your development environment using thin:

$ 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:

web: bundle exec thin start -p $PORT

If your application is using resque worker, then you should specify it in the Procfile as well:

web: bundle exec thin start -p $PORT
worker: bundle exec rake resque:work

Now you can run your app locally:

$ 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 development libraries required to build that gem.

$ 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.

$ heroku ps
$ heroku logs

Get connected with Rhodes client

If you have a rhodes client and wanted to sync it with rhoconnect app on Heroku, then set proper syncserver URL in rhoconfig.txt file:

syncserver = 'http://<your-heroku-app-here>.herokuapp.com/application'
Back to Top