AppTower-ubistrano 1.0.2 → 1.1.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,12 @@
1
+ Version 1.1.0
2
+ -------------
3
+
4
+ * Sinatra apps deploying properly
5
+ * PHP and Rails apps should be deploying properly
6
+ * `cap ubuntu` flow hardened
7
+
8
+ Version 1.0.3
9
+ -------------
10
+
11
+ * `cap ubuntu` tested on Ubuntu 8.04 LTS Hardy
12
+ * App deploying not at all tested
@@ -14,7 +14,7 @@ Capistrano::Configuration.instance(:must_exist).load do
14
14
  namespace :virtual_host do
15
15
  desc "Create a new virtual host"
16
16
  task :create, :roles => :web do
17
- upload_from_erb "/etc/apache2/sites-available/#{application}_#{stage}", binding, :name => 'virtual_host', :folder => 'ubuntu'
17
+ upload_from_erb "/etc/apache2/sites-available/#{application}_#{stage}", binding, :name => 'virtual_host', :folder => 'apache'
18
18
  end
19
19
 
20
20
  desc "Enable a virtual host"
@@ -3,10 +3,7 @@ Capistrano::Configuration.instance(:must_exist).load do
3
3
  namespace :deploy do
4
4
  desc "Restart application"
5
5
  task :restart, :roles => :app, :except => { :no_release => true } do
6
- run_each [
7
- "mkdir #{current_path}/tmp",
8
- "touch #{current_path}/tmp/restart.txt"
9
- ]
6
+ run_each "touch #{current_path}/tmp/restart.txt"
10
7
  end
11
8
 
12
9
  desc "Start application"
@@ -27,25 +24,28 @@ Capistrano::Configuration.instance(:must_exist).load do
27
24
  ]
28
25
  mysql.create.db
29
26
  deploy.setup
30
- deploy.update
31
- apache.virtual_host.create
32
27
  case platform
28
+ when :php
29
+ deploy.update
33
30
  when :rails
34
31
  rails.config.default
32
+ deploy.update
35
33
  deploy.migrate
36
34
  when :sinatra
37
35
  sinatra.config.default
36
+ deploy.update
38
37
  sinatra.install
39
38
  end
39
+ apache.virtual_host.create
40
40
  deploy.start
41
41
  apache.reload
42
42
  end
43
43
 
44
44
  desc "Stop servers and destroy all files"
45
45
  task :destroy, :roles => :app do
46
- deploy.stop
47
46
  sudo "rm -Rf #{deploy_to}"
48
47
  mysql.destroy.db
48
+ apache.virtual_host.destroy
49
49
  end
50
50
  end
51
51
 
@@ -113,7 +113,7 @@ Capistrano::Configuration.instance(:must_exist).load do
113
113
  end
114
114
 
115
115
  def space(str)
116
- "\n#{'=' * 90}\n#{str}"
116
+ "\n#{'=' * 80}\n#{str}"
117
117
  end
118
118
 
119
119
 
@@ -161,12 +161,13 @@ If not, instructions for doing it manually will be displayed."
161
161
  "Please run these manually:
162
162
  sudo aptitude update
163
163
  sudo aptitude upgrade
164
- sudo aptitude build-essential"
164
+ sudo aptitude build-essential
165
+ Continue?"
165
166
  when :create_keys
166
167
  "May I generate an rsa ssh key pair in your ~/.ssh folder?"
167
168
  when :create_server_keys
168
- "May I generate an rsa ssh key pair in the server's ~/.ssh folder?
169
- The public key will be displayed."
169
+ "May I generate an rsa ssh key pair on the server?
170
+ The public key will be displayed for adding to your GitHub account."
170
171
  when :god
171
172
  "May I install God?"
172
173
  when :god_apache
@@ -175,7 +176,7 @@ See #{File.expand_path '../../', File.dirname(__FILE__)}/templates/ubuntu/apache
175
176
  when :god_mysql
176
177
  "Would you like God to monitor mysql?
177
178
  See #{File.expand_path '../../', File.dirname(__FILE__)}/templates/ubuntu/mysql.god.erb"
178
- when :god_apache
179
+ when :god_sshd
179
180
  "Would you like God to monitor sshd?
180
181
  See #{File.expand_path '../../', File.dirname(__FILE__)}/templates/ubuntu/sshd.god.erb"
