ricodigo-capistrano-recipes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ # Common hooks for all scenarios.
2
+ Capistrano::Configuration.instance.load do
3
+ after 'deploy:setup' do
4
+ app.setup
5
+ bundler.setup if Capistrano::CLI.ui.agree("Do you need to install the bundler gem? [Yn]")
6
+ end
7
+
8
+ after "deploy:update_code" do
9
+ symlinks.make
10
+ bundler.install
11
+ end
12
+ end
13
+
14
+
@@ -0,0 +1,42 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :log do
3
+ desc "|capistrano-recipes| 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
+ |capistrano-recipes| 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/*.log {
16
+ daily
17
+ rotate #{ENV['days'] || 7}
18
+ compress
19
+ delaycompress
20
+ missingok
21
+ notifempty
22
+ copytruncate
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
+
28
+ rotate_script = %Q{/var/log/mongodb/*.log {
29
+ daily
30
+ rotate #{ENV['days'] || 7}
31
+ compress
32
+ delaycompress
33
+ missingok
34
+ notifempty
35
+ copytruncate
36
+ }}
37
+ put rotate_script, "#{shared_path}/logrotate_script"
38
+ "#{sudo} cp #{shared_path}/logrotate_script /etc/logrotate.d/mongodb"
39
+ run "rm #{shared_path}/logrotate_script"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ # Where your nginx lives. Usually /opt/nginx or /usr/local/nginx for source compiled.
4
+ set :nginx_path_prefix, "/etc/nginx" unless exists?(:nginx_path_prefix)
5
+
6
+ # Path to the nginx erb template to be parsed before uploading to remote
7
+ set(:nginx_local_config) { "#{templates_path}/nginx.conf.erb" } unless exists?(:nginx_local_config)
8
+
9
+ # Path to where your remote config will reside (I use a directory sites inside conf)
10
+ set(:nginx_remote_config) do
11
+ "#{nginx_path_prefix}/conf/sites/#{application}.conf"
12
+ end unless exists?(:nginx_remote_config)
13
+
14
+ # Nginx tasks are not *nix agnostic, they assume you're using Debian/Ubuntu.
15
+ # Override them as needed.
16
+ namespace :nginx do
17
+ desc "|capistrano-recipes| Parses and uploads nginx configuration for this app."
18
+ task :setup, :roles => :app , :except => { :no_release => true } do
19
+ sudo "mkdir -p #{File.dirname(nginx_remote_config)}"
20
+ set(:nginx_domains) { Capistrano::CLI.ui.ask("Enter #{application} domain names:") {|q|q.default = "#{application}.com"} }
21
+ generate_config(nginx_local_config, "/tmp/nginx.#{application}.config")
22
+ sudo "mv '/tmp/nginx.#{application}.config' #{nginx_remote_config}"
23
+ end
24
+
25
+ desc "|capistrano-recipes| Parses config file and outputs it to STDOUT (internal task)"
26
+ task :parse, :roles => :app , :except => { :no_release => true } do
27
+ puts parse_config(nginx_local_config)
28
+ end
29
+
30
+ desc "|capistrano-recipes| Restart nginx"
31
+ task :restart, :roles => :app , :except => { :no_release => true } do
32
+ sudo "service nginx restart"
33
+ end
34
+
35
+ desc "|capistrano-recipes| Stop nginx"
36
+ task :stop, :roles => :app , :except => { :no_release => true } do
37
+ sudo "service nginx stop"
38
+ end
39
+
40
+ desc "|capistrano-recipes| Start nginx"
41
+ task :start, :roles => :app , :except => { :no_release => true } do
42
+ sudo "service nginx start"
43
+ end
44
+
45
+ desc "|capistrano-recipes| Show nginx status"
46
+ task :status, :roles => :app , :except => { :no_release => true } do
47
+ sudo "service nginx status"
48
+ end
49
+ end
50
+
51
+ after 'deploy:setup' do
52
+ nginx.setup if Capistrano::CLI.ui.agree("Create nginx configuration file? [Yn]")
53
+ end if is_using_nginx
54
+ end
55
+
@@ -0,0 +1,27 @@
1
+ Capistrano::Configuration.instance.load do
2
+ # These are set to the same structure in shared <=> current
3
+ set :normal_symlinks, %w(tmp log config/mongoid.yml) unless exists?(:normal_symlinks)
4
+
5
+ # Weird symlinks go somewhere else. Weird.
6
+ set :weird_symlinks, { 'bundle' => 'vendor/bundle',
7
+ 'pids' => 'tmp/pids' } unless exists?(:weird_symlinks)
8
+
9
+ namespace :symlinks do
10
+ desc "|capistrano-recipes| Make all the symlinks in a single run"
11
+ task :make, :roles => :app, :except => { :no_release => true } do
12
+ commands = normal_symlinks.map do |path|
13
+ "rm -rf #{current_path}/#{path} && \
14
+ ln -s #{shared_path}/#{path} #{current_path}/#{path}"
15
+ end
16
+
17
+ commands += weird_symlinks.map do |from, to|
18
+ "rm -rf #{current_path}/#{to} && \
19
+ ln -s #{shared_path}/#{from} #{current_path}/#{to}"
20
+ end
21
+
22
+ run <<-CMD
23
+ cd #{current_path} && #{commands.join(" && ")}
24
+ CMD
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,80 @@
1
+ Capistrano::Configuration.instance.load do
2
+ # Number of workers (Rule of thumb is 1 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, 4 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' unless exists?(:unicorn_bin)
19
+ set :unicorn_socket, File.join(sockets_path,'unicorn.sock') unless exists?(:unicorn_socket)
20
+
21
+ # Defines where the unicorn pid will live.
22
+ set(:unicorn_pid) { File.join(pids_path, "unicorn.pid") } unless exists?(:unicorn_pid)
23
+
24
+ # Our unicorn template to be parsed by erb
25
+ # You may need to generate this file the first time with the generator
26
+ # included in the gem
27
+ set(:unicorn_local_config) { File.join(templates_path, "unicorn.rb.erb") }
28
+
29
+ # The remote location of unicorn's config file. Used by god to fire it up
30
+ set(:unicorn_remote_config) { "#{shared_path}/config/unicorn.rb" }
31
+
32
+ def unicorn_start_cmd
33
+ "#{unicorn_bin} -c #{unicorn_remote_config} -E #{rails_env} -D"
34
+ end
35
+
36
+ def unicorn_stop_cmd
37
+ "kill -QUIT {{PID}}"
38
+ end
39
+
40
+ def unicorn_restart_cmd
41
+ "kill -USR2 {{PID}}"
42
+ end
43
+
44
+ # Unicorn
45
+ #------------------------------------------------------------------------------
46
+ namespace :unicorn do
47
+ desc "|capistrano-recipes| Starts unicorn directly"
48
+ task :start, :roles => :app do
49
+ run unicorn_start_cmd
50
+ end
51
+
52
+ desc "|capistrano-recipes| Stops unicorn directly"
53
+ task :stop, :roles => :app do
54
+ run unicorn_stop_cmd
55
+ end
56
+
57
+ desc "|capistrano-recipes| Restarts unicorn directly"
58
+ task :restart, :roles => :app do
59
+ run unicorn_restart_cmd
60
+ end
61
+
62
+ desc <<-EOF
63
+ |capistrano-recipes| Parses the configuration file through ERB to fetch our variables and \
64
+ uploads the result to #{unicorn_remote_config}, to be loaded by whoever is booting \
65
+ up the unicorn.
66
+ EOF
67
+ task :setup, :roles => :app , :except => { :no_release => true } do
68
+ # TODO: refactor this to a more generic setup task once we have more socket tasks.
69
+ sudo "mkdir -p #{sockets_path}"
70
+ sudo "chown #{user}:#{group} #{sockets_path}"
71
+ sudo "chmod +rw #{sockets_path}"
72
+
73
+ generate_config(unicorn_local_config,unicorn_remote_config)
74
+ end
75
+ end
76
+
77
+ after 'deploy:setup' do
78
+ unicorn.setup if Capistrano::CLI.ui.agree("Create unicorn configuration file? [Yn]")
79
+ end if is_using_unicorn
80
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path("..", __FILE__)
2
+ require 'capistrano'
3
+ require 'capistrano/cli'
4
+ require 'helpers'
5
+
6
+ Dir.glob(File.join(File.dirname(__FILE__), '/recipes/*.rb')).sort.each { |f| load f }
@@ -0,0 +1,87 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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{ricodigo-capistrano-recipes}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David A. Cuadrado"]
12
+ s.date = %q{2011-05-13}
13
+ s.description = %q{our capistrano recipes. forked from capistrano-recipes}
14
+ s.email = %q{krawek@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "generators/app.bluepill.erb",
28
+ "generators/nginx.conf.erb",
29
+ "generators/unicorn.rb.erb",
30
+ "lib/helpers.rb",
31
+ "lib/recipes/application.rb",
32
+ "lib/recipes/bluepill.rb",
33
+ "lib/recipes/bundler.rb",
34
+ "lib/recipes/db.rb",
35
+ "lib/recipes/deploy.rb",
36
+ "lib/recipes/hooks.rb",
37
+ "lib/recipes/log.rb",
38
+ "lib/recipes/nginx.rb",
39
+ "lib/recipes/symlinks.rb",
40
+ "lib/recipes/unicorn.rb",
41
+ "lib/ricodigo_capistrano_recipes.rb",
42
+ "ricodigo-capistrano-recipes.gemspec"
43
+ ]
44
+ s.homepage = %q{http://github.com/ricodigo/ricodigo-capistrano-recipes}
45
+ s.licenses = ["MIT"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.7}
48
+ s.summary = %q{our capistrano recipes. forked from capistrano-recipes}
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<capistrano>, [">= 2.5.9"])
56
+ s.add_runtime_dependency(%q<capistrano-ext>, [">= 1.2.1"])
57
+ s.add_runtime_dependency(%q<mongoid>, [">= 0"])
58
+ s.add_runtime_dependency(%q<unicorn>, [">= 0"])
59
+ s.add_runtime_dependency(%q<magent>, [">= 0"])
60
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
61
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_development_dependency(%q<rcov>, [">= 0"])
64
+ else
65
+ s.add_dependency(%q<capistrano>, [">= 2.5.9"])
66
+ s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
67
+ s.add_dependency(%q<mongoid>, [">= 0"])
68
+ s.add_dependency(%q<unicorn>, [">= 0"])
69
+ s.add_dependency(%q<magent>, [">= 0"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
71
+ s.add_dependency(%q<shoulda>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ end
75
+ else
76
+ s.add_dependency(%q<capistrano>, [">= 2.5.9"])
77
+ s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
78
+ s.add_dependency(%q<mongoid>, [">= 0"])
79
+ s.add_dependency(%q<unicorn>, [">= 0"])
80
+ s.add_dependency(%q<magent>, [">= 0"])
81
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
82
+ s.add_dependency(%q<shoulda>, [">= 0"])
83
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
84
+ s.add_dependency(%q<rcov>, [">= 0"])
85
+ end
86
+ end
87
+
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ricodigo-capistrano-recipes
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - David A. Cuadrado
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-13 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: capistrano
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 5
30
+ - 9
31
+ version: 2.5.9
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: capistrano-ext
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 2
45
+ - 1
46
+ version: 1.2.1
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: mongoid
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: unicorn
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: magent
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ name: jeweler
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 1
98
+ - 6
99
+ - 0
100
+ version: 1.6.0
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: shoulda
106
+ requirement: &id007 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: *id007
117
+ - !ruby/object:Gem::Dependency
118
+ name: bundler
119
+ requirement: &id008 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ segments:
125
+ - 1
126
+ - 0
127
+ - 0
128
+ version: 1.0.0
129
+ type: :development
130
+ prerelease: false
131
+ version_requirements: *id008
132
+ - !ruby/object:Gem::Dependency
133
+ name: rcov
134
+ requirement: &id009 !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: *id009
145
+ description: our capistrano recipes. forked from capistrano-recipes
146
+ email: krawek@gmail.com
147
+ executables: []
148
+
149
+ extensions: []
150
+
151
+ extra_rdoc_files:
152
+ - LICENSE
153
+ - README.rdoc
154
+ files:
155
+ - .document
156
+ - Gemfile
157
+ - Gemfile.lock
158
+ - LICENSE
159
+ - README.rdoc
160
+ - Rakefile
161
+ - VERSION
162
+ - generators/app.bluepill.erb
163
+ - generators/nginx.conf.erb
164
+ - generators/unicorn.rb.erb
165
+ - lib/helpers.rb
166
+ - lib/recipes/application.rb
167
+ - lib/recipes/bluepill.rb
168
+ - lib/recipes/bundler.rb
169
+ - lib/recipes/db.rb
170
+ - lib/recipes/deploy.rb
171
+ - lib/recipes/hooks.rb
172
+ - lib/recipes/log.rb
173
+ - lib/recipes/nginx.rb
174
+ - lib/recipes/symlinks.rb
175
+ - lib/recipes/unicorn.rb
176
+ - lib/ricodigo_capistrano_recipes.rb
177
+ - ricodigo-capistrano-recipes.gemspec
178
+ has_rdoc: true
179
+ homepage: http://github.com/ricodigo/ricodigo-capistrano-recipes
180
+ licenses:
181
+ - MIT
182
+ post_install_message:
183
+ rdoc_options: []
184
+
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ hash: -436794333035792505
193
+ segments:
194
+ - 0
195
+ version: "0"
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ segments:
202
+ - 0
203
+ version: "0"
204
+ requirements: []
205
+
206
+ rubyforge_project:
207
+ rubygems_version: 1.3.7
208
+ signing_key:
209
+ specification_version: 3
210
+ summary: our capistrano recipes. forked from capistrano-recipes
211
+ test_files: []
212
+