ricodigo-capistrano-recipes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "capistrano", ">= 2.5.9"
4
+ gem "capistrano-ext", ">= 1.2.1"
5
+ gem "mongoid"
6
+ gem "unicorn"
7
+ gem "magent"
8
+
9
+ group :development do
10
+ gem "jeweler", "~> 1.6.0"
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "rcov", ">= 0"
14
+ end
15
+
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.7)
5
+ activesupport (= 3.0.7)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activesupport (3.0.7)
9
+ addressable (2.2.6)
10
+ bson (1.3.1)
11
+ builder (2.1.2)
12
+ capistrano (2.6.0)
13
+ highline
14
+ net-scp (>= 1.0.0)
15
+ net-sftp (>= 2.0.0)
16
+ net-ssh (>= 2.0.14)
17
+ net-ssh-gateway (>= 1.1.0)
18
+ capistrano-ext (1.2.1)
19
+ capistrano (>= 1.0.0)
20
+ em-websocket (0.3.0)
21
+ addressable (>= 2.1.1)
22
+ eventmachine (>= 0.12.9)
23
+ eventmachine (0.12.10)
24
+ git (1.2.5)
25
+ highline (1.6.2)
26
+ i18n (0.5.0)
27
+ jeweler (1.6.0)
28
+ bundler (~> 1.0.0)
29
+ git (>= 1.2.5)
30
+ rake
31
+ kgio (2.4.0)
32
+ magent (0.5.4)
33
+ em-websocket
34
+ em-websocket
35
+ mongo
36
+ mongo (~> 1.0)
37
+ uuidtools
38
+ uuidtools
39
+ mongo (1.3.1)
40
+ bson (>= 1.3.1)
41
+ mongoid (2.0.1)
42
+ activemodel (~> 3.0)
43
+ mongo (~> 1.3)
44
+ tzinfo (~> 0.3.22)
45
+ will_paginate (~> 3.0.pre)
46
+ net-scp (1.0.4)
47
+ net-ssh (>= 1.99.1)
48
+ net-sftp (2.0.5)
49
+ net-ssh (>= 2.0.9)
50
+ net-ssh (2.1.4)
51
+ net-ssh-gateway (1.1.0)
52
+ net-ssh (>= 1.99.1)
53
+ rack (1.2.2)
54
+ rake (0.8.7)
55
+ rcov (0.9.9)
56
+ shoulda (2.11.3)
57
+ tzinfo (0.3.27)
58
+ unicorn (3.6.2)
59
+ kgio (~> 2.3)
60
+ rack
61
+ uuidtools (2.1.2)
62
+ will_paginate (3.0.pre2)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 1.0.0)
69
+ capistrano (>= 2.5.9)
70
+ capistrano-ext (>= 1.2.1)
71
+ jeweler (~> 1.6.0)
72
+ magent
73
+ mongoid
74
+ rcov
75
+ shoulda
76
+ unicorn
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2011 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.
data/README.rdoc ADDED
@@ -0,0 +1,88 @@
1
+ =Capistrano Recipes
2
+
3
+ Useful Capistrano recipes including:
4
+
5
+ * Create Mongoid database and user on server (via prompts)
6
+ * Create standalone copy of mongoid.yml in shared path (via prompts)
7
+ * Log rotation and tailing commands
8
+ * Configure, start/stop/restart Unicorn application server
9
+ * Send commands to Bluepill monitoring tools
10
+
11
+ ==Included Tasks
12
+
13
+ * cap db:create_yaml
14
+ * cap db:mongoid:setup
15
+ * cap db:mongoid:dump
16
+ * cap db:mongoid:fetch_dump
17
+ * cap db:mongoid:restore
18
+ * cap log:rotate
19
+ * cap log:tail
20
+ * cap nginx:setup
21
+ * cap nginx:start
22
+ * cap nginx:stop
23
+ * cap nginx:restart
24
+ * cap nginx:status
25
+ * cap unicorn:start
26
+ * cap unicorn:stop
27
+ * cap unicorn:restart
28
+ * cap unicorn:setup
29
+ * cap symlinks:make
30
+ * cap bluepill:install
31
+ * cap bluepill:init
32
+ * cap bluepill:start
33
+ * cap bluepill:restart
34
+ * cap bluepill:stop
35
+ * cap bluepill:status
36
+
37
+
38
+ ==Installation
39
+
40
+ Easy as pie...
41
+
42
+ Install this gem:
43
+
44
+ sudo gem install ricodigo-capistrano-recipes
45
+
46
+ To setup the initial Capistrano deploy file, go to your Rails app folder via command line and enter:
47
+
48
+ capify .
49
+
50
+ ==Configuration
51
+
52
+ Inside the newly created config/deploy.rb, add:
53
+
54
+ require 'capistrano/ext/multistage' # only require if you've installed Cap ext gem
55
+
56
+ # This one should go at the end of your deploy.rb
57
+ require 'ricodigo_capistrano_recipes'
58
+
59
+ ===RVM
60
+
61
+ RVM is enabled by default. You can disable it by setting :using_rvm to false, or leverage it
62
+ by setting your rvm_ruby_string to appropriate ones (default is ree)
63
+
64
+ If using_rvm is true, the rvm recipe will load rvm's own capistrano extensions so you don't
65
+ have to worry about it during deploy. Just make sure you have everything set up right, like
66
+ .rvmrc on project root and system-wide install on the servers.
67
+
68
+ See (http://rvm.beginrescueend.com/rvm/install) for more info.
69
+
70
+ ===Nginx
71
+
72
+ If you're using nginx as your web server, set :web_server to :nginx and deploy:setup will
73
+ generate the appropriate configuration file for it based on your other variables, such as
74
+ :application_uses_ssl, etc.
75
+
76
+ ===Unicorn
77
+
78
+ If you're running Unicorn (http://unicorn.bogomips.org/) be sure to add this line instead:
79
+
80
+ set :server, :unicorn
81
+
82
+ ==Contributors (thank you!)
83
+
84
+ https://github.com/ricodigo/ricodigo-capistrano-recipes/contributors
85
+
86
+ ==Copyright
87
+
88
+ Copyright (c) 2009-2011 Webficient LLC, Phil Misiowiec. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "ricodigo-capistrano-recipes"
16
+ gem.homepage = "http://github.com/ricodigo/ricodigo-capistrano-recipes"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{our capistrano recipes. forked from capistrano-recipes}
19
+ gem.description = %Q{our capistrano recipes. forked from capistrano-recipes}
20
+ gem.email = "krawek@gmail.com"
21
+ gem.authors = ["David A. Cuadrado"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ricodigo-capistrano-recipes #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,35 @@
1
+ app_name = '<%= application %>'
2
+ rails_root = '<%= deploy_to %>/current'
3
+ rails_env = '<%= environment %>'
4
+ log_file = "#{rails_root}/log/bluepill.log"
5
+ unicorn_bin = '<%= unicorn_bin %>'
6
+ unicorn_pid = '<%= unicorn_pid %>'
7
+ unicorn_config = '<%= unicorn_remote_config %>'
8
+ unicorn_start_cmd = '<%= unicorn_start_cmd %>'
9
+ unicorn_stop_cmd = '<%= unicorn_stop_cmd %>'
10
+ unicorn_restart_cmd = '<%= unicorn_restart_cmd %>'
11
+
12
+
13
+ puts ">> Starting #{app_name} bluepill with RAILS_ROOT=#{rails_root} and RAILS_ENV=#{rails_env}"
14
+
15
+ Bluepill.application(app_name, :log_file => log_file) do |app|
16
+ app.process("unicorn-#{app_name}") do |process|
17
+ process.pid_file = unicorn_pid
18
+ process.working_dir = rails_root
19
+
20
+ process.start_command = unicorn_start_cmd
21
+ process.stop_command = unicorn_stop_cmd
22
+ process.restart_command = unicorn_restart_cmd
23
+
24
+ process.start_grace_time = 8.seconds
25
+ process.stop_grace_time = 5.seconds
26
+ process.restart_grace_time = 13.seconds
27
+
28
+ process.monitor_children do |child_process|
29
+ child_process.stop_command = "kill -QUIT {{PID}}"
30
+
31
+ child_process.checks :mem_usage, :every => 15.seconds, :below => 165.megabytes, :times => [3,4], :fires => :stop
32
+ child_process.checks :cpu_usage, :every => 15.seconds, :below => 90, :times => [3,4], :fires => :stop
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,185 @@
1
+ upstream <%= application %>_app_server {
2
+ server unix:<%= unicorn_socket %> fail_timeout=0;
3
+ }
4
+
5
+ # <%= application %> Server
6
+ server {
7
+ listen <%= application_port %>;
8
+ client_max_body_size 500M;
9
+ server_name <%= nginx_domains %>;
10
+
11
+ # ~2 seconds is often enough for most folks to parse HTML/CSS and
12
+ # retrieve needed images/icons/frames, connections are cheap in
13
+ # nginx so increasing this is generally safe...
14
+ keepalive_timeout 5;
15
+
16
+ # path for static files
17
+ root <%= deploy_to %>/current/public;
18
+ access_log <%= deploy_to %>/current/log/nginx.access.log main;
19
+ error_log <%= deploy_to %>/current/log/nginx.error.log info;
20
+
21
+ # this rewrites all the requests to the maintenance.html
22
+ # page if it exists in the doc root. This is for capistrano's
23
+ # disable web task
24
+ if (-f $document_root/system/maintenance.html) {
25
+ rewrite ^(.*)$ /system/maintenance.html last;
26
+ break;
27
+ }
28
+
29
+ location / {
30
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31
+ proxy_set_header Host $http_host;
32
+
33
+ # If the file exists as a static file serve it directly without
34
+ # running all the other rewite tests on it
35
+ if (-f $request_filename) {
36
+ break;
37
+ }
38
+
39
+ # check for index.html for directory index
40
+ # if its there on the filesystem then rewite
41
+ # the url to add /index.html to the end of it
42
+ # and then break to send it to the next config rules.
43
+ if (-f $request_filename/index.html) {
44
+ rewrite (.*) $1/index.html break;
45
+ }
46
+
47
+ # this is the meat of the rails page caching config
48
+ # it adds .html to the end of the url and then checks
49
+ # the filesystem for that file. If it exists, then we
50
+ # rewite the url to have explicit .html on the end
51
+ # and then send it on its way to the next config rule.
52
+ # if there is no file on the fs then it sets all the
53
+ # necessary headers and proxies to our upstream mongrels
54
+ if (-f $request_filename.html) {
55
+ rewrite (.*) $1.html break;
56
+ }
57
+
58
+ if (!-f $request_filename) {
59
+ proxy_pass http://<%= application %>_app_server;
60
+ break;
61
+ }
62
+ }
63
+
64
+ # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
65
+ # BUT there's a chance it could break the ajax calls.
66
+ location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
67
+ expires max;
68
+ break;
69
+ }
70
+
71
+ location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
72
+ expires max;
73
+ break;
74
+ }
75
+
76
+ # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
77
+ # BUT there's a chance it could break the ajax calls.
78
+ location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
79
+ expires max;
80
+ break;
81
+ }
82
+
83
+ location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
84
+ expires max;
85
+ break;
86
+ }
87
+
88
+ # if the request is for a static resource, nginx should serve it directly
89
+ # and add a far future expires header to it, making the browser
90
+ # cache the resource and navigate faster over the website
91
+ location ~ ^/(images|javascripts|stylesheets|system)/ {
92
+ root <%= deploy_to %>/current/public;
93
+ expires max;
94
+ break;
95
+ }
96
+
97
+ # Rails error pages
98
+ error_page 500 502 503 504 /500.html;
99
+ location = /500.html {
100
+ root <%= deploy_to %>/current/public;
101
+ }
102
+ }
103
+
104
+ <% if application_uses_ssl %>
105
+
106
+ upstream <%= application %>_app_ssl {
107
+ server unix:<%= unicorn_socket %> fail_timeout=0;
108
+ }
109
+
110
+ # This server is setup for ssl. Uncomment if
111
+ # you are using ssl as well as port 80.
112
+ server {
113
+ listen <%= application_port_ssl %>;
114
+ server_name <%= nginx_domains %>;
115
+
116
+ ssl on;
117
+ ssl_certificate /etc/ssl/certs/server.crt;
118
+ ssl_certificate_key /etc/ssl/private/server.key;
119
+ ssl_session_timeout 5m;
120
+ client_max_body_size 50M;
121
+
122
+ root <%= deploy_to %>/current/public;
123
+ access_log <%= deploy_to %>/current/log/nginx.access.log main;
124
+ error_log <%= deploy_to %>/current/log/nginx.error.log info;
125
+
126
+ # this rewrites all the requests to the maintenance.html
127
+ # page if it exists in the doc root. This is for capistrano's
128
+ # disable web task
129
+ if (-f $document_root/system/maintenance.html) {
130
+ rewrite ^(.*)$ /system/maintenance.html last;
131
+ break;
132
+ }
133
+
134
+ location / {
135
+ # needed to forward user's IP address to rails
136
+ proxy_set_header X-Real-IP $remote_addr;
137
+
138
+ # needed for HTTPS
139
+ proxy_set_header X_FORWARDED_PROTO https;
140
+
141
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
142
+ proxy_set_header Host $http_host;
143
+ proxy_redirect off;
144
+ proxy_max_temp_file_size 0;
145
+
146
+
147
+ # If the file exists as a static file serve it directly without
148
+ # running all the other rewite tests on it
149
+ if (-f $request_filename) {
150
+ break;
151
+ }
152
+
153
+ # check for index.html for directory index
154
+ # if its there on the filesystem then rewite
155
+ # the url to add /index.html to the end of it
156
+ # and then break to send it to the next config rules.
157
+ if (-f $request_filename/index.html) {
158
+ rewrite (.*) $1/index.html break;
159
+ }
160
+
161
+ # this is the meat of the rails page caching config
162
+ # it adds .html to the end of the url and then checks
163
+ # the filesystem for that file. If it exists, then we
164
+ # rewite the url to have explicit .html on the end
165
+ # and then send it on its way to the next config rule.
166
+ # if there is no file on the fs then it sets all the
167
+ # necessary headers and proxies to our upstream mongrels
168
+ if (-f $request_filename.html) {
169
+ rewrite (.*) $1.html break;
170
+ }
171
+
172
+ <% if is_using_unicorn %>
173
+ if (!-f $request_filename) {
174
+ proxy_pass http://<%= application %>_app_ssl;
175
+ break;
176
+ }
177
+ <% end %>
178
+ }
179
+
180
+ error_page 500 502 503 504 /500.html;
181
+ location = /500.html {
182
+ root <%= deploy_to %>/current/public;
183
+ }
184
+ }
185
+ <% end %>