deprec 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ == deprec quickstart (with svn, trac and deployment to apache/mongrel/mysql)
2
+
3
+ Here are instructions that will take a fresh install of Ubuntu Dapper (6.06.1 server), create a working rails app, create an SVN repository and trac installation for it and deploy it using apache, mongrel and mysql.
4
+
5
+ All commands below are run on your local host. You will *never* be requested
6
+ to log into the remote server manually. Capistrano does all the work.
7
+
8
+ - Mike
9
+
10
+
11
+ # Install deprec on workstation
12
+ sudo gem install deprec --include-dependencies
13
+ echo 'require "deprec/recipes"' >> ~/.caprc
14
+ echo 'ssh_options[:keys] = %w(~/.ssh/id_dsa)' >> ~/.caprc
15
+ echo 'ssh_options[:paranoid] = false' >> ~/.caprc
16
+ echo 'ssh_options[:forward_agent] = true' >> ~/.caprc
17
+
18
+ # Create rails project on workstation and configure for deprec
19
+ # (alternatively use an existing project)
20
+ rails example
21
+ cd example
22
+ ./script/generate scaffold_resource person name:string age:integer
23
+ deprec --apply-to . --name example --domain www.example.com
24
+
25
+ # NOTE! Use following two commands if you only have 'root' account on server
26
+ # Some VPS services provide you with this when you sign up
27
+ cap change_root_password_as_root # '_as_root' means run this as 'root' user
28
+ cap setup_admin_account_as_root
29
+
30
+ # Copy your ssh keys to remote server to avoid having to type passwords
31
+ cap setup_ssh_keys
32
+
33
+ # Install all required software on remote server
34
+ cap install_rails_stack svn_install trac_install
35
+
36
+ # Import application into subversion respository and setup trac
37
+ cap svn_setup
38
+ cap trac_setup
39
+ cap trac_user_add # this command allows you to create other trac users
40
+ cap trac_start # trac is now available on http://www.example.com:9000/
41
+ cap trac_stop # if you had the need
42
+
43
+ # Deploy application
44
+ cap setup
45
+ cap deploy_with_migrations
46
+ cap apache_restart
47
+ # application is now running on http://www.example.com/people
@@ -1,19 +1,14 @@
1
- == Slicehost extras
1
+ == Slicehost specific notes for deprec
2
2
 
3
- # A freshly built slice gives you the root account
4
- # This creates a user account with sudo access
5
- # The '_as_root' means 'log in as root to do this'
6
- #
7
- export HOSTS=deptest.deprecated.org
8
- cap setup_admin_account_as_root # XXX echo new username
9
- cap setup_ssh_keys # XXX do for others also
10
- cap install_rails_stack
11
- cap install_php
12
- cap setup
13
- cap deploy_with_migrations
14
- cap restart_apache
3
+ # Slicehost provides you with root login and password for your slice.
15
4
 
16
- # svn+trac
17
- cap install_svn
18
- cap svn_setup_repos
5
+ # Change the root password!
6
+ cap change_root_password_as_root # '_as_root' means run this as 'root' user
19
7
 