181
182
  when :have_keys
@@ -199,6 +200,8 @@ Reload apache?"
199
200
  "It is highly recommended you run mysql_secure_installation manually.
200
201
  See http://dev.mysql.com/doc/refman/5.1/en/mysql-secure-installation.html
201
202
  Continue?"
203
+ when :sinatra_install
204
+ "Would you like to run install.rb (from your app) if it exists?"
202
205
  when :ssh_keys_create
203
206
  "Create rsa ssh key pairs locally or remotely? (default: remote)"
204
207
  when :ssh_keys_upload
@@ -215,7 +218,8 @@ Continue?"
215
218
  "May I add sudo-without-password privileges for the deploy user?
216
219
  I will have to edit /etc/sudoers."
217
220
  when :ubuntu_restart
218
- "Would you like to restart the server now?"
221
+ "Its probably a good idea to restart the server now.
222
+ OK?"
219
223
  when :ubuntu_finished
220
224
  "That's it! Glad you made it.
221
225
 
@@ -3,7 +3,9 @@ Capistrano::Configuration.instance(:must_exist).load do
3
3
  namespace :sinatra do
4
4
  desc "Runs install.rb if exists"
5
5
  task :install do
6
- run_puts "if [ -e #{current_path}/install.rb ]; then sudo ruby #{current_path}/install.rb; fi"
6
+ if yes(msg(:sinatra_install))
7
+ run_puts "if [ -e #{current_path}/install.rb ]; then sudo ruby #{current_path}/install.rb; fi"
8
+ end
7
9
  end
8
10
 
9
11
  namespace :config do
data/lib/ubistrano/ssh.rb CHANGED
@@ -3,16 +3,22 @@ Capistrano::Configuration.instance(:must_exist).load do
3
3
  namespace :ssh do
4
4
  desc 'Generate ssh keys and upload to server'
5
5
  task :default do
6
- ssh.keys.create
6
+ ssh.keys.create.remote
7
+ ssh.keys.create.local
7
8
  ssh.keys.upload
8
9
  end
9
10
 
10
11
  namespace :keys do
11
- desc "Creates an rsa ssh key pair (local or remote)"
12
- task :create do
13
- if ask(msg(:ssh_keys_create))[0..0].downcase == 'l'
14
- system('ssh-keygen -t rsa') if yes(msg(:create_keys))
15
- else
12
+ namespace :create do
13
+ desc "Creates an rsa ssh key pair (local)"
14
+ task :local do
15
+ if ask(msg(:ssh_keys_create))[0..0].downcase == 'l'
16
+ system('ssh-keygen -t rsa') if yes(msg(:create_keys))
17
+ end unless yes(msg(:have_keys))
18
+ end
19
+
20
+ desc "Creates an rsa ssh key pair (remote)"
21
+ task :remote do
16
22
  if yes(msg(:create_server_keys))
17
23
  pass = ask "Enter a password for this key:"
18
24
  sudo_each [
@@ -22,7 +28,7 @@ Capistrano::Configuration.instance(:must_exist).load do
22
28
  ]
23
29
  sudo_puts "tail -1 /home/#{user}/.ssh/id_rsa.pub"
24
30
  end
25
- end unless yes(msg(:have_keys))
31
+ end
26
32
  end
27
33
 
28
34
  desc "Uploads local ssh public keys into remote authorized_keys"
@@ -4,16 +4,13 @@ Capistrano::Configuration.instance(:must_exist).load do
4
4
  desc "Set up a fresh Ubuntu server"
5
5
  task :default do
6
6
  puts space(msg(:about_templates))
7
- if yes("Have you already created the user defined in deploy.rb?")
8
- ssh.default
9
- ubuntu.config.default
10
- ubuntu.aptitude.default
11
- ubuntu.install.default
12
- ubuntu.restart
13
- puts space(msg(:ubuntu_finished))
14
- else
15
- puts space(msg(:visudo))
16
- end
7
+ puts space(msg(:visudo)) unless yes("Have you already created the user defined in deploy.rb?")
8
+ ssh.default
9
+ ubuntu.config.default
10
+ ubuntu.aptitude.default
11
+ ubuntu.install.default
12
+ ubuntu.restart
13
+ puts space(msg(:ubuntu_finished))
17
14
  end
