dark-capistrano-recipes 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ # Common hooks for all scenarios.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ after 'deploy:setup' do
4
+ app.setup
5
+ bundler.setup
6
+ end
7
+
8
+ after "deploy:update_code" do
9
+ symlinks.make
10
+ bundler.install
11
+ deploy.cleanup
12
+ end
13
+ end
14
+
15
+
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :log do
3
+ desc "Tail all application log files"
4
+ task :tail, :roles => :app do
5
+ run "tail -f #{shared_path}/log/*.log" do |channel, stream, data|
6
+ puts "#{channel[:host]}: #{data}"
7
+ break if stream == :err
8
+ end
9
+ end
10
+
11
+ desc <<-DESC
12
+ Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
13
+ DESC
14
+ task :rotate, :roles => :app do
15
+ rotate_script = %Q{#{shared_path}/log/#{environment}.log {
16
+ daily
17
+ rotate #{ENV['days'] || 7}
18
+ size #{ENV['size'] || "5M"}
19
+ compress
20
+ create 640 #{user} #{ENV['group'] || user}
21
+ missingok
22
+ }}
23
+ put rotate_script, "#{shared_path}/logrotate_script"
24
+ "#{sudo} cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}"
25
+ run "rm #{shared_path}/logrotate_script"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,54 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ # Where your nginx lives. Usually /opt/nginx or /usr/local/nginx for source
4
+ # compiled.
5
+ set :nginx_path_prefix, "/opt/nginx" unless exists?(:nginx_path_prefix)
6
+
7
+ # Path to the nginx erb template to be parsed before uploading to remote
8
+ set(:nginx_local_config) { "#{templates_path}/nginx.conf.erb" } unless exists?(:nginx_local_config)
9
+
10
+ # Path to where your remote config will reside (I use a directory sites inside conf)
11
+ set(:nginx_remote_config) do
12
+ "#{nginx_path_prefix}/conf/sites/#{application}.conf"
13
+ end unless exists?(:nginx_remote_config)
14
+
15
+ # Nginx tasks are not *nix agnostic, they assume you're using Debian/Ubuntu.
16
+ # Override them as needed.
17
+ namespace :nginx do
18
+
19
+ desc "Parses and uploads nginx configuration for this app."
20
+ task :setup do
21
+ generate_config(nginx_local_config, nginx_remote_config)
22
+ end
23
+
24
+ # [internal] Parses config file and outputs it to STDOUT
25
+ task :parse do
26
+ puts parse_config(nginx_local_config)
27
+ end
28
+
29
+ desc "Restart nginx"
30
+ task :restart do
31
+ sudo "service nginx restart"
32
+ end
33
+
34
+ desc "Stop nginx"
35
+ task :stop do
36
+ sudo "service nginx stop"
37
+ end
38
+
39
+ desc "Start nginx"
40
+ task :start do
41
+ sudo "service nginx start"
42
+ end
43
+
44
+ desc "Show nginx status"
45
+ task :status do
46
+ sudo "service nginx status"
47
+ end
48
+
49
+ end
50
+
51
+ after 'deploy:setup', 'nginx:setup' if is_using_nginx
52
+
53
+ end
54
+
@@ -0,0 +1,18 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :passenger do
3
+ desc "Restart Rails app running under Phusion Passenger by touching restart.txt"
4
+ task :bounce, :roles => :app do
5
+ run "#{sudo} touch #{current_path}/tmp/restart.txt"
6
+ end
7
+
8
+ desc "Inspect Phusion Passenger's memory usage. Assumes binaries are located in /opt/ruby-enterprise."
9
+ task :memory, :roles => :app do
10
+ run "#{sudo} /opt/ruby-enterprise/bin/passenger-memory-stats"
11
+ end
12
+
13
+ desc "Inspect Phusion Passenger's internal status. Assumes binaries are located in /opt/ruby-enterprise."
14
+ task :status, :roles => :app do
15
+ run "#{sudo} /opt/ruby-enterprise/bin/passenger-status"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # RVM jazz
2
+ #------------------------------------------------------------------------------
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ if defined?(using_rvm) && using_rvm
5
+ # Add RVM's lib directory to the load path.
6
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
7
+
8
+ # Load RVM's capistrano plugin.
9
+ require "rvm/capistrano"
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ # These are set to the same structure in shared <=> current
3
+ set :normal_symlinks, %w(
4
+ config/database.yml
5
+ ) unless exists?(:normal_symlinks)
6
+
7
+ # Weird symlinks go somewhere else. Weird.
8
+ set :weird_symlinks, {
9
+ 'bundle' => 'vendor/bundle'
10
+ } unless exists?(:weird_symlinks)
11
+
12
+ namespace :symlinks do
13
+ desc "Make all the damn symlinks in a single run"
14
+ task :make, :roles => :app, :except => { :no_release => true } do
15
+ commands = normal_symlinks.map do |path|
16
+ "rm -rf #{current_path}/#{path} && \
17
+ ln -s #{shared_path}/#{path} #{current_path}/#{path}"
18
+ end
19
+
20
+ commands += weird_symlinks.map do |from, to|
21
+ "rm -rf #{current_path}/#{to} && \
22
+ ln -s #{shared_path}/#{from} #{current_path}/#{to}"
23
+ end
24
+
25
+
26
+ run <<-CMD
27
+ cd #{current_path} &&
28
+ #{commands.join(" && ")}
29
+ CMD
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,83 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ # Number of workers (Rule of thumb is 2 per CPU)
3
+ # Just be aware that every worker needs to cache all classes and thus eat some
4
+ # of your RAM.
5
+ set :unicorn_workers, 8 unless exists?(:unicorn_workers)
6
+
7
+ # Workers timeout in the amount of seconds below, when the master kills it and
8
+ # forks another one.
9
+ set :unicorn_workers_timeout, 30 unless exists?(:unicorn_workers_timeout)
10
+
11
+ # Workers are started with this user/group
12
+ # By default we get the user/group set in capistrano.
13
+ set(:unicorn_user) { user } unless exists?(:unicorn_user)
14
+ set(:unicorn_group) { group } unless exists?(:unicorn_group)
15
+
16
+ # The wrapped bin to start unicorn
17
+ # This is necessary if you're using rvm
18
+ set :unicorn_bin, 'unicorn_rails' unless exists?(:unicorn_bin)
19
+
20
+
21
+ set :unicorn_socket, File.join(sockets_path,'unicorn.sock') unless exists?(:unicorn_socket)
22
+
23
+ # Defines where the unicorn pid will live.
24
+ set(:unicorn_pid) { File.join(pids_path, "unicorn.pid") } unless exists?(:unicorn_pid)
25
+
26
+
27
+ # Our unicorn template to be parsed by erb
28
+ # You may need to generate this file the first time with the generator
29
+ # included in the gem
30
+ set(:unicorn_local_config) { File.join(templates_path, "unicorn.rb.erb") }
31
+
32
+ # The remote location of unicorn's config file. Used by god to fire it up
33
+ set(:unicorn_remote_config) { "#{shared_path}/config/unicorn.rb" }
34
+
35
+ def unicorn_start_cmd
36
+ "cd #{current_path} && #{unicorn_bin} -c #{unicorn_remote_config} -E #{rails_env} -D"
37
+ end
38
+
39
+ def unicorn_stop_cmd
40
+ "kill -QUIT `cat #{unicorn_pid}`"
41
+ end
42
+
43
+ def unicorn_restart_cmd
44
+ "kill -USR2 `cat #{unicorn_pid}`"
45
+ end
46
+
47
+ # Unicorn
48
+ #------------------------------------------------------------------------------
49
+ namespace :unicorn do
50
+ desc "Start unicorn"
51
+ task :start, :roles => :app do
52
+ run unicorn_start_cmd
53
+ end
54
+
55
+ desc "Stop unicorn"
56
+ task :stop, :roles => :app do
57
+ run unicorn_stop_cmd
58
+ end
59
+
60
+ desc "Restart unicorn"
61
+ task :restart, :roles => :app do
62
+ run unicorn_restart_cmd do |ch, stream, out|
63
+
64
+ end
65
+ end
66
+
67
+ desc <<-EOF
68
+ Parses the configuration file through ERB to fetch our variables and \
69
+ uploads the result to #{unicorn_remote_config}, to be loaded by whoever is booting \
70
+ up the unicorn.
71
+ EOF
72
+ task :setup do
73
+ # TODO: refactor this to a more generic setup task once we have more socket tasks.
74
+ sudo "mkdir -p #{sockets_path}"
75
+ sudo "chown #{user}:#{group} #{sockets_path} -R"
76
+ generate_config(unicorn_local_config,unicorn_remote_config)
77
+ end
78
+ end
79
+
80
+ after 'deploy:setup', 'unicorn:setup' if is_using_unicorn
81
+
82
+ end
83
+
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dark-capistrano-recipes
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 4
10
+ version: 0.6.4
11
+ platform: ruby
12
+ authors:
13
+ - Phil Misiowiec
14
+ - Leonardo Bighetti
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-09-20 00:00:00 -03:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: capistrano
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 9
31
+ segments:
32
+ - 2
33
+ - 5
34
+ - 9
35
+ version: 2.5.9
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: capistrano-ext
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 29
47
+ segments:
48
+ - 1
49
+ - 2
50
+ - 1
51
+ version: 1.2.1
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ description: Extend the Capistrano gem with these useful recipes
55
+ email: leonardobighetti@gmail.com
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - LICENSE
62
+ - README.rdoc
63
+ files:
64
+ - .gitignore
65
+ - LICENSE
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION.yml
69
+ - dark-capistrano-recipes.gemspec
70
+ - doc/god/god
71
+ - doc/god/god.conf
72
+ - doc/god/god.init
73
+ - generators/app.god.erb
74
+ - generators/nginx.conf.erb
75
+ - generators/unicorn.rb.erb
76
+ - lib/capistrano_recipes.rb
77
+ - lib/helpers.rb
78
+ - lib/recipes/application.rb
79
+ - lib/recipes/bundler.rb
80
+ - lib/recipes/db.rb
81
+ - lib/recipes/deploy.rb
82
+ - lib/recipes/god.rb
83
+ - lib/recipes/hooks.rb
84
+ - lib/recipes/log.rb
85
+ - lib/recipes/nginx.rb
86
+ - lib/recipes/passenger.rb
87
+ - lib/recipes/rvm.rb
88
+ - lib/recipes/symlinks.rb
89
+ - lib/recipes/unicorn.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/darkside/capistrano-recipes
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project:
120
+ rubygems_version: 1.3.7
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Darkside's Capistrano recipes
124
+ test_files: []
125
+