denis-capone 0.0.3 → 0.0.4

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.
data/Rakefile CHANGED
@@ -9,13 +9,11 @@ begin
9
9
  gem.email = "barushev@gmail.com"
10
10
  gem.homepage = "http://github.com/denis/capone"
11
11
  gem.authors = ["Denis Barushev"]
12
-
13
- gem.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{lib,recipes,tasks,templates}/**/*")
14
-
15
12
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ gem.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{lib,recipes,tasks,templates}/**/*")
16
14
  end
17
15
  rescue LoadError
18
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
17
  end
20
18
 
21
19
  require 'rake/testtask'
@@ -38,14 +36,14 @@ rescue LoadError
38
36
  end
39
37
  end
40
38
 
39
+ task :test => :check_dependencies
41
40
 
42
41
  task :default => :test
43
42
 
44
43
  require 'rake/rdoctask'
45
44
  Rake::RDocTask.new do |rdoc|
46
- if File.exist?('VERSION.yml')
47
- config = YAML.load(File.read('VERSION.yml'))
48
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
+ if File.exist?('VERSION')
46
+ version = File.read('VERSION')
49
47
  else
50
48
  version = ""
51
49
  end
data/recipes/deploy.rb CHANGED
@@ -4,7 +4,7 @@ namespace :capone do
4
4
  Create MySQL user and database using data from config/database.yml.
5
5
  DESC
6
6
  task :setup_db, :roles => :db, :only => { :primary => true } do
7
- config = YAML::load(File.open("config/database.yml"))["production"]
7
+ config = YAML::load(File.open("config/database.yml"))[rails_env]
8
8
  root_password = Capistrano::CLI.password_prompt(prompt="Enter a root password for MySQL: ")
9
9
 
10
10
  run "mysql -u root --password=#{root_password} -e \"CREATE DATABASE IF NOT EXISTS #{config["database"]} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT ALL PRIVILEGES ON #{config["database"]}.* TO '#{config["username"]}'@'localhost' IDENTIFIED BY '#{config["password"]}' WITH GRANT OPTION;\""
@@ -16,5 +16,12 @@ namespace :capone do
16
16
  task :install_gems, :roles => :app do
17
17
  run "rake gems:install -f #{release_path}/Rakefile"
18
18
  end
19
+
20
+ desc <<-DESC
21
+ Load fixtures from db/fixtures to the database
22
+ DESC
23
+ task :load_fixtures, :roles => :db, :only => { :primary => true } do
24
+ run "rake db:fixtures:load FIXTURES_PATH=db/fixtures RAILS_ENV=#{rails_env} -f #{release_path}/Rakefile"
25
+ end
19
26
  end
20
27
  end
data/recipes/nginx.rb ADDED
@@ -0,0 +1,26 @@
1
+ namespace :capone do
2
+ namespace :nginx do
3
+ desc <<-DESC
4
+ Enable virtual host.
5
+ DESC
6
+ task :enable_vhost do
7
+ sudo "ln -fs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
8
+ sudo "/etc/init.d/nginx reload"
9
+ end
10
+
11
+ desc <<-DESC
12
+ Disable virtual host.
13
+ DESC
14
+ task :disable_vhost do
15
+ sudo "rm /etc/nginx/sites-enabled/#{application}"
16
+ sudo "/etc/init.d/nginx reload"
17
+ end
18
+
19
+ desc <<-DESC
20
+ Reload nginx configuration if config file was changed.
21
+ DESC
22
+ task :reload_if_config_file_changed do
23
+ run "bash -c \"if ! cmp #{previous_release}/config/nginx.conf #{current_path}/config/nginx.conf; then #{sudo} /etc/init.d/nginx reload; fi\""
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ # Original version of this file was excerpted from "Advanced Rails Recipes",
2
+ # published by The Pragmatic Bookshelf.
3
+ namespace :capone do
4
+ namespace :whenever do
5
+ desc <<-DESC
6
+ Update the crontab file.
7
+ DESC
8
+ task :update_crontab, :roles => :db do
9
+ run "cd #{release_path} && whenever --update-crontab #{application}"
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,5 @@
1
1
  require "mongrel_cluster/recipes"
2
+ require "capone"
2
3
 
3
4
  set :application, "set your application name here"
4
5
  set :repository, "someuser@somehost:git/#{application}.git"
@@ -11,12 +12,18 @@ set :deploy_to, "/var/www/apps/#{application}"
11
12
 
12
13
  set :mongrel_conf, "#{deploy_to}/current/config/mongrel_cluster.yml"
13
14
 
14
- role :app, "your app-server here", :cron => true
15
+ set :rails_env, "production"
16
+
17
+ role :app, "your app-server here"
15
18
  role :web, "your web-server here"
16
19
  role :db, "your db-server here", :primary => true
17
20
 
18
21
  after "deploy:setup", "capone:deploy:setup_db"