18
15
 
19
16
  desc "Restart Ubuntu server"
@@ -23,6 +20,14 @@ Capistrano::Configuration.instance(:must_exist).load do
23
20
  end
24
21
  end
25
22
 
23
+ desc "Restart Ubuntu server and wait"
24
+ task :restart_and_wait do
25
+ if yes(msg(:ubuntu_restart))
26
+ sudo_each 'shutdown -r now'
27
+ exit unless yes('Please wait a little while for your server to restart. Continue?')
28
+ end
29
+ end
30
+
26
31
  namespace :aptitude do
27
32
  desc 'Run all aptitude tasks'
28
33
  task :default do
@@ -31,8 +36,9 @@ Capistrano::Configuration.instance(:must_exist).load do
31
36
  aptitude.upgrade
32
37
  aptitude.essential
33
38
  else
34
- msg :aptitude_instructions
39
+ exit unless yes(msg(:aptitude_instructions))
35
40
  end
41
+ ubuntu.restart_and_wait
36
42
  end
37
43
 
38
44
  desc 'Aptitude update'
@@ -118,7 +124,8 @@ Capistrano::Configuration.instance(:must_exist).load do
118
124
  if yes("May I install Apache?")
119
125
  sudo_puts [
120
126
  'aptitude install apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapr1 libaprutil1 ssl-cert -q -y',
121
- 'a2enmod rewrite'
127
+ 'a2enmod rewrite',
128
+ 'a2dissite default'
122
129
  ]
123
130
  end
124
131
  end
@@ -138,7 +145,7 @@ Capistrano::Configuration.instance(:must_exist).load do
138
145
  if yes("May I install MySQL?")
139
146
  sudo_puts 'aptitude install mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 libmysqlclient15-dev libmysqlclient15off -q -y'
140
147
  ROOT.mysql.create.user
141
- yes msg(:secure_mysql)
148
+ exit unless yes(msg(:secure_mysql))
142
149
  end
143
150
  end
144
151
 
@@ -151,7 +158,7 @@ Capistrano::Configuration.instance(:must_exist).load do
151
158
  "cd #{bin} && sudo chmod 0700 mysqltuner.pl",
152
159
  "cd #{bin} && sudo mv mysqltuner.pl mysqltuner"
153
160
  ]
154
- yes msg(:mysqltuner_instructions)
161
+ exit unless yes(msg(:mysqltuner_instructions))
155
162
  end
156
163
  end
157
164
 
@@ -193,12 +200,12 @@ Capistrano::Configuration.instance(:must_exist).load do
193
200
 
194
201
  desc 'Install Ruby'
195
202
  task :ruby, :roles => :app do
196
- install_source(:ruby) do |path|
197
- sudo_puts [
198
- "aptitude install libopenssl-ruby -q -y",
199
- make_install(path)
200
- ]
201
- end if yes("May I install Ruby?")
203
+ if yes("May I install Ruby?")
204
+ sudo_puts "aptitude install libopenssl-ruby -q -y"
205
+ install_source(:ruby) do |path|
206
+ sudo_puts make_install(path)
207
+ end
208
+ end
202
209
  end
203
210
 
204
211
  desc 'Install RubyGems'
@@ -235,7 +242,7 @@ Capistrano::Configuration.instance(:must_exist).load do
235
242
  upload_from_erb('/usr/local/etc/god/sshd.god', binding, :folder => 'ubuntu') if yes(msg(:god_sshd))
236
243
  sudo_puts [
237
244
  'update-rc.d god defaults',
238
- './etc/init.d/god start'
245
+ '/etc/init.d/god start'
239
246
  ]
240
247
  end
241
248
  end
data/lib/ubistrano.rb CHANGED
@@ -5,19 +5,42 @@ Dir["#{File.dirname(__FILE__)}/ubistrano/*.rb"].each { |f| require f }
5
5
 
6
6
  Capistrano::Configuration.instance(:must_exist).load do
7
7
 
