1. Introduction
WebROaR is an application server that makes deployments of ruby web applications extremely simple. It provides an integrated solution to view the run time performance numbers and sends email notifications in case any exceptions occur in any of the deployed applications.
It is 5 to 55% faster than all other comparable deployment stacks for Ruby on Rails applications.
1.1. Key Features
-
Maximum Performance.
-
Simplified Deployment.
-
Runs Ruby on Rails™ as well as other Rack compliant applications.
-
Run Multiple Applications Simultaneously.
-
Implements HTTP/1.1 grammar as per RFC 2616 including support for persistent, and chunked requests.
-
Intelligent load balancing and dynamic reaping of stuck ruby processing instances.
-
Provides run time performance data for the deployed applications.
-
Generates notifications in case any exceptions occur in any of the deployed applications.
-
Zero Downtime Application Upgrades.
-
Static assets encoding.
-
SSL support.
2. Supported Operating Systems
WebROaR has been tested on Ubuntu 8.10/9.04/9.10/10.04, Debian 5 (64 Bit), Mac OS X (v10.5 & v10.6), Arch Linux 2009.08 and Cent OS 5.2. Basically, it should be able to run on any *IX OS.
Currently it does not support Microsoft® Windows.
3. Install
3.1. Prerequisites
-
ruby 1.8.x or 1.9.x
-
ruby 1.8-dev or 1.9-dev
-
openssl ruby extension (On Ubuntu/Debian it is available as libopenssl-ruby1.X)
-
zlib ruby extension
-
rubygems
-
C build tools (gcc etc) (e.g. build-essential on Ubuntu, Xcode on MacOS)
-
libsqlite3
-
libsqlite3-dev
-
gnutls 2.4.1 or later (Only necessary in case SSL support is required)
-
gnutls-dev 2.4.1 or later (Only necessary in case SSL support is required)
3.2. Procedure
WebROaR can be installed through its gem or directly from its source code. One can also use Capistrano to perform a non-interactive installation of the server.
3.2.1. Install using gem
WebROaR can be installed using the following commands:
sudo gem install webroar sudo webroar install
|
|
SSL Support
In case you would like to setup SSL support for the server, use the following command line switch with sudo webroar install command mentioned above. sudo webroar install --ssl-support Configure further SSL options in the server’s admin panel http://<yourservername>:<port>/admin-panel/configuration After restarting the server, admin panel would now also be accessible over SSL. https://<yourservername>:<port>/admin-panel |
3.2.2. Install from source code
If you like living in the fast lane, you can install the edge version giving the following commands:
git clone git://github.com/webroar/webroar.git cd webroar sudo rake install
|
|
SSL Support
To build with SSL support, use the following additional switch with the sudo rake install command: sudo rake install ssl=yes Configure further SSL options in the server’s admin panel http://<yourservername>:<port>/admin-panel/configuration After restarting the server, admin panel would now also be accessible over SSL. https://<yourservername>:<port>/admin-panel |
3.2.3. Non-Interactive Install using Capistrano
You can use following Capistrano script to install the edge version on a remote machine
-
Create folder <dir>, move to <dir> folder using cd <dir>.
-
Apply command capify .
-
Replace the content of config/deploy.rb with the following script
set :application, "WebROaR" set :repository, "git://github.com/webroar/webroar.git" set :scm, :git ############################################# # WebROaR installation parameters # ############################################# # Instead of asking for admin user name, password and port you can directly set # it from here. set :user, 'username' set :port, 22 set(:password) { Capistrano::CLI.password_prompt("Enter ssh password for \ #{user}: ") } set :use_sudo, false set :deploy_to, "path-to-deploy-webroar" set(:webroar_admin_username) { Capistrano::CLI.ui.ask("Please enter a username \ for the administrator account of server's admin panel:") } set(:webroar_admin_password) { Capistrano::CLI.password_prompt("Please enter a \ password(minimum 6 characters) for the administrator account of server's admin \ panel:") } set(:webroar_port) { Capistrano::CLI.ui.ask("Enter server port \ (default is 3000):") } set :webroar_import_configuration, true # set false to beging with fresh install set :webroar_ssl_support, false # set true to Build webroar with SSL support role :web, "server" # Your HTTP server, Apache/etc role :app, "server" # This may be the same as your `Web` server role :db, "server", :primary => true # This is where Rails migrations will run ############################################ namespace :deploy do # hook into capistrano's deploy task after 'deploy:update_code', 'deploy:webroar:install' task :finalize_update, :except => { :no_release => true } do run "chmod -R g+w #{release_path}" if fetch(:group_writable, true) end namespace :webroar do desc "Uninstall the webroar gem" task :uninstall do run "#{sudo} webroar uninstall; #{sudo} gem uninstall -ax webroar" end desc "Install the server" task :install, :roles => :app do run "cd #{release_path}; #{sudo} rake install #{'ssl=on' if \ webroar_ssl_support}", :pty=>true do |ch, stream, out| next if out.chomp == '' logger.important out, ch[:server] case out when / least/ raise Capistrano::Error, out when />/ ch.send_data("#{webroar_import_configuration ? '1' : '2'}\n") when / username/ ch.send_data("#{webroar_admin_username}\n") when / password/ ch.send_data("#{webroar_admin_password}\n") when / port/ ch.send_data("#{webroar_port}\n") end end end desc "Start, Stop and Restat the server" %w(start stop restart).each do |name| task name.to_sym,:roles => :app do run "#{sudo} webroar #{name}" #Manual Configuration required, this is best effort. end end end end -
Set the variables in config/deploy.rb file.
-
To setup the fresh directory structure on the remote machine run cap deploy:setup
-
To deploy the application for the first time run cap deploy:cold (Steps 1-6 are to be followed only once to create directory setup on remote machine.)
-
Update the current version with the latest code from github using cap deploy:update.
3.3. Troubleshooting
|
|
It is suggested that rubygems software should be setup correctly beforehand, and you should be successfully able to access and use the already installed gems. (If you use Ubuntu, you might be able to relate to this point better.) |
-
In case auto-installation of dependent gems fails (due to some prehistoric rubygems version or any other reason), you can install the following dependent gems individually first:
calendar_date_select, rack, rake, rspec, sqlite3-ruby, starling, will_paginate
-
After successful installation of the webroar gem, any errors that occur during the setup are saved to the install.log created in the installed gem’s directory. This can be used to troubleshoot the issues, if any.
-
All run time logs for the server and the deployed applications can be found in /var/log/webroar. In the unfortunate event of the server crashing, a core dump file would be created in /tmp if gcore is available on that machine.
3.4. Know Issue
-
WebROaR with SSL build crashes on Ubuntu 10.04 upon execution of gnutls_handshake by secure connection.
3.5. Setting up database for server admin panel
The server’s admin panel itself is a Ruby on Rails™ web application, and by default uses sqlite as it’s database. You can edit admin_panel/config/database.yml to setup a database of your liking and follow it up by running these commands from the admin_panel directory.
rake db:create rake db:migrate
admin_panel directory would be present under the server’s rubygem directory.
4. Usage
Start/Stop/Restart WebROaR:
sudo webroar start sudo webroar stop sudo webroar restart
Start/Stop/Restart a deployed application:
sudo webroar start <Application Name> sudo webroar stop <Application Name> sudo webroar restart <Application Name>
|
|
You can stop the admin panel application of the server any time, to conserve resources and ensure better security. sudo webroar stop "Admin Panel" To start it whenever you want, use the following command: sudo webroar start "Admin Panel" Please note that analytics data and exceptions are still captured by the server even when the admin panel is stopped. |
5. Deploying applications
5.1. Deploy using Admin Panel
If the server got installed successfully, you should be able access it’s admin
panel using the link:
http://<yourservername>:<port>/admin-panel
You can log in with the administrator account username and password that you had entered during server installation. Deploy the ruby web application of your choice accessing the Configuration link of the admin panel.
|
|
You do "not" need to restart the server when you deploy a new application. The application starts up automatically after deployment. |
5.2. Deploy using Capistrano
WebROaR can be easily integrated with Capistrano using the following instructions.
After installing Capistrano, run the following command in your application’s root directory:
capify .
It would create Capfile and config/deploy.rb files. Modify config/deploy.rb file as shown below:
set :application, "myapp"
set :scm,:none
set :repository, "."
set :copy_cache, "/tmp/my-app"
set :copy_compression,:gzip
set :deploy_via,:copy
set :copy_exclude, [".git/*", "log/*", "Capfile", "config/deploy.rb", "*~", ".*"]
set :password, 'password'
set :use_sudo, false
set :user, 'username'
set :port, 22
set :deploy_to, "path-to-your-web-app-directory/#{application}"
################################
# Parameters used to add application to the server
################################
set :resolver, "/#{application.gsub(' ','_')}"
set :path, "#{deploy_to}/current"
set :app_type, "rails"
set :environment, "production"
set :analytics, "--analytics" # ' ' (blank) to disable analytics
set :min_workers, "4"
set :max_workers, "8"
set :run_as_user, "#{user}"
################################
role :app, "server"
role :web, "server"
role :db, "server", :primary => true
#role :db, "your slave db-server here"
namespace :deploy do
[:stop, :start, :restart].each do |action|
desc "#{action.to_s.capitalize} the application."
task action, :roles => :app do
run "#{sudo} webroar #{action.to_s} #{application.to_s}"
end
end
desc "Add application to the server"
task :add, :roles => :app do
run "#{sudo} webroar add '#{application}' --resolver'#{resolver}' \
--path'#{path}' -type'#{app_type}' -environment'#{environment}' #{analytics} \
--min-workers#{min_workers} --max-workers#{max_workers} \
--run-as-user'#{run_as_user}'"
end
desc "Remove application from the server"
task :remove, :roles => :app do
run "#{sudo} webroar remove '#{application}'"
end
end
after "deploy:update", "deploy:restart"
Create the application directory structure by running setup command:
cap deploy:setup
Deploy the application using command:
cap deploy
Add the application to WebROaR:
cap deploy:add
Please note that the application needs to be added to the server only once.
You can use the following commands for starting/stopping/restarting the application while upgrading it in the future:
cap deploy:stop cap deploy:start cap deploy:restart
5.3. Rack applications (other than Rails)
To deploy any Rack based application (other than Rails) the following are required in it’s root directory:
-
public folder containing static files like images and stylesheets
-
config.ru - the Rackup file for starting the application. This file must contain the complete logic for initializing the application.
Here are some examples of the Rackup files:
Merb
require 'rubygems'
require 'merb-core'
Merb::Config.setup(:merb_root => ENV['APP_ROOT'],
:environment => ENV['APP_ENV'],
:path_prefix => ENV['APP_BASE_URI'])
Merb.environment = Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
Merb::BootLoader.run
run Merb::Rack::Application.new
Sinatra
require 'rubygems' require 'rack' require 'sinatra' set :env, ENV['APP_ENV'] || :production set :raise_errors, true run Sinatra::Application
You can use following environment variables in config.ru to access the few application configuration parameters given at a time of application deployment in WebROaR.
-
ENV['APP_ROOT\'] - To get the application root
-
ENV['APP_ENV\'] - To get the application environment
-
ENV['APP_BASE_URI\'] - To get the baseuri
6. Accessing run time statistics
For those applications whose Analytics are Enabled in their configuration, the following graphs are available under the Analytics link of the admin panel.
-
URL Breakdown
-
Most Time Consuming URLs
-
URL Hits
-
Slowest URLs
-
Top Database Consuming URLs
-
Percentage Time Spent in Database Layer
-
Average Response Time
-
Peak Requests in Second
-
Percentage CPU Utilization
-
Physical Memory Utilization
Additionally, CPU and Physical Memory usage graphs for the entire server are also available.
|
|
Currently, Analytics are only supported for Ruby on Rails™ applications. Also, after a specific request has been processed by the server, it takes about a minute for it’s data to show up in the graphs. |
7. Exception Tracking and Notifications
Any exceptions that occur in any of the deployed application are captured by the server. An email notification is also sent out immediately with details of the exception, if the mail settings have been configured in the admin panel.
All the exceptions can be seen under the Exceptions link of the server admin panel.
|
|
Currently, this feature is only supported for Ruby on Rails™ applications. Also, it takes about a minute for an exception to show up in the Admin Panel after it has occurred. |
8. Uninstall
If you didn’t like the server, use the following commands in sequence to uninstall it.
sudo webroar uninstall sudo gem uninstall webroar
9. Test Suite
If you are a programmer and wish to play around with the server’s code, you might like to use it’s test suite to test the robustness of your changes.
It can be run using the following command:
sudo webroar test
We execute this suite on our nightly builds and it currently has the following tests:
-
Unit Tests
-
Functional Tests
-
Admin-Panel Tests
-
Load Test I - Continuous run
-
Load Test II - Random sleep interval run
-
Build Tests
10. Command Line Options
10.1. webroar help
WebROaR - Ruby Application Server
Usage:
webroar -h/--help
webroar -v/--version
webroar command [argument] [options...]
Examples:
webroar install
webroar help
Further help:
webroar help commands list all 'webroar' commands
webroar help <COMMAND> show help on COMMAND
10.2. webroar help commands
install Install the server
uninstall Uninstall the server
start [APPNAME] Start the server or an application
stop [APPNAME] Stop the server or an application
restart [APPNAME] Restart the server or an application
add APPNAME Deploy an application on server
remove APPNAME Remove an application from server
test Run the test suite
For help on a particular command, use 'webroar help COMMAND'.
10.3. webroar install
Usage:
webroar install [options]
Options:
-L Additional library paths to be used for linking of
the server
-I Additional include paths to be used for compiling of
the server
-s, --ssl-support Install the server with SSL support
-d, --debug-build Compile the server as a debug build to output
extremely verbose logs
The following options would make the install non-interactive by suppressing
the questions prompted by the installer
-P, --port Server port number
-i, --import Import configuration, logs and admin panel data from
the previous installation
--no-import Do not import configuration, logs and admin panel
data from the previous installation
-u, --username Username for the administrator account of server's
admin panel
-p, --password Password for the administrator account of server\'s
admin panel
Summary:
Install the server
10.4. webroar uninstall
Usage:
webroar uninstall
Summary:
Uninstall the server
10.5. webroar start
Usage:
webroar start [APPNAME ...]
Arguments:
APPNAME Name of the application
Summary:
Start the server or an application
Description:
'start' command without any arguments starts the server. One can start
multiple applications together by passing multiple names.
10.6. webroar stop
Usage:
webroar stop [APPNAME ...]
Arguments:
APPNAME Name of the application
Summary:
Stop the server or an application
Description:
'stop' command without any arguments stops the server. One can stop multiple
applications together by passing multiple names.
10.7. webroar restart
Usage:
webroar restart [APPNAME ...]
Arguments:
APPNAME Name of the application
Summary:
Restart the server or an application
Description:
'restart' command without any arguments restarts the server. One can restart
multiple applications together by passing multiple names.
10.8. webroar add
Usage:
webroar add APPNAME -R ... -D ... -U ... [options]
Arguments:
APPNAME Name of the application
Options:
-R, --resolver
Resolver to identify the application. Set it to '/' if you would like
to run the application on the root domain. e.g. http://yourserver:port/.
Else set the relevant base URI with which you would like to access the
application, e.g. '/app1' if you want the application to be accessible
via http://yourserver:port/app1.
If you would like to set a virtual host for your application e.g.
www.company1.com, please specify it here. You can also host this
application on a particular subdomain e.g. app1.company1.com.
Wildcard '*' can also be used in defining the virtual host name,
but it should only be used either at the start or the end. Prefix the
virtual host name with tilde(~), if a wildcard is used in defining it.
e.g. (i) ~*.server.com (ii) ~www.server.* (iii) ~*.server.*
-D, --path
Complete path for your application root directory: e.g.
/home/someuser/webapps/app1
-U, --run-as-user
Name of the user with whose privileges you would like to run the
application (root can be dangerous!). This user should have all the
necessary permissions to get your web application working properly
(e.g. write access on required files and directories etc)
The following parameters are optional
-T, --type
Type of the application either rack or rails (default: rails)
-E, --environment
Environment in which you want to run the application
(default: production)
-A, --analytics
Enable analytics to get detailed numbers about the run time
performance of the application. This number gathering adds a very
small overhead on your application
-N, --min-workers
Minimum number of worker processes that should run for this deployed
application. Multiple worker instances help in processing a higher
number of concurrent user requests simultaneously. The server would
always ensure at least these many worker processes run for this
application (default: 4)
-X, --max-workers
Maximum number of worker processes that should run for this deployed
application. Multiple worker instances help in processing a higher
number of concurrent user requests simultaneously. The server would
ensure that maximum only these many worker processes run for this
application (default: 8)
Summary:
Deploy (and start) a new application on the server.
10.9. webroar remove
Usage:
webroar remove APPNAME
Arguments:
APPNAME Name of the application
Summary:
Remove the specified application from the server.
10.10. webroar test
Usage:
webroar test [options]
Options:
-r, --report-dir DIR Report directory
-d, --debug-build Compile the server as a debug build to output
extremely verbose logs
-l, --load-test Also run the load tests
Summary:
Run the test suite