Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm deploying a simple Rails app to this small ubuntu precise64 server setup :
* 1 server running nginx
* 2 servers running unicorn
* 1 server running postgresql

My servers are provisionned with Puppet and I'm pushing the app with capistrano.

My Capfile

load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks

The deploy.rb file is super simple

# Execute "bundle install" after deploy, but only when really needed
require "bundler/capistrano"

# Name of the application in scm (GIT)
set :application, "devops-test-app"
set :repository, ""
set :scm, :git

set :deploy_to, "/var/www/#{application}"

# server there the web server is running (nginx)
role :web, ""

# server there the db is running
# This is where Rails migrations will run
role :db, "", :primary => true

# servers there the app servers are running (unicorn)
role :app, "", ""

set :rails_env, :production

# user on the server
set :user, "deployer"
set :use_sudo, false

namespace :deploy do 
  task :start, :roles => :app, :except => { :no_release => true } do
    run "service unicorn_#{application} start"

  task :stop, :roles => :app, :except => { :no_release => true } do
    run "service unicorn_#{application} stop"

  task :restart, :roles => :app, :except => { :no_release => true } do
    run "service unicorn_#{application} restart"

  task :copy_in_database_yml do
    run "cp #{shared_path}/config/database.yml #{latest_release}/config/"

  # Precompile assets
  # I have to precompile the assets on the app servers too, and I don't really know why...
  # namespace :assets do
  #   task :precompile, :roles => [:web, :app], :except => { :no_release => true } do
  #     run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
  #   end
  # end

before "deploy:assets:precompile", "deploy:copy_in_database_yml"

If I don't precompile assets on the app servers, the application fails.

$ cap ROLES="app" COMMAND="cat /var/www/devops-test-app/current/log/production.log" invoke
  * 2013-05-01 21:43:10 executing `invoke'
  * executing "cat /var/www/devops-test-app/current/log/production.log"
    servers: ["", ""]
    [] executing command
 ** [out ::] Connecting to database specified by database.yml
 ** [out ::] Connecting to database specified by database.yml
 ** [out ::] Started GET "/posts" for at 2013-05-01 19:42:10 +0000
 ** [out ::] Processing by PostsController#index as HTML
 ** [out ::] Rendered posts/index.html.erb within layouts/application (25.7ms)
 ** [out ::] Completed 500 Internal Server Error in 122ms
 ** [out ::] 
 ** [out ::] ActionView::Template::Error (application.css isn't precompiled):
 ** [out ::] 2: <html>
 ** [out ::] 3: <head>
 ** [out ::] 4:   <title>DevopsTestApp</title>
 ** [out ::] 5:   <%= stylesheet_link_tag    "application", :media => "all" %>
 ** [out ::] 6:   <%= javascript_include_tag "application" %>
 ** [out ::] 7:   <%= csrf_meta_tags %>
 ** [out ::] 8: </head>
 ** [out ::] app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__677166568443748084_17536100'
 ** [out ::] app/controllers/posts_controller.rb:7:in `index'

If I uncomment the commented lines in deploy.rb, everything is fine.

But why ?? I thought you would need to compile the assets only on the web server, not on the app server.

Please help me understand why :)

Thanks, best regards


share|improve this question
I hope you aren't actually using those IP addresses, or the US Department of Defense may become unhappy with you, since they're assigned to the DoD... – Michael Hampton May 1 '13 at 19:49
oooops, didn't know that, this is a local setup (running on vagrant) – geoffroy May 1 '13 at 20:13
There are IP addresses reserved for private networks already. See RFC 1918 for the complete list. – Michael Hampton May 1 '13 at 20:16
thanks ! I just took the trick from the book Deploying Rails, not to interfere with my local network. But I will use addresses from now. Best – geoffroy May 1 '13 at 20:25
That crap actually got into print?! Take your copy and beat the author over the head with it. :) – Michael Hampton May 1 '13 at 20:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.