8
- # Reference ROOT when namespaces clash
9
- ROOT = self
8
+ # Default capistrano/ubistrano values
9
+ set :ubistrano, {
10
+ :base_dir => '/var/www',
11
+ :db_user => 'app',
12
+ :db_pass => '',
13
+ :deploy_via => :remote_cache,
14
+ :domain => [],
15
+ :platform => :rails,
16
+ :plugins => {},
17
+ :port => 22,
18
+ :repository_cache => 'git_cache',
19
+ :scm => :git,
20
+ :stage => :production,
21
+ :use_sudo => false,
22
+ :user => 'deploy',
23
+ :versions => {}
24
+ }.merge(ubistrano)
25
+
26
+ # Default plugins
27
+ ubistrano[:plugins] = {
28
+ :app_helpers => false,
29
+ :asset_packager => false,
30
+ :attachment_fu => false,
31
+ :rails_widget => false,
32
+ :thinking_sphinx => false
33
+ }.merge(ubistrano[:plugins])
10
34
 
11
- # Default package versions
12
- ubistrano[:versions] ||= {}
13
- ubistrano[:versions].merge!(
35
+ # Default versions
36
+ ubistrano[:versions] = {
14
37
  :git => '1.6.0.4',
15
38
  :mysecureshell => '1.1',
16
39
  :rails => '2.2.2',
17
40
  :ruby => '1.8.7-p72',
18
41
  :rubygems => '1.3.1',
19
42
  :sphinx => '0.9.8.1'
20
- )
43
+ }.merge(ubistrano[:versions])
21
44
 
22
45
  # Merge ubistrano hash with capistrano
23
46
  ubistrano.each do |key, value|
@@ -26,46 +49,30 @@ Capistrano::Configuration.instance(:must_exist).load do
26
49
  set(key, value)
27
50
  end
28
51
 
29
- # Set default capistrano values
30
- set :db_user, fetch(:db_user, 'app')
31
- set :db_pass, fetch(:db_pass, '')
32
- set :platform, fetch(:platform, :rails)
33
- set :port, fetch(:port, 22)
34
- set :stage, fetch(:stage, :production)
35
- set :use_sudo, fetch(:use_sudo, false)
36
- set :user, fetch(:user, 'deploy')
37
- set :sources, fetch(:sources, {
52
+ # Default sources
53
+ set :sources, {
38
54
  :git => "http://kernel.org/pub/software/scm/git/git-#{versions_git}.tar.gz",
39
55
  :mysecureshell => "http://internap.dl.sourceforge.net/sourceforge/mysecureshell/MySecureShell-#{versions_mysecureshell}_source.tgz",
40
56
  :mysqltuner => "http://mysqltuner.com/mysqltuner.pl",
41
57
  :ruby => "ftp://ftp.ruby-lang.org/pub/ruby/#{versions_ruby.split('.')[0..1].join('.')}/ruby-#{versions_ruby}.tar.gz",
42
58
  :rubygems => "http://rubyforge.org/frs/download.php/45905/rubygems-#{versions_rubygems}.tgz",
43
59
  :sphinx => "http://www.sphinxsearch.com/downloads/sphinx-#{versions_sphinx}.tar.gz"
44
- })
60
+ }.merge(fetch(:sources, {}))
45
61
 
46
- # Rails plugins
47
- set :app_helpers, fetch(:app_helpers, false)
48
- set :rails_widget, fetch(:rails_widget, false)
49
- set :ultrasphinx, fetch(:ultrasphinx, false)
50
- set :thinking_sphinx, fetch(:thinking_sphinx, false)
51
- set :attachment_fu, fetch(:attachment_fu, false)
52
- set :asset_packager, fetch(:asset_packager, false)
53
- after('deploy:update_code', 'rails:config:app_helpers') if app_helpers
54
- after('deploy:update_code', 'rails:config:asset_packager') if asset_packager
55
- after('deploy:update_code', 'rails:config:attachment_fu') if attachment_fu
56
- after('deploy:update_code', 'rails:config:rails_widget') if rails_widget
57
- after('deploy:update_code', 'rails:config:ultrasphinx') if ultrasphinx
58
- after('deploy:update_code', 'rails:config:thinking_sphinx') if thinking_sphinx
59
-
60
- # Git by default
61
- set :scm, :git
62
- set :deploy_via, :remote_cache
63
- set :repository_cache, 'git_cache'
64
- ssh_options[:paranoid] = false
65
-
66
62
  # Events