8
+ # Create an account with sudo access
9
+ cap setup_admin_account_as_root
10
+
11
+ # Copy your ssh keys to remote server to avoid having to type passwords
12
+ cap setup_ssh_keys
13
+
14
+ now read README.quickstart
@@ -0,0 +1,19 @@
1
+ == svn and trac
2
+
3
+ Installs subversion and trac software on server.
4
+ Creates subversion repository on server and imports project.
5
+ Sets up trac installation for project.
6
+
7
+ role :scm, 'deptest.deprecated.org'
8
+
9
+ # install packages
10
+ cap apache_install svn_install trac_install
11
+
12
+ # import project
13
+ cap svn_import_project
14
+ cap trac_init
15
+ cap trac_start
16
+
17
+ # your project will be viewable at http://yourdomain:8000/
18
+ # you can add other users with 'cap trac_user_add'
19
+
@@ -0,0 +1,35 @@
1
+ module Capistrano
2
+ # The CLI class encapsulates the behavior of capistrano when it is invoked
3
+ # as a command-line utility. This allows other programs to embed ST and
4
+ # preserve it's command-line semantics.
5
+ class CLI
6
+
7
+ # Prompt for a password using echo suppression.
8
+ def self.password_prompt(prompt="Password: ")
9
+ sync = STDOUT.sync
10
+ begin
11
+ with_echo do
12
+ STDOUT.sync = true
13
+ print(prompt)
14
+ STDIN.gets.chomp
15
+ end
16
+ ensure
17
+ STDOUT.sync = sync
18
+ puts
19
+ end
20
+ end
21
+
22
+ def self.prompt(prompt="Password: ")
23
+ sync = STDOUT.sync
24
+ begin
25
+ STDOUT.sync = true
26
+ print(prompt)
27
+ STDIN.gets.chomp
28
+ ensure
29
+ STDOUT.sync = sync
30
+ puts
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -2,10 +2,10 @@
2
2
  require 'capistrano'
3
3
 
4
4
  module Deprec
5
- DEPREC_TEMPLATES_BASE = File.join(File.dirname(__FILE__), '..', 'recipes', 'templates')
5
+ DEPREC_TEMPLATES_BASE = File.join(File.dirname(__FILE__), '..', 'templates')
6
6
 
7
7
  def render_template_to_file(template_name, destination_file_name, templates_dir = DEPREC_TEMPLATES_BASE)
8
- template_name += '.conf' if File.extname(template_name) == ''
8
+ template_name += '.conf' if File.extname(template_name) == '' # XXX this to be removed
9
9
 
10
10
  file = File.join(templates_dir, template_name)
11
11
  buffer = render :template => File.read(file)
@@ -21,7 +21,7 @@ module Deprec
21
21
  # XXX if options[:requires_sudo] and :use_sudo then use sudo
22
22
  sudo <<-END
23
23
  sh -c '
24
- grep "#{value}" #{filename} > /dev/null 2>&1 ||
24
+ grep -F "#{value}" #{filename} > /dev/null 2>&1 ||
25
25
  test ! -f #{filename} ||
26
26
  echo "#{value}" >> #{filename}
27
27
  '
@@ -13,6 +13,7 @@ set :domain, "<%= domain_name %>"
13
13
  role :web, domain
14
14
  role :app, domain
15
15
  role :db, domain, :primary => true
16
+ role :scm, domain
16
17
 
17
18
  # =============================================================================
18
19
  # REQUIRED VARIABLES
@@ -1,15 +1,19 @@
1
1
  require 'deprec/recipes/ssh'
2
2
  require 'deprec/recipes/svn'
3
+ require 'deprec/recipes/trac'
3
4
  require 'deprec/recipes/ubuntu'
5
+ require 'deprec/recipes/apache'
6
+ require 'deprec/recipes/memcache'
4
7
  require 'deprec/third_party/mongrel_cluster/recipes'
5
8
  require 'deprec/third_party/vmbuilder/plugins'
6
9
  require 'deprec/third_party/railsmachine/recipes/apache'
7
10
  require 'deprec/third_party/railsmachine/recipes/mysql'
11
+ require 'deprec/capistrano_extensions/cli_extensions.rb'
8
12
  require 'deprec/capistrano_extensions/deprec_extensions.rb'
9
13
  require 'deprec/capistrano_extensions/actor_extensions.rb'
10
14
 
11
15
  Capistrano.configuration(:must_exist).load do
12
- set :application, lambda { application = Capistrano::CLI.password_prompt "Enter application name:" }
16
+ set :application, lambda { Capistrano::CLI.prompt "Enter application name: " }
13
17
  set :user, (defined?(user) ? user : ENV['USER']) # user who is deploying
14
18
  set :group, 'deploy' # deployment group
