capistrano-recipes 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Webficient LLC, Phil Misiowiec
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ =Capistrano Recipes
2
+
3
+ Useful Capistrano recipes including:
4
+
5
+ * Create MySQL database and user on server (via prompts)
6
+ * Create standalone copy of database.yml in shared path (via prompts)
7
+ * Log rotation and tailing commands
8
+ * Restart and profile Phusion Passenger application server
9
+
10
+ ==Installation
11
+
12
+ Easy as pie...
13
+
14
+ Ensure you have the Capistrano and Capistrano extensions gems installed:
15
+
16
+ sudo gem install capistrano
17
+ sudo gem install capistrano-ext
18
+
19
+ Install this gem:
20
+
21
+ sudo gem install webficient-capistrano-recipes --source=http://gems.github.com
22
+
23
+ To setup the initial Capistrano deploy file, go to your Rails app folder via command line and enter:
24
+
25
+ capify .
26
+
27
+ Inside the newly created config/deploy.rb, add:
28
+
29
+ require 'capistrano_recipes'
30
+
31
+ If you're running Phusion Passenger (http://www.modrails.com) be sure you add this line to config/deploy.rb:
32
+
33
+ set :server, :passenger
34
+
35
+ ==Copyright
36
+
37
+ Copyright (c) 2009 Webficient LLC, Phil Misiowiec. See LICENSE for details.
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capistrano-recipes"
8
+ gem.summary = %Q{Capistrano recipes}
9
+ gem.email = "phil@webficient.com"
10
+ gem.homepage = "http://github.com/webficient/capistrano-recipes"
11
+ gem.authors = ["Phil Misiowiec"]
12
+ gem.add_dependency('capistrano', ['>= 2.5.5'])
13
+ gem.add_dependency('capistrano-ext', ['>= 1.2.1'])
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+ require 'rake/rdoctask'
21
+ Rake::RDocTask.new do |rdoc|
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.title = 'capistrano-recipes'
24
+ rdoc.options << '--line-numbers' << '--inline-source'
25
+ rdoc.rdoc_files.include('README*')
26
+ rdoc.rdoc_files.include('lib/**/*.rb')
27
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 0
4
+ :minor: 4
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capistrano-recipes}
8
+ s.version = "0.4.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Phil Misiowiec"]
12
+ s.date = %q{2009-09-29}
13
+ s.email = %q{phil@webficient.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "capistrano-recipes.gemspec",
25
+ "lib/capistrano_recipes.rb",
26
+ "lib/helpers.rb",
27
+ "lib/recipes/db.rb",
28
+ "lib/recipes/deploy.rb",
29
+ "lib/recipes/log.rb",
30
+ "lib/recipes/passenger.rb",
31
+ "lib/recipes/symlink.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/webficient/capistrano-recipes}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{Capistrano recipes}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<capistrano>, [">= 2.5.5"])
45
+ s.add_runtime_dependency(%q<capistrano-ext>, [">= 1.2.1"])
46
+ else
47
+ s.add_dependency(%q<capistrano>, [">= 2.5.5"])
48
+ s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<capistrano>, [">= 2.5.5"])
52
+ s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
53
+ end
54
+ end
@@ -0,0 +1,10 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cli'
3
+ require 'capistrano/ext/multistage'
4
+ require 'helpers'
5
+
6
+ @@cap_config = Capistrano::Configuration.respond_to?(:instance) ?
7
+ Capistrano::Configuration.instance(:must_exist) :
8
+ Capistrano.configuration(:must_exist)
9
+
10
+ Dir.glob(File.join(File.dirname(__FILE__), '/recipes/*.rb')).each { |f| load f }
@@ -0,0 +1,9 @@
1
+ # =========================================================================
2
+ # These are helper methods that will be available to your recipes.
3
+ # =========================================================================
4
+
5
+ # Execute a rake task, example:
6
+ # run_rake log:clear
7
+ def run_rake(task)
8
+ run "cd #{current_path} && rake #{task} RAILS_ENV=#{stage}"
9
+ end
@@ -0,0 +1,60 @@
1
+ require 'erb'
2
+
3
+ @@cap_config.load do
4
+
5
+ namespace :db do
6
+ namespace :mysql do
7
+ desc "Create MySQL database and user for this environment using prompted values"
8
+ task :setup, :roles => :db, :only => { :primary => true } do
9
+ prepare_for_db_command
10
+
11
+ sql = <<-SQL
12
+ CREATE DATABASE #{db_name};
13
+ GRANT ALL PRIVILEGES ON #{db_name}.* TO #{db_user}@localhost IDENTIFIED BY '#{db_pass}';
14
+ SQL
15
+
16
+ run "mysql --user=#{db_admin_user} -p --execute=\"#{sql}\"" do |channel, stream, data|
17
+ if data =~ /^Enter password:/
18
+ pass = Capistrano::CLI.password_prompt "Enter database password for '#{db_admin_user}':"
19
+ channel.send_data "#{pass}\n"
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Create database.yml in shared path with settings for current stage and test env"
26
+ task :create_yaml do
27
+ set(:db_user) { Capistrano::CLI.ui.ask "Enter #{stage} database username:" }
28
+ set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{stage} database password:" }
29
+
30
+ db_config = ERB.new <<-EOF
31
+ base: &base
32
+ adapter: mysql
33
+ username: #{db_user}
34
+ password: #{db_pass}
35
+
36
+ #{stage}:
37
+ database: #{application}_#{stage}
38
+ <<: *base
39
+
40
+ test:
41
+ database: #{application}_test
42
+ <<: *base
43
+ EOF
44
+
45
+ put db_config.result, "#{shared_path}/config/database.yml"
46
+ end
47
+
48
+ desc "Create symlink for database yaml stored in shared path"
49
+ task :symlink do
50
+ run "#{sudo} ln -nfs #{shared_path}/config/database.yml #{current_release}/config/database.yml"
51
+ end
52
+ end
53
+
54
+ def prepare_for_db_command
55
+ set :db_name, "#{application}_#{stage}"
56
+ set(:db_admin_user) { Capistrano::CLI.ui.ask "Username with priviledged database access (to create db):" }
57
+ set(:db_user) { Capistrano::CLI.ui.ask "Enter #{stage} database username:" }
58
+ set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{stage} database password:" }
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ @@cap_config.load do
2
+
3
+ set :shared_children, %w(system log pids config)
4
+
5
+ after "deploy:setup" do
6
+ db.create_yaml if Capistrano::CLI.ui.agree("Create database.yml in app's shared path?")
7
+ end
8
+
9
+ after "deploy:update_code", "db:symlink"
10
+
11
+ namespace :deploy do
12
+
13
+ desc <<-DESC
14
+ Restarts your application. If you are running Phusion Passenger, you can \
15
+ explicitly set the server type:
16
+
17
+ set :server, :passenger
18
+
19
+ ...which will touch tmp/restart.txt, a file monitored by Passenger.
20
+ Otherwise, this command will call the script/process/reaper \
21
+ script under the current path.
22
+
23
+ By default, this will be invoked via sudo as the `app' user. If \
24
+ you wish to run it as a different user, set the :runner variable to \
25
+ that user. If you are in an environment where you can't use sudo, set \
26
+ the :use_sudo variable to false:
27
+
28
+ set :use_sudo, false
29
+ DESC
30
+ task :restart, :roles => :app, :except => { :no_release => true } do
31
+ if exists?(:server) && fetch(:server).to_s.downcase == 'passenger'
32
+ passenger.bounce
33
+ else
34
+ try_runner "#{current_path}/script/process/reaper"
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ @@cap_config.load do
2
+ namespace :log do
3
+
4
+ desc "Tail application log file for the specified environment, e.g. cap staging log:tail"
5
+ task :tail, :roles => :app do
6
+ run "tail -f #{shared_path}/log/#{stage}.log" do |channel, stream, data|
7
+ puts "#{channel[:host]}: #{data}"
8
+ break if stream == :err
9
+ end
10
+ end
11
+
12
+ desc <<-DESC
13
+ Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
14
+ DESC
15
+ task :rotate, :roles => :app do
16
+ rotate_script = %Q{#{shared_path}/log/#{stage}.log {
17
+ daily
18
+ rotate #{ENV['days'] || 7}
19
+ size #{ENV['size'] || "5M"}
20
+ compress
21
+ create 640 #{user} #{ENV['group'] || user}
22
+ missingok
23
+ }}
24
+ put rotate_script, "#{shared_path}/logrotate_script"
25
+ "#{sudo} cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}"
26
+ run "rm #{shared_path}/logrotate_script"
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ @@cap_config.load do
2
+ namespace :passenger do
3
+
4
+ desc "Restart Rails app running under Phusion Passenger by touching restart.txt"
5
+ task :bounce, :roles => :app do
6
+ run "#{sudo} touch #{current_path}/tmp/restart.txt"
7
+ end
8
+
9
+ desc "Inspect Phusion Passenger's memory usage. Assumes binaries are located in /opt/ruby-enterprise."
10
+ task :memory, :roles => :app do
11
+ run "#{sudo} /opt/ruby-enterprise/bin/passenger-memory-stats"
12
+ end
13
+
14
+ desc "Inspect Phusion Passenger's internal status. Assumes binaries are located in /opt/ruby-enterprise."
15
+ task :status, :roles => :app do
16
+ run "#{sudo} /opt/ruby-enterprise/bin/passenger-status"
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ @@cap_config.load do
2
+ namespace :symlink do
3
+
4
+ desc <<-DESC
5
+ Create shared directories
6
+ DESC
7
+ task :create_shared_dirs, :roles => :app do
8
+ symlinks.each { |link| run "mkdir -p #{shared_path}/#{link}" } if symlinks
9
+ end
10
+
11
+ desc <<-DESC
12
+ Create links to shared directories from current deployment's public directory
13
+ DESC
14
+ task :create_links, :roles => :app do
15
+ symlinks.each { |link|
16
+ run "rm -rf #{release_path}/public/#{link}"
17
+ run "ln -nfs #{shared_path}/#{link} #{release_path}/public/#{link}"
18
+ } if symlinks
19
+ end
20
+
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-recipes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Phil Misiowiec
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-29 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: capistrano
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.5.5
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
+ description:
36
+ email: phil@webficient.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION.yml
50
+ - capistrano-recipes.gemspec
51
+ - lib/capistrano_recipes.rb
52
+ - lib/helpers.rb
53
+ - lib/recipes/db.rb
54
+ - lib/recipes/deploy.rb
55
+ - lib/recipes/log.rb
56
+ - lib/recipes/passenger.rb
57
+ - lib/recipes/symlink.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/webficient/capistrano-recipes
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Capistrano recipes
86
+ test_files: []
87
+