67
- on :before, 'setup_stage', :except => [ :staging, :testing ] # Executed before every task
68
- after('deploy:update_code', 'rails:config:to_app' ) if platform == :rails
69
- after('deploy:update_code', 'sinatra:config:to_app') if platform == :sinatra
63
+ on :before, 'setup_stage', :except => [ :staging, :testing ] # Executed before every task
64
+ after('deploy:update_code', 'rails:config:to_app' ) if platform == :rails
65
+ after('deploy:update_code', 'sinatra:config:to_app') if platform == :sinatra
66
+ after('deploy:update_code', 'rails:config:app_helpers') if plugins_app_helpers
67
+ after('deploy:update_code', 'rails:config:asset_packager') if plugins_asset_packager
68
+ after('deploy:update_code', 'rails:config:attachment_fu') if plugins_attachment_fu
69
+ after('deploy:update_code', 'rails:config:rails_widget') if plugins_rails_widget
70
+ after('deploy:update_code', 'rails:config:thinking_sphinx') if plugins_thinking_sphinx
71
+
72
+ # Other options
73
+ ssh_options[:paranoid] = false
74
+
75
+ # Reference ROOT when namespaces clash
76
+ ROOT = self
70
77
 
71
78
  end
@@ -1,8 +1,7 @@
1
1
  <VirtualHost *:80>
2
-
2
+ <% unless domain.empty? %>
3
3
  ServerName <%= domain.first %>
4
4
  ServerAlias <%= domain[1..-1].join ' ' %>
5
-
5
+ <% end %>
6
6
  DocumentRoot <%= deploy_to %>/current/public
7
-
8
7
  </VirtualHost>
@@ -1,10 +1,19 @@
1
1
  require 'sinatra'
2
2
  require 'rubygems'
3
-
3
+
4
4
  Sinatra::Application.default_options.merge!(
5
5
  :run => false,
6
- :env => :production
6
+ :env => :production,
7
+ :raise_errors => true,
8
+ :app_file => 'app.rb',
9
+ :root => '<%= deploy_to %>/current',
10
+ :views => '<%= deploy_to %>/current/views',
11
+ :public => '<%= deploy_to %>/current/public'
7
12
  )
8
-
9
- require 'app.rb'
13
+
14
+ log = File.new('<%= deploy_to %>/shared/log/sinatra.log', 'a')
15
+ STDOUT.reopen(log)
16
+ STDERR.reopen(log)
17
+
18
+ require 'app'
10
19
  run Sinatra.application
data/ubistrano.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ubistrano'
3
- s.version = '1.0.2'
4
- s.date = '2008-12-13'
3
+ s.version = '1.1.0'
4
+ s.date = '2008-12-14'
5
5
 
6
6
  s.summary = "Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano"
7
7
  s.description = "Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano"
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  MIT-LICENSE
18
18
  README.markdown
19
19
  Rakefile
20
- changelog.rdoc
20
+ changelog.markdown
21
21
  example/deploy.rb
22
22
  lib/ubistrano.rb
23
23
  lib/ubistrano/apache.rb
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: AppTower-ubistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AppTower
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-13 00:00:00 -08:00
12
+ date: 2008-12-14 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,7 +25,7 @@ files:
25
25
  - MIT-LICENSE
26
26
  - README.markdown
27
27
  - Rakefile
28
- - changelog.rdoc
28
+ - changelog.markdown
29
29
  - example/deploy.rb
30
30
  - lib/ubistrano.rb
31
31
  - lib/ubistrano/apache.rb
data/changelog.rdoc DELETED
@@ -1,25 +0,0 @@
1
-
2
- Version 2.0.0
3
- * Tested on Ubuntu 8.04 LTS Hardy
4
- * Deploys PHP, Rails, and Sinatra apps
5
- * Redux version with new stack
6
- * Apache
7
- * Git
8
- * God
9
- * MySQL
10
- * Passenger (mod_rails)
11
- * Rails
12
- * Ruby Enterprise Edition
13
-
14
- Version 1.1.0
15
- * Tested on Debian Etch
16
- * Git
17
- * Nginx
18
- * Mongrel cluster
19
- * Monit
20
- * MySQL
21
- * PHP (Nginx w/ spawn-fcgi)
22
- * Rails
23
- * Ruby
24
- * RubyGems
25
- * Sphinx