Table of Contents
Ruby instance family
The Ruby instance family on Simple Hosting is a perfect solution to host web applications.
You can publish any web application that uses Rack, including Ruby On Rails and Sinatra applications, coupled with the database of your choice.
The extensible storage space and multiple sizes make it easy and affordable to get started and grow your application over time.
Prerequisites
Users of Ruby Simple Hosting instances should have:
- some knowledge of the Ruby language
- some knowledge of git
- an application which is compatible with Ruby 2.4 (MRI) or 1.9.3 in old instances
- an application which is compatible with Rack
- an application which uses Bundler to manage dependencies
- the following installed locally:
- ruby
- bundler
- git
Note: Usage of the Ruby instance is dependent on standard tools such as bundler and git being installed locally.
Directory structure
To be compatible with Rack, your application's files must adhere to a specific layout, containing the following directories and files:
config.ru
: A Rackup file like the one specified in the Rack documentationpublic/
: If you have any static files, they should be in this directory
Ruby on Rails applications (rails >2) should work out of the box.
Example file structure:
. ├── config.ru └── public └── robots.txt
Installation of dependencies
In order for your Ruby application's dependencies to be installed, you must declare them in a Gemfile placed at the root of your project. This file must match the format indicated in the Bundler documentation.
Example Gemfile:
source 'https://rubygems.org' gem 'rails', '~> 4.0.0' gem 'debugger', group: :development
Note: During the installation of dependencies, the gems specified in the development
and test
groups will not be installed.
bundle install
Once your dependencies have been declared, you must generate a Gemfile.lock
file by running the bundle install
command. This is the file that will be used to install the dependencies on your instance.
Configuring Multiple Vhosts
If you would like for multiple vhosts to route to different Ruby applications on a single Simple Hosting instance, then you will need to configure the routing in the config.ru file.
A simple config.ru example below:
map 'http://www.example.com/' do run Proc.new { |env| [200, {'Content-Type' => 'text/html; charset="utf-8"'}, ['<!DOCTYPE html><html><meta charset="utf-8"><title>It works', "</title><b>It works!</b><br /><br />You've reached ", 'www.example.com' ] ] } end map 'http://www.another-example.com/' do run Proc.new { |env| [200, {'Content-Type' => 'text/html; charset="utf-8"'}, ['<!DOCTYPE html><html><meta charset="utf-8"><title>It works', "</title><b>It works!</b><br /><br />You've reached ", 'www.another-example.com' ] ] } end
Databases
Like the other Simple Hosting instance families, Ruby instances support three types of databases: MySQL, PostgreSQL and MongoDB.
PostgreSQL
Parameters:
- Hostname: localhost
- Port: 5432
Here's an example Ruby on Rails configuration with a PostreSQL database (config/database.yml
):
production: adapter: postgresql database: ruby-example host: localhost port: 5432 username: hosting-db password: encoding: unicode pool: 5
MySQL
Parameters:
- Socket : /srv/run/mysqld/mysqld.sock
Here's an example Ruby on Rails configuration with a MySQL database (config/database.yml
):
production: adapter: mysql2 database: ruby-example socket: /srv/run/mysqld/mysqld.sock username: tony password: micelli encoding: utf-8 pool: 5
MongoDB
Parameters:
- Hostname: localhost
- Port: 27017
Here's an example Mongoid configuration (mongoid.yml
):
production: sessions: default: database: ruby-example hosts: - localhost:27017
Pushing your application to your instance
You must use git to push your application to your instance and to deploy it.
Create a local git repository
First, in the root directory of your project on your local machine, run the following commands to initialize a Git repo to track your code's changes:
$ git init $ git add . $ git commit -m "Initial commit"
Deployment of your application
Once your code is tracked by git locally, you must push it to your instance.
In the command below, replace INSTANCE_ID
with your instance ID, and and DC_ID
with the ID of the datacenter where your instance lives (dc0
for Paris, dc1
for Baltimore, dc2
for Luxembourg):
$ git remote add gandi git+ssh://INSTANCE_ID@git.DC_ID.gpaas.net/default.git $ git push gandi master
Then, run the deploy command:
$ ssh INSTANCE_ID@git.DC_ID.gpaas.net deploy default.git
$ ssh INSTANCE_ID@git.DC_ID.gpaas.net deploy default.git production
Logs and troubleshooting
Standard output (stdout) as well as errors related to the application's execution are stored in the following logfiles on your instance's data disk:
- via SSH:
/srv/data/var/log/www/uwsgi.log
- via SFTP:
/lamp0/var/log/www/uwsgi.log
This is useful, notably, for verifying that your application has started correctly.
Cron jobs
Like other Simple Hosting instance families, it's possible to run scheduled tasks (cron jobs) on Ruby instances. Environment variables defined by your application are also available in your cron jobs (see internal_design for more details on environment variables).
Example cron job:
1@hourly 0 test (cd /srv/data/web/vhosts/default; rake my_namespace:some_useful_task)
For more information on cron jobs and Simple Hosting, see http://wiki.gandi.net/en/simple/anacron.
Internal design
Ruby instances use Uwsgi to execute your application's code. Apache is used to serve static files. Apache will serve the files that exist in a directory named public/
at the root of your project and will relay all other requests to Uwsgi.
The following environment variables are assigned and available in your application and in cron jobs:
- RAILS_ENV=production
- RACK_ENV=production
Additional information
Redis is not currently supported on Simple Hosting. If you'd like to see redis support, let us know on our wishlist.