Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few updates that might be worth considering? #30

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Load DSL and Setup Up Stages

set :bundle_cmd, "/usr/local/rbenv/shims/bundle"

require 'capistrano/setup'

# Includes default deployment tasks
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ This is a sample configuration for deploying Ruby on Rails applications with Cap

See
<http://www.talkingquickly.co.uk/2014/01/deploying-rails-apps-to-a-vps-with-capistrano-v3/>
for a tutorial on usage.
for a tutorial on usage.


Or for more details, this is also the example configuration used in the
book Reliably Deploying Rails Applications available on Leanpub:
Expand All @@ -18,10 +19,10 @@ book Reliably Deploying Rails Applications available on Leanpub:

You should have the following in your Gemfile:

gem 'capistrano', '~> 3.1.0'
gem 'capistrano', '~> 3.2.1'

# rails specific capistrano funcitons
gem 'capistrano-rails', '~> 1.1.0'
gem 'capistrano-rails', '~> 1.1.1'

# integrate bundler with capistrano
gem 'capistrano-bundler'
Expand All @@ -32,3 +33,12 @@ You should have the following in your Gemfile:
# Use Unicorn as our app server
gem 'unicorn'

## Additions

I have added Sphinx to this. So add to gemfile:

gem 'thinking-sphinx', '~> 3.1.0'
gem 'mysql2'

gordonbisnor fork is also referencing the following article: <http://blog.isnorcreative.com/2014/09/02/rails-deploy-to-new-vps.html/> and the forked Rails server template: <https://github.com/gordonbisnor/rails-server-template>

25 changes: 23 additions & 2 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'thinking_sphinx/capistrano'

set :application, 'app_name'
set :deploy_user, 'deploy'

Expand All @@ -7,15 +9,15 @@

# setup rbenv.
set :rbenv_type, :system
set :rbenv_ruby, '2.1.1'
set :rbenv_ruby, '2.1.2'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}

# how many old releases do we want to keep, not much
set :keep_releases, 5

# files we want symlinking to specific entries in shared
set :linked_files, %w{config/database.yml}
set :linked_files, %w{config/database.yml config/secrets.yml config/thinking_sphinx.yml}

# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
Expand All @@ -30,8 +32,13 @@
set(:config_files, %w(
nginx.conf
database.example.yml
secrets.example.yml
thinking_sphinx.yml
log_rotation
monit
monit.sphinx
start_sphinx
stop_sphinx
unicorn.rb
unicorn_init.sh
))
Expand All @@ -40,6 +47,8 @@
# by deploy:setup_config
set(:executable_config_files, %w(
unicorn_init.sh
start_sphinx
stop_sphinx
))


Expand All @@ -64,6 +73,18 @@
{
source: "monit",
link: "/etc/monit/conf.d/{{full_app_name}}.conf"
},
{
source: "monit.sphinx",
link: "/etc/monit/conf.d/sphinx.conf"
},
{
source: "start_sphinx",
link: "/etc/init.d/start_sphinx"
},
{
source: "stop_sphinx",
link: "/etc/init.d/stop_sphinx"
}
])

Expand Down
9 changes: 9 additions & 0 deletions config/deploy/shared/monit.sphinx.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% application = fetch(:application) %>

check process searchd
with pidfile <%= deploy_to %>/shared/tmp/pids/production.sphinx.pid
start program = "/etc/init.d/start_sphinx"
stop program = "/etc/init.d/stop_sphinx"



3 changes: 3 additions & 0 deletions config/deploy/shared/secrets.example.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= fetch(:rails_env) %>:
secret_key_base: xxx

7 changes: 7 additions & 0 deletions config/deploy/shared/start_sphinx.erb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/sh

cd <%= fetch(:deploy_to) %>/current && RAILS_ENV=production bundle exec rake ts:index
cd <%= fetch(:deploy_to) %>/current && RAILS_ENV=production bundle exec rake ts:start > log/sphinx.log 2>&1



4 changes: 4 additions & 0 deletions config/deploy/shared/stop_sphinx.erb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
export PATH="$PATH:/usr/local/bin"

cd <%= fetch(:deploy_to) %>/current && RAILS_ENV=production bundle exec rake ts:stop > log/sphinx.log 2>&1
3 changes: 3 additions & 0 deletions config/deploy/shared/thinking_sphinx.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
production:
pid_file: <%= fetch(:deploy_to) %>/shared/tmp/pids/production.sphinx.pid