capistrano-recipes 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +19 -2
- data/Rakefile +0 -1
- data/VERSION.yml +2 -2
- data/capistrano-recipes.gemspec +2 -5
- data/lib/capistrano_recipes.rb +0 -1
- data/lib/helpers.rb +15 -1
- data/lib/recipes/db.rb +7 -12
- data/lib/recipes/deploy.rb +1 -3
- data/lib/recipes/log.rb +2 -4
- data/lib/recipes/passenger.rb +0 -2
- data/lib/recipes/symlink.rb +36 -7
- metadata +2 -12
data/README.rdoc
CHANGED
@@ -7,18 +7,34 @@ Useful Capistrano recipes including:
|
|
7
7
|
* Log rotation and tailing commands
|
8
8
|
* Restart and profile Phusion Passenger application server
|
9
9
|
|
10
|
+
==Included Tasks
|
11
|
+
|
12
|
+
* cap db:create_yaml
|
13
|
+
* cap db:mysql:setup
|
14
|
+
* cap log:rotate
|
15
|
+
* cap log:tail
|
16
|
+
* cap passenger:bounce
|
17
|
+
* cap passenger:memory
|
18
|
+
* cap passenger:status
|
19
|
+
* cap symlink:create_shared_dirs
|
20
|
+
* cap symlink:shared_config_files
|
21
|
+
* cap symlink:shared_directories
|
22
|
+
|
10
23
|
==Installation
|
11
24
|
|
12
25
|
Easy as pie...
|
13
26
|
|
14
|
-
Ensure you have the Capistrano
|
27
|
+
Ensure you have the Capistrano gem installed:
|
15
28
|
|
16
29
|
sudo gem install capistrano
|
30
|
+
|
31
|
+
Optionally install the Capistrano extensions gem to give you multistage support:
|
32
|
+
|
17
33
|
sudo gem install capistrano-ext
|
18
34
|
|
19
35
|
Install this gem:
|
20
36
|
|
21
|
-
sudo gem install
|
37
|
+
sudo gem install capistrano-recipes --source=http://gemcutter.com
|
22
38
|
|
23
39
|
To setup the initial Capistrano deploy file, go to your Rails app folder via command line and enter:
|
24
40
|
|
@@ -27,6 +43,7 @@ To setup the initial Capistrano deploy file, go to your Rails app folder via com
|
|
27
43
|
Inside the newly created config/deploy.rb, add:
|
28
44
|
|
29
45
|
require 'capistrano_recipes'
|
46
|
+
require 'capistrano/ext/multistage' # only require if you've installed Cap ext gem
|
30
47
|
|
31
48
|
If you're running Phusion Passenger (http://www.modrails.com) be sure you add this line to config/deploy.rb:
|
32
49
|
|
data/Rakefile
CHANGED
@@ -11,7 +11,6 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/webficient/capistrano-recipes"
|
12
12
|
gem.authors = ["Phil Misiowiec"]
|
13
13
|
gem.add_dependency('capistrano', ['>= 2.5.9'])
|
14
|
-
gem.add_dependency('capistrano-ext', ['>= 1.2.1'])
|
15
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
15
|
end
|
17
16
|
rescue LoadError
|
data/VERSION.yml
CHANGED
data/capistrano-recipes.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{capistrano-recipes}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Phil Misiowiec"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-01}
|
13
13
|
s.description = %q{Extend the Capistrano gem with these useful recipes}
|
14
14
|
s.email = %q{phil@webficient.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,13 +43,10 @@ Gem::Specification.new do |s|
|
|
43
43
|
|
44
44
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
45
|
s.add_runtime_dependency(%q<capistrano>, [">= 2.5.9"])
|
46
|
-
s.add_runtime_dependency(%q<capistrano-ext>, [">= 1.2.1"])
|
47
46
|
else
|
48
47
|
s.add_dependency(%q<capistrano>, [">= 2.5.9"])
|
49
|
-
s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
|
50
48
|
end
|
51
49
|
else
|
52
50
|
s.add_dependency(%q<capistrano>, [">= 2.5.9"])
|
53
|
-
s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
|
54
51
|
end
|
55
52
|
end
|
data/lib/capistrano_recipes.rb
CHANGED
data/lib/helpers.rb
CHANGED
@@ -2,8 +2,22 @@
|
|
2
2
|
# These are helper methods that will be available to your recipes.
|
3
3
|
# =========================================================================
|
4
4
|
|
5
|
+
# automatically sets the environment based on presence of
|
6
|
+
# :stage (multistage gem), :rails_env, or RAILS_ENV variable; otherwise defaults to 'production'
|
7
|
+
def environment
|
8
|
+
if exists?(:stage)
|
9
|
+
stage
|
10
|
+
elsif exists?(:rails_env)
|
11
|
+
rails_env
|
12
|
+
elsif(ENV['RAILS_ENV'])
|
13
|
+
ENV['RAILS_ENV']
|
14
|
+
else
|
15
|
+
"production"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
# Execute a rake task, example:
|
6
20
|
# run_rake log:clear
|
7
21
|
def run_rake(task)
|
8
|
-
run "cd #{current_path} && rake #{task} RAILS_ENV=#{
|
22
|
+
run "cd #{current_path} && rake #{task} RAILS_ENV=#{environment}"
|
9
23
|
end
|
data/lib/recipes/db.rb
CHANGED
@@ -23,8 +23,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
23
23
|
|
24
24
|
desc "Create database.yml in shared path with settings for current stage and test env"
|
25
25
|
task :create_yaml do
|
26
|
-
set(:db_user) { Capistrano::CLI.ui.ask "Enter #{
|
27
|
-
set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{
|
26
|
+
set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" }
|
27
|
+
set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" }
|
28
28
|
|
29
29
|
db_config = ERB.new <<-EOF
|
30
30
|
base: &base
|
@@ -32,8 +32,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
32
32
|
username: #{db_user}
|
33
33
|
password: #{db_pass}
|
34
34
|
|
35
|
-
#{
|
36
|
-
database: #{application}_#{
|
35
|
+
#{environment}:
|
36
|
+
database: #{application}_#{environment}
|
37
37
|
<<: *base
|
38
38
|
|
39
39
|
test:
|
@@ -43,17 +43,12 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
43
43
|
|
44
44
|
put db_config.result, "#{shared_path}/config/database.yml"
|
45
45
|
end
|
46
|
-
|
47
|
-
desc "Create symlink for database yaml stored in shared path"
|
48
|
-
task :symlink do
|
49
|
-
run "#{sudo} ln -nfs #{shared_path}/config/database.yml #{current_release}/config/database.yml"
|
50
|
-
end
|
51
46
|
end
|
52
47
|
|
53
48
|
def prepare_for_db_command
|
54
|
-
set :db_name, "#{application}_#{
|
49
|
+
set :db_name, "#{application}_#{environment}"
|
55
50
|
set(:db_admin_user) { Capistrano::CLI.ui.ask "Username with priviledged database access (to create db):" }
|
56
|
-
set(:db_user) { Capistrano::CLI.ui.ask "Enter #{
|
57
|
-
set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{
|
51
|
+
set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" }
|
52
|
+
set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" }
|
58
53
|
end
|
59
54
|
end
|
data/lib/recipes/deploy.rb
CHANGED
@@ -5,10 +5,9 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
5
5
|
db.create_yaml if Capistrano::CLI.ui.agree("Create database.yml in app's shared path?")
|
6
6
|
end
|
7
7
|
|
8
|
-
after "deploy:update_code", "
|
8
|
+
after "deploy:update_code", "symlink:shared_config_files"
|
9
9
|
|
10
10
|
namespace :deploy do
|
11
|
-
|
12
11
|
desc <<-DESC
|
13
12
|
Restarts your application. If you are running Phusion Passenger, you can \
|
14
13
|
explicitly set the server type:
|
@@ -33,6 +32,5 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
33
32
|
try_runner "#{current_path}/script/process/reaper"
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
36
|
end
|
data/lib/recipes/log.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
Capistrano::Configuration.instance(:must_exist).load do
|
2
2
|
namespace :log do
|
3
|
-
|
4
3
|
desc "Tail application log file for the specified environment, e.g. cap staging log:tail"
|
5
4
|
task :tail, :roles => :app do
|
6
|
-
run "tail -f #{shared_path}/log/#{
|
5
|
+
run "tail -f #{shared_path}/log/#{environment}.log" do |channel, stream, data|
|
7
6
|
puts "#{channel[:host]}: #{data}"
|
8
7
|
break if stream == :err
|
9
8
|
end
|
@@ -13,7 +12,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
13
12
|
Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
|
14
13
|
DESC
|
15
14
|
task :rotate, :roles => :app do
|
16
|
-
rotate_script = %Q{#{shared_path}/log/#{
|
15
|
+
rotate_script = %Q{#{shared_path}/log/#{environment}.log {
|
17
16
|
daily
|
18
17
|
rotate #{ENV['days'] || 7}
|
19
18
|
size #{ENV['size'] || "5M"}
|
@@ -25,6 +24,5 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
25
24
|
"#{sudo} cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}"
|
26
25
|
run "rm #{shared_path}/logrotate_script"
|
27
26
|
end
|
28
|
-
|
29
27
|
end
|
30
28
|
end
|
data/lib/recipes/passenger.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
Capistrano::Configuration.instance(:must_exist).load do
|
2
2
|
namespace :passenger do
|
3
|
-
|
4
3
|
desc "Restart Rails app running under Phusion Passenger by touching restart.txt"
|
5
4
|
task :bounce, :roles => :app do
|
6
5
|
run "#{sudo} touch #{current_path}/tmp/restart.txt"
|
@@ -15,6 +14,5 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
15
14
|
task :status, :roles => :app do
|
16
15
|
run "#{sudo} /opt/ruby-enterprise/bin/passenger-status"
|
17
16
|
end
|
18
|
-
|
19
17
|
end
|
20
18
|
end
|
data/lib/recipes/symlink.rb
CHANGED
@@ -1,22 +1,51 @@
|
|
1
1
|
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
unless exists?(:config_files)
|
3
|
+
set :config_files, 'database.yml'
|
4
|
+
end
|
5
|
+
|
2
6
|
namespace :symlink do
|
3
|
-
|
4
7
|
desc <<-DESC
|
5
|
-
Create shared directories
|
8
|
+
Create shared directories. Specify which directories are shared via:
|
9
|
+
set :shared_dirs, %w(avatars videos)
|
6
10
|
DESC
|
7
11
|
task :create_shared_dirs, :roles => :app do
|
8
|
-
|
12
|
+
shared_dirs.each { |link| run "mkdir -p #{shared_path}/#{link}" } if shared_dirs
|
9
13
|
end
|
10
14
|
|
11
15
|
desc <<-DESC
|
12
|
-
Create links to shared directories from current deployment's public directory
|
16
|
+
Create links to shared directories from current deployment's public directory.
|
17
|
+
Specify which directories are shared via:
|
18
|
+
set :shared_dirs, %w(avatars videos)
|
13
19
|
DESC
|
14
|
-
task :
|
15
|
-
|
20
|
+
task :shared_directories, :roles => :app do
|
21
|
+
shared_dirs.each do |link|
|
16
22
|
run "rm -rf #{release_path}/public/#{link}"
|
17
23
|
run "ln -nfs #{shared_path}/#{link} #{release_path}/public/#{link}"
|
18
|
-
|
24
|
+
end if shared_dirs
|
19
25
|
end
|
20
26
|
|
27
|
+
desc <<-DESC
|
28
|
+
Create links to config files stored in shared config directory.
|
29
|
+
Specify which config files to link using the following:
|
30
|
+
set :config_files, 'database.yml'
|
31
|
+
DESC
|
32
|
+
task :shared_config_files, :roles => :app do
|
33
|
+
config_files.each do |file_path|
|
34
|
+
begin
|
35
|
+
run "#{sudo} rm #{config_path}#{file_path}"
|
36
|
+
run "#{sudo} ln -nfs #{shared_config_path}#{file_path} #{config_path}#{file_path}"
|
37
|
+
rescue
|
38
|
+
puts "Problem linking to #{file_path}. Be sure file already exists in #{shared_config_path}."
|
39
|
+
end
|
40
|
+
end if config_files
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def config_path
|
45
|
+
"#{current_release}/config/"
|
46
|
+
end
|
47
|
+
|
48
|
+
def shared_config_path
|
49
|
+
"#{shared_path}/config/"
|
21
50
|
end
|
22
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-recipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Misiowiec
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,16 +22,6 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 2.5.9
|
24
24
|
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: capistrano-ext
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.2.1
|
34
|
-
version:
|
35
25
|
description: Extend the Capistrano gem with these useful recipes
|
36
26
|
email: phil@webficient.com
|
37
27
|
executables: []
|