commonthread-common_recipies 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 CommonThread, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the contact_info plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the contact_info plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'common_recipies'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "common_recipies"
3
+ s.version = "0.1.0"
4
+ s.date = "2008-11-03"
5
+ s.summary = "Provides common capistrano recipies that are useful in all rails apps"
6
+ s.email = "ben@commonthread.com"
7
+ s.homepage = "http://github.com/commonthread/common_recipies"
8
+ s.description = "Provides common capistrano recipies that are useful in all rails apps"
9
+ s.has_rdoc = true
10
+ s.authors = ["Ben Wyrosdick"]
11
+ s.files = ["README",
12
+ "LICENSE",
13
+ "Rakefile",
14
+ "common_recipies.gemspec",
15
+ "lib/common_recipies.rb"]
16
+ s.rdoc_options = ["--main", "README"]
17
+ s.extra_rdoc_files = ["README"]
18
+ end
@@ -0,0 +1,285 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :deploy do
3
+ desc 'Setup server for deployment'
4
+ task :setup do
5
+ run "umask 02 && mkdir -p #{deploy_to} #{deploy_to}/releases #{deploy_to}/shared #{deploy_to}/shared/system #{deploy_to}/shared/log #{deploy_to}/shared/pids"
6
+
7
+ database_yml = <<-EOF
8
+ production:
9
+ adapter: mysql
10
+ database: #{application}
11
+ username: root
12
+ password: changeme
13
+ host: localhost
14
+ EOF
15
+
16
+ put database_yml, "#{shared_path}/database.yml"
17
+ end
18
+
19
+ desc 'Runs the deploy for a first time'
20
+ task :first_time do
21
+ update
22
+ run "cd #{current_path} && rake db:create"
23
+ run "cd #{current_path} && rake db:schema:load"
24
+ restart
25
+ end
26
+ end
27
+
28
+ namespace :util do
29
+ desc "check how many people are using the system"
30
+ task :current_users, :roles => :web do
31
+ run "#{current_path}/script/current_users"
32
+ end
33
+
34
+ desc "check the current env variables on the server"
35
+ task :check_env do
36
+ run "env"
37
+ end
38
+ end
39
+
40
+ # ====================
41
+ # = Slicehost Recipe =
42
+ # ====================
43
+ namespace :slicehost do
44
+ desc "Setup Environment"
45
+ task :setup_env do
46
+ update_apt_get
47
+ install_dev_tools
48
+ install_logrotate
49
+ install_git
50
+ install_mysql
51
+ install_rails_stack
52
+ install_imagemagick
53
+ install_apache
54
+ config_apache
55
+ enable_rewrite
56
+ enable_deflate
57
+ install_passenger
58
+ config_passenger
59
+ config_vhost
60
+ restart_apache
61
+ end
62
+
63
+ desc "Update apt-get sources"
64
+ task :update_apt_get do
65
+ sudo "apt-get update"
66
+ end
67
+
68
+ desc "Install Development Tools"
69
+ task :install_dev_tools do
70
+ sudo "apt-get install build-essential -y"
71
+ end
72
+
73
+ desc "Install DNS Tools"
74
+ task :install_dns_tools do
75
+ sudo "apt-get install dnsutils -y"
76
+ end
77
+
78
+ desc "Install Git"
79
+ task :install_git do
80
+ sudo "apt-get install git-core git-svn -y"
81
+ end
82
+
83
+ desc "Install Subversion"
84
+ task :install_subversion do
85
+ sudo "apt-get install subversion -y"
86
+ end
87
+
88
+ desc "Install SQLite3"
89
+ task :install_sqlite3, :roles => :db do
90
+ sudo "apt-get install sqlite3 libsqlite3-ruby -y"
91
+ end
92
+
93
+ desc "Install MySQL"
94
+ task :install_mysql, :roles => :db do
95
+ sudo "apt-get install libmysql-ruby mysql-client libmysqlclient15-dev -y"
96
+ end
97
+
98
+ desc "Install ImageMagick"
99
+ task :install_imagemagick, :roles => :app do
100
+ sudo "apt-get install imagemagick -y"
101
+ end
102
+
103
+ desc "Install Ruby, Gems, and Rails"
104
+ task :install_rails_stack, :roles => :app do
105
+ sudo "apt-get install ruby ruby1.8-dev irb ri rdoc libopenssl-ruby1.8 -y"
106
+
107
+ [
108
+ "mkdir -p src",
109
+ "cd src",
110
+ "wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz",
111
+ "tar xvzf rubygems-1.0.1.tgz",
112
+ "cd rubygems-1.0.1/ && sudo ruby setup.rb",
113
+ ].each {|cmd| run cmd}
114
+
115
+ sudo "ln -s /usr/bin/gem1.8 /usr/bin/gem"
116
+
117
+ rails_versions.each {|version| sudo "gem install rails -v #{version} --no-ri --no-rdoc"}
118
+ end
119
+
120
+ desc "Install Apache"
121
+ task :install_apache, :roles => :web do
122
+ sudo "apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 apache2-prefork-dev libapr1-dev -y"
123
+ end
124
+
125
+ desc "Configure Apache"
126
+ task :config_apache, :roles => :web do
127
+ deflate_config = <<-EOF
128
+ ServerName localhost
129
+ EOF
130
+
131
+ put deflate_config, "src/httpd.conf"
132
+ sudo "mv src/httpd.conf /etc/apache2/httpd.conf"
133
+
134
+ restart_apache
135
+ end
136
+
137
+ desc "Enable Apache mod_rewrite"
138
+ task :enable_rewrite, :roles => :web do
139
+ sudo "a2enmod rewrite"
140
+
141
+ force_apache
142
+ end
143
+
144
+ desc "Disable Apache mod_rewrite"
145
+ task :disable_rewrite, :roles => :web do
146
+ sudo "a2dismod rewrite"
147
+
148
+ force_apache
149
+ end
150
+
151
+ desc "Restart Apache"
152
+ task :restart_apache, :roles => :web do
153
+ sudo "apache2ctl restart"
154
+ end
155
+
156
+ desc "Force-Reload Apache"
157
+ task :force_apache, :roles => :web do
158
+ sudo "/etc/init.d/apache2 force-reload"
159
+ end
160
+
161
+ desc "Enable/Configure Deflate on Apache"
162
+ task :enable_deflate, :roles => :web do
163
+ deflate_config = <<-EOF
164
+ <IfModule mod_deflate.c>
165
+ # AddOutputFilterByType DEFLATE text/html text/plain text/xml
166
+ AddOutputFilterByType DEFLATE application/x-javascript text/css
167
+ </IfModule>
168
+ EOF
169
+
170
+ put deflate_config, "src/deflate.conf"
171
+ sudo "mv src/deflate.conf /etc/apache2/mods-available/deflate.conf"
172
+
173
+ sudo "a2enmod deflate"
174
+
175
+ force_apache
176
+ end
177
+
178
+ desc "Disable Deflate on Apache"
179
+ task :disable_deflate, :roles => :web do
180
+ sudo "a2dismod deflate"
181
+
182
+ force_apache
183
+ end
184
+
185
+ desc "Install Passenger"
186
+ task :install_passenger do
187
+ sudo "gem install passenger -v 2.0.2 --no-ri --no-rdoc"
188
+ input = ''
189
+ run "sudo passenger-install-apache2-module" do |ch,stream,out|
190
+ next if out.chomp == input.chomp || out.chomp == ''
191
+ print out
192
+ ch.send_data(input = $stdin.gets) if out =~ /enter/i
193
+ end
194
+ end
195
+
196
+ desc "Configure Passenger"
197
+ task :config_passenger do
198
+ passenger_config =<<-EOF
199
+ LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2/ext/apache2/mod_passenger.so
200
+ PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2
201
+ PassengerRuby /usr/bin/ruby
202
+ PassengerPoolIdleTime 1800
203
+ #PassengerMaxPoolSize 20
204
+ PassengerMaxInstancesPerApp 3
205
+
206
+ #RailsSpawnMethod conservative
207
+ RailsAllowModRewrite on
208
+ EOF
209
+
210
+ put passenger_config, "src/passenger"
211
+ sudo "mv src/passenger /etc/apache2/conf.d/passenger"
212
+
213
+ force_apache
214
+ end
215
+
216
+ desc "Configure VHost"
217
+ task :config_vhost, :roles => :web do
218
+ vhost_config =<<-EOF
219
+ <VirtualHost *:80>
220
+ ServerName #{server_name}
221
+ ServerAlias #{server_aliases.join(' ')}
222
+ DocumentRoot #{deploy_to}/current/public
223
+
224
+ <IfModule mod_rewrite.c>
225
+ # Check for maintenance file and allow images, styles and javascripts
226
+ RewriteEngine On
227
+ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
228
+ RewriteCond %{SCRIPT_FILENAME} !maintenance.html
229
+ RewriteCond %{SCRIPT_FILENAME} !^/(images|stylesheets|javascripts)/(.+)$
230
+ RewriteRule ^.*$ /system/maintenance.html [L]
231
+ </IfModule>
232
+
233
+ <Directory "#{deploy_to}/current/public">
234
+ Options FollowSymLinks
235
+ AllowOverride None
236
+ Order allow,deny
237
+ Allow from all
238
+ </Directory>
239
+ </VirtualHost>
240
+ EOF
241
+ put vhost_config, "src/vhost_config"
242
+ sudo "mv src/vhost_config /etc/apache2/sites-available/#{application}"
243
+ sudo "a2ensite #{application}"
244
+
245
+ restart_apache
246
+ end
247
+
248
+ desc "Install logrotate to handle rotation of log files"
249
+ task :install_logrotate, :roles => :app do
250
+ sudo "apt-get install logrotate -y"
251
+ end
252
+
253
+ desc "Configure logrotate to handle rotation of the production log files"
254
+ task :config_logrotate, :roles => :app do
255
+ logrotate_config =<<-EOF
256
+ #{shared_path}/log/production.log {
257
+ daily
258
+ rotate 7
259
+ compress
260
+ missingok
261
+ sharedscripts
262
+ postrotate
263
+ touch #{current_path}/tmp/restart.txt
264
+ endscript
265
+ }
266
+ EOF
267
+
268
+ put logrotate_config, "src/rails_#{application}"
269
+ sudo "mv src/rails_#{application} /etc/logrotate.d/rails_#{application}"
270
+ end
271
+ end
272
+
273
+ desc "Install a gem on the remote server"
274
+ task :gem_install, :roles => :app do
275
+ gem_name = Capistrano::CLI.ui.ask "What gem would you like to install? "
276
+
277
+ sudo "gem install #{gem_name} --no-rdoc --no-ri"
278
+ end
279
+
280
+ after :"deploy:update_code" do
281
+ run "rm -f #{current_release}/config/database.yml"
282
+ run "ln -s #{shared_path}/database.yml #{current_release}/config/database.yml"
283
+ run "rm -f #{current_release}/public/.htaccess"
284
+ end
285
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commonthread-common_recipies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Wyrosdick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Provides common capistrano recipies that are useful in all rails apps
17
+ email: ben@commonthread.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - README
26
+ - LICENSE
27
+ - Rakefile
28
+ - common_recipies.gemspec
29
+ - lib/common_recipies.rb
30
+ has_rdoc: true
31
+ homepage: http://github.com/commonthread/common_recipies
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --main
35
+ - README
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.2.0
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: Provides common capistrano recipies that are useful in all rails apps
57
+ test_files: []
58
+