15
19
  set :src_dir, (defined?(src_dir) ? src_dir : '/usr/local/src') # 3rd party src on servers
@@ -30,7 +34,7 @@ Capistrano.configuration(:must_exist).load do
30
34
  install_packages_for_rails # install packages that come with distribution
31
35
  install_rubygems
32
36
  install_gems
33
- install_apache
37
+ apache_install
34
38
  end
35
39
 
36
40
  desc <<-DESC
@@ -70,7 +74,7 @@ Capistrano.configuration(:must_exist).load do
70
74
  files = ["#{deploy_to}/shared/log/mongrel.log", "#{deploy_to}/shared/log/#{rails_env}.log"]
71
75
 
72
76
  sudo "chgrp -R #{mongrel_group} #{tmp_dir} #{shared_dir}"
73
- sudo "chmod 0775 #{tmp_dir} #{shared_dir}"
77
+ sudo "chmod -R g+w #{tmp_dir} #{shared_dir}"
74
78
  # set owner and group of mongrels file (if they exist)
75
79
  files.each { |file|
76
80
  sudo "chown #{mongrel_user} #{file} || exit 0"
@@ -175,132 +179,6 @@ Capistrano.configuration(:must_exist).load do
175
179
  gem.upgrade
176
180
  gem.update_system
177
181
  end
178
-
179
- task :install_apache do
180
- version = 'httpd-2.2.4'
181
- set :src_package, {
182
- :file => version + '.tar.gz',
183
- :md5sum => '3add41e0b924d4bb53c2dee55a38c09e httpd-2.2.4.tar.gz',
184
- :dir => version,
185
- :url => "http://www.apache.org/dist/httpd/#{version}.tar.gz",
186
- :unpack => "tar zxf #{version}.tar.gz;",
187
- :configure => %w(
188
- ./configure
189
- --enable-mods-shared=all
190
- --enable-proxy
191
- --enable-proxy-balancer
192
- --enable-proxy-http
193
- --enable-rewrite
194
- --enable-cache
195
- --enable-headers
196
- --enable-ssl
197
- --enable-deflate
198
- --with-included-apr #_so_this_recipe_doesn't_break_when_rerun
199
- --enable-dav #_for_subversion_
200
- --enable-so #_for_subversion_
201
- ;
202
- ).reject{|arg| arg.match '#'}.join(' '),
203
- :make => 'make;',
204
- :install => 'make install;',
205
- :post_install => 'install -b support/apachectl /etc/init.d/httpd;'
206
- }
207
- apt.install( {:base => %w(zlib1g-dev zlib1g openssl libssl-dev)}, :stable )
208
- deprec.download_src(src_package, src_dir)
209
- deprec.install_from_src(src_package, src_dir)
210
- # ubuntu specific - should instead call generic name which can be picked up by different distros
211
- send(run_method, "update-rc.d httpd defaults")
212
- end
213
-
214
- desc "Install PHP from source"
215
- task :install_php do
216
- version = 'php-5.2.2'
217
- set :src_package, {
218
- :file => version + '.tar.gz',
219
- :md5sum => '7a920d0096900b2b962b21dc5c55fe3c php-5.2.2.tar.gz',
220
- :dir => version,
221
- :url => "http://www.php.net/distributions/#{version}.tar.gz",
222
- :unpack => "tar zxf #{version}.tar.gz;",
223
- :configure => %w(
224
- ./configure
225
- --prefix=/usr/local/php
226
- --with-apxs2=/usr/local/apache2/bin/apxs
227
- --disable-ipv6
228
- --enable-sockets
229
- --enable-soap
230
- --with-pcre-regex
231
- --with-mysql
232
- --with-zlib
233
- --with-gettext
234
- --with-sqlite
235
- --enable-sqlite-utf8
236
- --with-openssl
237
- --with-mcrypt
238
- --with-ncurses
239
- --with-jpeg-dir=/usr
240
- --with-gd
241
- --with-ctype
242
- --enable-mbstring
243
- --with-curl==/usr/lib
244
- ;
245
- ).reject{|arg| arg.match '#'}.join(' '),
246
- :make => 'make;',
247
- :install => 'make install;',
248
- :post_install => ""
249
- }
250
- apt.install( {:base => %w(zlib1g-dev zlib1g openssl libssl-dev
251
- flex libcurl3 libcurl3-dev libmcrypt-dev libmysqlclient15-dev libncurses5-dev
252
- libxml2-dev libjpeg62-dev libpng12-dev)}, :stable )
253
- run "export CFLAGS=-O2;"
254
- deprec.download_src(src_package, src_dir)
255
- deprec.install_from_src(src_package, src_dir)
256
- deprec.append_to_file_if_missing('/usr/local/apache2/conf/httpd.conf', 'AddType application/x-httpd-php .php')
257
- end
258
-
259
-
260
-
261
- # move all memcache stuff to separate file
262
- set :memcache_ip, '127.0.0.1'
263
- set :memcache_port, 11211
264
- set :memcache_memory, 256
265
-
266
- # XXX needs thought/work
267
- task :memcached_start do
268
- run "memcached -d -m #{memcache_memory} -l #{memcache_ip} -p #{memcache_port}"
269
- end
270
-
271
- # XXX needs thought/work
272
- task :memcached_stop do
273
- run "killall memcached"
274
- end
275
-
276
- # XXX needs thought/work
277
- task :memcached_restart do
278
- memcached_stop
279
- memcached_start
280
- end
281
-
282
- task :install_memcached do
283
- version = 'memcached-1.2.2'
284
- set :src_package, {
285
- :file => version + '.tar.gz',
286
- :md5sum => 'a08851f7fa7b15e92ee6320b7a79c321 memcached-1.2.2.tar.gz',
287
- :dir => version,
288
- :url => "http://www.danga.com/memcached/dist/#{version}.tar.gz",
289
- :unpack => "tar zxf #{version}.tar.gz;",
290
- :configure => %w{
291
- ./configure
292
- --prefix=/usr/local
293
- ;
294
- }.reject{|arg| arg.match '#'}.join(' '),
295
- :make => 'make;',
296
- :install => 'make install;',
297
- :post_install => 'install -b support/apachectl /etc/init.d/httpd;'
298
- }
299
- apt.install( {:base => %w(libevent-dev)}, :stable )
300
- deprec.download_src(src_package, src_dir)
301
- deprec.install_from_src(src_package, src_dir)
302
- end
303
-
304
182
 
305
183
  desc "Setup public symlink directories"
306
184
  task :setup_symlinks, :roles => [:app, :web] do
@@ -332,7 +210,7 @@ Capistrano.configuration(:must_exist).load do
332
210
  end
333
211
 
334
212
  task :setup_admin_account do
335
- user = Capistrano::CLI.password_prompt "Enter userid for new user:"
213
+ user = Capistrano::CLI.prompt "Enter userid for new user: "
336
214
  deprec.useradd(user, :shell => '/bin/bash')
337
215
  puts "Setting pasword for new account"
338
216
  sudo_with_input("passwd #{user}", /UNIX password/) # ??? how many versions of the prompt are there?
@@ -344,6 +222,15 @@ Capistrano.configuration(:must_exist).load do
344
222
  task :setup_admin_account_as_root do
345
223
  as_root { setup_admin_account }
346
224
  end
225
+
226
+ desc "Change password for the root account"
227
+ task :change_root_password do
228
+ sudo_with_input("passwd root", /UNIX password/) # ??? how many versions of the prompt are there?
229
+ end
230
+
231
+ task :change_root_password_as_root do
232
+ as_root { change_root_password }
233
+ end
347
234
 
348
235
 
349
236
  end
@@ -0,0 +1,91 @@
1
+ Capistrano.configuration(:must_exist).load do
2
+
3
+ task :install_apache do # deprecated
4
+ apache_install
5
+ end
6
+
7
+ task :apache_install do
8
+ version = 'httpd-2.2.4'
9
+ set :src_package, {
10
+ :file => version + '.tar.gz',
11
+ :md5sum => '3add41e0b924d4bb53c2dee55a38c09e httpd-2.2.4.tar.gz',
12
+ :dir => version,
13
+ :url => "http://www.apache.org/dist/httpd/#{version}.tar.gz",
14
+ :unpack => "tar zxf #{version}.tar.gz;",
15
+ :configure => %w(
16
+ ./configure
17
+ --enable-mods-shared=all
18
+ --enable-proxy
19
+ --enable-proxy-balancer
20
+ --enable-proxy-http
21
+ --enable-rewrite
22
+ --enable-cache
23
+ --enable-headers
24
+ --enable-ssl
25
+ --enable-deflate
26
+ --with-included-apr #_so_this_recipe_doesn't_break_when_rerun
27
+ --enable-dav #_for_subversion_
28
+ --enable-so #_for_subversion_
29
+ ;
30
+ ).reject{|arg| arg.match '#'}.join(' '),
31
+ :make => 'make;',
32
+ :install => 'make install;',
33
+ :post_install => 'install -b support/apachectl /etc/init.d/httpd;'
34
+ }
35
+ apt.install( {:base => %w(zlib1g-dev zlib1g openssl libssl-dev)}, :stable )
36
+ deprec.download_src(src_package, src_dir)
37
+ deprec.install_from_src(src_package, src_dir)
38
+ # ubuntu specific - should instead call generic name which can be picked up by different distros
39
+ send(run_method, "update-rc.d httpd defaults")
40
+ end
41
+
42
+ task :install_php do # deprecated
43
+ php_install
44
+ end
45
+
46
+ desc "Install PHP from source"
47
+ task :php_install do
48
+ version = 'php-5.2.2'
49
+ set :src_package, {
50
+ :file => version + '.tar.gz',
51
+ :md5sum => '7a920d0096900b2b962b21dc5c55fe3c php-5.2.2.tar.gz',
52
+ :dir => version,
53
+ :url => "http://www.php.net/distributions/#{version}.tar.gz",
54
+ :unpack => "tar zxf #{version}.tar.gz;",
55
+ :configure => %w(
56
+ ./configure
57
+ --prefix=/usr/local/php
58
+ --with-apxs2=/usr/local/apache2/bin/apxs
59
+ --disable-ipv6
60
+ --enable-sockets
61
+ --enable-soap
62
+ --with-pcre-regex
63
+ --with-mysql
64
+ --with-zlib
65
+ --with-gettext
66
+ --with-sqlite
67
+ --enable-sqlite-utf8
68
+ --with-openssl
69
+ --with-mcrypt
70
+ --with-ncurses
71
+ --with-jpeg-dir=/usr
72
+ --with-gd
73
+ --with-ctype
74
+ --enable-mbstring
75
+ --with-curl==/usr/lib
76
+ ;
77
+ ).reject{|arg| arg.match '#'}.join(' '),
78
+ :make => 'make;',
79
+ :install => 'make install;',
80
+ :post_install => ""
81
+ }
82
+ apt.install( {:base => %w(zlib1g-dev zlib1g openssl libssl-dev
83
+ flex libcurl3 libcurl3-dev libmcrypt-dev libmysqlclient15-dev libncurses5-dev
84
+ libxml2-dev libjpeg62-dev libpng12-dev)}, :stable )
85
+ run "export CFLAGS=-O2;"
86
+ deprec.download_src(src_package, src_dir)
87
+ deprec.install_from_src(src_package, src_dir)
88
+ deprec.append_to_file_if_missing('/usr/local/apache2/conf/httpd.conf', 'AddType application/x-httpd-php .php')
89
+ end
90
+
91
+ end