19
22
  after "deploy:update_code", "capone:deploy:install_gems"
23
+ # after "deploy:cold", "capone:deploy:load_fixtures"
24
+
25
+ before "deploy:start", "capone:nginx:enable_vhost"
26
+ after "deploy:stop", "capone:nginx:disable_vhost"
27
+ after "deploy:restart", "capone:nginx:reload_if_config_file_changed"
20
28
 
21
- # after "deploy:start", "capone:cron:start"
22
- # before "deploy:stop", "capone:cron:stop"
29
+ # after "deploy:symlink", "capone:whenever:update_crontab"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: denis-capone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Barushev
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-12 00:00:00 -07:00
12
+ date: 2009-09-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,18 +28,17 @@ files:
28
28
  - Rakefile
29
29
  - lib/capone.rb
30
30
  - recipes/backup.rb
31
- - recipes/cron.rb
32
31
  - recipes/deploy.rb
33
32
  - recipes/git.rb
34
33
  - recipes/install.rb
34
+ - recipes/nginx.rb
35
35
  - recipes/update.rb
36
+ - recipes/whenever.rb
36
37
  - tasks/capone_tasks.rake
37
38
  - templates/Capfile
38
- - templates/config/cron.erb
39
39
  - templates/config/deploy.rb
40
40
  - templates/config/mongrel_cluster.yml.erb
41
41
  - templates/config/monitrc
42
- - templates/lib/tasks/chores.rake
43
42
  - templates/system/nginx.conf
44
43
  has_rdoc: false
45
44
  homepage: http://github.com/denis/capone
data/recipes/cron.rb DELETED
@@ -1,49 +0,0 @@
1
- # Original version of this file was excerpted from "Advanced Rails Recipes",
2
- # published by The Pragmatic Bookshelf.
3
- namespace :capone do
4
- namespace :cron do
5
- desc <<-DESC
6
- Starts cron (on the cron machine only).
7
- DESC
8
- task :start, :roles => :app, :only => {:cron => true} do
9
- cron_tab = "#{shared_path}/crontab.txt"
10
-
11
- require 'erb'
12
- template = File.read("config/cron.erb")
13
- file = ERB.new(template).result(binding)
14
- put file, cron_tab, :mode => 0644
15
-
16
- # merge with the current crontab
17
- # fails with an empty crontab, which is acceptable
18
- run "crontab -l >> #{cron_tab}" rescue nil
19
-
20
- # install the new crontab
21
- run "crontab #{cron_tab}"
22
- end
23
-
24
- desc <<-DESC
25
- Stops cron (on the cron machine only).
26
- DESC
27
- task :stop, :roles => :app, :only => {:cron => true} do
28
- cron_tmp = "#{shared_path}/~crontab.txt"
29
- cron_tab = "#{shared_path}/crontab.txt"
30
-
31
- begin
32
- # dump the current cron entries
33
- run "crontab -l > #{cron_tmp}"
34
-
35
- # remove any lines that contain the application name
36
- run "awk '{if ($0 !~ /#{application}/) print $0}' " +
37
- "#{cron_tmp} > #{cron_tab}"
38
-
39
- # replace the cron entries
40
- run "crontab #{cron_tab}"
41
- rescue
42
- # fails with an empty crontab, which is acceptable
43
- end
44
-
45
- # clean up
46
- run "rm -rf #{cron_tmp}"
47
- end
48
- end
49
- end
@@ -1,3 +0,0 @@
1
- 00 * * * * RAILS_ENV=production rake -f <%= current_path %>/Rakefile chores:hourly >> <%= deploy_to %>/shared/log/cron.log
2
- 01 0 * * * RAILS_ENV=production rake -f <%= current_path %>/Rakefile chores:daily >> <%= deploy_to %>/shared/log/cron.log
3
- 02 0 * * 1 RAILS_ENV=production rake -f <%= current_path %>/Rakefile chores:weekly >> <%= deploy_to %>/shared/log/cron.log
@@ -1,30 +0,0 @@
1
- # Original version of this file was excerpted from "Advanced Rails Recipes",
2
- # published by The Pragmatic Bookshelf.
3
- namespace :chores do
4
- desc "Cron run this task once a hour"
5
- task :hourly => :environment do
6
- chore("Hourly") do
7
- # Your Code Here
8
- end
9
- end
10
-
11
- desc "Cron run this task once a day"
12
- task :daily => :environment do
13
- chore("Daily") do
14
- # Your Code Here
15
- end
16
- end
17
-
18
- desc "Cron run this task once a week"
19
- task :weekly => :environment do
20
- chore("Weekly") do
21
- # Your Code Here
22
- end
23
- end
24
-
25
- def chore(name)
26
- puts "#{name} Task Invoked: #{Time.now}"
27
- yield
28
- puts "#{name} Task Finished: #{Time.now}"
29
- end
30
- end