Ruby on Rails on Flex Servers

Ruby on Rails is a framework for developing web applications in Ruby. We offer the latest Ruby versions for your Managed Flex Server. We regularly update these versions.
This guide explains how you can run a Ruby on Rails application on your Managed Flex Server.

Requirements

Ruby on Rails applications can be run on Managed Flex Server M and higher.

Building a Ruby on Rails application

This guide explains how to build a simple “Hello World” application that shows the default landing page for Ruby on Rails.

We recommend creating an ~/app/ directory for your own applications and then creating a subdirectory for each of your applications. This way, everything will always be neat and tidy. So, for the Rails application, we will create the directory ~/app/railstest and navigate to this directory:

mkdir ~/app/railstest
cd ~/app/railstest

Now set up the necessary structure for your application in the application directory ~/app/railstest you just created. In this example, we will set up a simple Rails project.

To install Rails and find it again later, execute the following commands:

mkdir -p ~/.gem
echo 'export PATH=$PATH:$(ruby -e "puts Gem.user_dir")/bin' >> ~/.profile
echo 'export GEM_HOME=$(ruby -e "puts Gem.user_dir") ' >> ~/.profile
source ~/.profile

Then you can install Rails:

gem install --no-document rails
rails new .

The option --no-document skips the installation of additional documentation, speeding up the installation process.

Finally, you need to configure Rails to accept your domain.

To do this, edit the file ~/app/railstest/config/environments/development.rb and add the following line before the last "end".

config.hosts << "your-own-domain.ch"

Integration

Using Custom Service Control

The Custom Service Control (CSC) can handle operations and the automatic management of your application, e.g. starting and stopping it when performing maintenance on your server.

Configuring the Rails helloworld app in the CSC is fairly simple. Set up a new custom service for the Rails application:

hpservices supervisord add railstest

A configuration framework is created in the file ~/.services/supervisord/railstest/service.conf for the new service. For the Rails application, the command has to be modified and the environment variable included as well. You can leave all other suggested values alone (delete the semicolon at the beginning of the line).

~/.services/supervisord/railstest/service.conf
[program:railstest]
command=%(ENV_HOME)s/app/railstest/bin/rails server -p 8080  ; the program (can take args)
directory=%(ENV_HOME)s/app/railstest/       ; directory to cwd to before exec (default no cwd)
autostart=true                ; start application at supervisord start (default: true)
stopwaitsecs=10               ; max num secs to wait before SIGKILL (default 10)
stdout_logfile=%(ENV_HOME)s/.services/supervisord/railstest/log/default.log
stdout_logfile_maxbytes=1MB   ; filesize at which to rotate logfiles (default ist 50MB)
stdout_logfile_backups=10     ; number of stdout logfile backups (0 means none, default 10)
stderr_logfile=%(ENV_HOME)s/.services/supervisord/railstest/log/default.err
stderr_logfile_maxbytes=1MB   ; filesize at which to rotate logfiles (default is 50MB)
stderr_logfile_backups=10     ; number of stderr logfile backups (0 means none, default 10)
environment=PATH="/usr/local/bin:/usr/bin:/bin:%(ENV_HOME)s/.gem/bin",GEM_HOME="%(ENV_HOME)s/.gem";

Production mode

In this example, the server will be started in developer mode. However, in your final application, you should use production mode by setting the environment variable RAILS_ENV=production.

You can apply the new configuration for your Rails application with supervisorctl update:

supervisorctl update
railstest: added process group

Attention: If you receive an error, you must uniquely execute before "hpservices supervisord start".

For more detailed information on working with CSC and the options it offers, refer to the guide for Custom Service Control.

Web server configuration

If you now want to make your application accessible via HTTP(S), you must configure your website in the Hostpoint Control Panel so that the web server will route requests to your application via proxy.

In your Hostpoint Control Panel, create a website of the type «Nginx proxy for own application»:

RubyOnRails EN

Server address and port
The proxy function expects that your application will be listening to the IPv4 loopback address 127.0.0.1, meaning that you only have to enter the port: 8080.

Additional information

 

 

Unable to find what you were looking for?

Our support experts are happy to assist you personally!

 

© 2001 - Hostpoint AG