Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Using capistrano nginx unicorn to deploy Sinatra apps

Tom Wilson edited this page Jun 25, 2014 · 2 revisions

Using capistrano-nginx-unicorn to deploy Sinatra apps

(This info is based on version 0.1.0)

Summary:

This Gem works fine to deploy Sinatra apps as well as Rails apps, without modification. There are only a few minor references to Rails in this Gem, and none of them conflict with a Sinatra deployment:

  • The :rails_env setting is confusing for non-Rails apps, but if you just use this to set your Sinatra/Rack environment, it actually works anyway.
  • The instructions to use the rails generator to create custom templates won't work without Rails, but it's easy to do it manually.

About the :rails_env setting

The value used for :rails_env is fed right into the "-E" argument for unicorn. See the unicorn_init.rb template for details. So all you have to do is the usual set :rails_env, 'production' and it sets the right environment even if you are not using Rails. The only "con" is that it will be forever confusing when you go back to review the code.

If you really care that the environment setting looks "right", you could:

  1. change your config files from: set :rails_env, 'production' to set :environment, 'production', and
  2. create a custom version of the unicorn_init.rb template and change this: -E <%= fetch(:rails_env) %> to this: -E <%= fetch(:environment) %> to pick up the environment value.

But it's easier to simply add an explanatory comment where you set set :rails_env, 'production' in your config files.

Generating custom templates without the Rails generator

If you're not using Rails, the "rails generate" command won't be available. That's OK, because all the generator does is copy the template files from the gem to your app's config/deploy/templates directory.

I think the simplest way to do this is to manually create the templates directory and copy the files right from github. (Because depending on your setup, it can be a pain to find the correct local source for the installed Gem.) Templates are at capistrano-nginx-unicorn / lib / generators / capistrano / nginx_unicorn / templates /.

Make sure you access the branch/version of the capistrano-nginx-unicorn repo that matches the version of the Gem you are using.