Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7654975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:23:37+00:00 2026-05-31T12:23:37+00:00

I followed the docs on cap + nginx + unicorn but have some problems

  • 0

I followed the docs on cap + nginx + unicorn but have some problems to understand how to do the database deployment correctly.

  • /config/database.yml should not be in the git repo ( preferable )
  • on production server in /shared/database.yml you place the database.yml
  • Problem is that on deploy it still looks for /config/database.yml

How can I make my deploy.rb grab the /shared/database.yml instead?
search high and low for this to no avail 🙁

deploy.rb

    # config/deploy.rb
require "bundler/capistrano"

set :scm, :git
set :repository, "root@109.etc:/srv/paintings.git"
set :branch, "origin/master"
set :migrate_target, :current
set :ssh_options, {:forward_agent => true}
set :rails_env, "production"
set :deploy_to, "/srv/paintings"
set :normalize_asset_timestamps, false

set :user, "root"
set :group, ""
set :use_sudo, true
default_run_options[:pty] = true

set :port, 5984
ssh_options[:port] = 5984


role :web, "109.etc"
role :app, "109.etc"
role :db, "109.etc", :primary => true

set(:latest_release) { fetch(:current_path) }
set(:release_path) { fetch(:current_path) }
set(:current_release) { fetch(:current_path) }

set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip }

default_environment["RAILS_ENV"] = 'production'

#default_environment["PATH"]         = "/bin/bash"
#default_environment["GEM_HOME"]     = "/usr/local/rvm/gems/ruby-1.9.3-p125"
#default_environment["GEM_PATH"]     = "/usr/local/rvm/gems/ruby-1.9.3-p125"
#default_environment["RUBY_VERSION"] = "ruby 1.9.3p125"
#default_run_options[:shell] = 'bash'

namespace :deploy do
  desc "Deploy your application"
  task :default do
    update
    restart
  end

  desc "Setup your git-based deployment app"
  task :setup, :except => {:no_release => true} do
    dirs = [deploy_to, shared_path]
    dirs += shared_children.map { |d| File.join(shared_path, d) }
    run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
    run "git clone #{repository} #{current_path}"
  end

  task :cold do
    update
    migrate
  end

  task :update do
    transaction do
      update_code
    end
  end

  desc "Update the deployed code."
  task :update_code, :except => {:no_release => true} do
    run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
    finalize_update
  end

  desc "Update the database (overwritten to avoid symlink)"
  task :migrations do
    transaction do
      update_code
    end
    migrate
    restart
  end

  task :finalize_update, :except => {:no_release => true} do
    run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)

    # mkdir -p is making sure that the directories are there for some SCM's that don't
    # save empty folders
    run <<-CMD
      rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &&
      mkdir -p #{latest_release}/public &&
      mkdir -p #{latest_release}/tmp &&
      ln -s #{shared_path}/log #{latest_release}/log &&
      ln -s #{shared_path}/system #{latest_release}/public/system &&
      ln -s #{shared_path}/pids #{latest_release}/tmp/pids
    CMD

    if fetch(:normalize_asset_timestamps, true)
      stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
      asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
      run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => {"TZ" => "UTC"}
    end
  end

  desc "Zero-downtime restart of Unicorn"
  task :restart, :except => {:no_release => true} do
    #run "kill -s USR2 'cat /srv/paintings/shared/pids/unicorn.pid'"
    run "kill -s USR2 'cat /srv/paintings/shared/tmp/unicorn.pid'"
  end

  desc "Start unicorn"
  task :start, :except => {:no_release => true} do
    run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D"
  end

  desc "Stop unicorn"
  task :stop, :except => {:no_release => true} do
    #run "kill -s QUIT 'cat /srv/paintings/shared/pids/unicorn.pid'"
    run "kill -s QUIT 'cat /tmp/unicorn.pid'"
  end

  namespace :rollback do
    desc "Moves the repo back to the previous version of HEAD"
    task :repo, :except => {:no_release => true} do
      set :branch, "HEAD@{1}"
      deploy.default
    end

    desc "Rewrite reflog so HEAD@{1} will continue to point to at the next previous release."
    task :cleanup, :except => {:no_release => true} do
      run "cd #{current_path}; git reflog delete --rewrite HEAD@{1}; git reflog delete --rewrite HEAD@{1}"
    end

    desc "Rolls back to the previously deployed version."
    task :default do
      rollback.repo
      rollback.cleanup
    end
  end
end

def run_rake(cmd)
  run "cd #{current_path}; #{rake} #{cmd}"
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:23:39+00:00Added an answer on May 31, 2026 at 12:23 pm

    I’m using a very similar deploy.rb, but I have one more symbolic link in my finalize_update method:

    ln -sf #{shared_path}/database.yml #{latest_release}/config/database.yml
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed numerous screen casts as well as trawled the backbone docs extensively
I have followed the Poll tutorial on http://docs.djangoproject.com . I would like to know
I have followed this tutorial http://netbeans.org/kb/docs/websvc/gs-axis.html and successfully created the web service. When i
I followed steps here: https://developers.facebook.com/docs/guides/mobile/#android but I really don't get how use Graph API
I've followed this: https://dev.twitter.com/docs/auth/creating-signature to the end but I can't find how to encode
I followed the application to run the tests of pylons project: http://pylonshq.com/docs/en/0.9.7/i18n/#testing-the-application But when
I followed https://docs.djangoproject.com/en/dev/ref/contrib/flatpages/ and I created a flatpage using my own template in http://localhost:8000/about-me/
Followed this question about delayed_job and monit Its working on my development machine. But
I followed the explanation on the sIFR wiki, but can't seem to get accented
So followed all the basic tutorials. Am using Zend 1.8 but i keep getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.