capone 0.0.5

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Denis Barushev
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,14 @@
1
+ = Capone
2
+
3
+ Capone is the set of rake tasks and capistrano recipes that help to:
4
+ * generate configs;
5
+ * prepare servers for production use;
6
+ * deploy applications;
7
+ * maintain servers.
8
+
9
+ Capone supports only Ubuntu 8.04 LTS as an OS, Mongrel as an application server,
10
+ nginx as a web server, MySQL as a database server and Subversion or git as a SCM.
11
+
12
+ == Copyright
13
+
14
+ Copyright (c) 2009 Denis Barushev. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capone"
8
+ gem.summary = "Capone is the set of rake tasks and capistrano recipes."
9
+ gem.email = "barushev@gmail.com"
10
+ gem.homepage = "http://github.com/denis/capone"
11
+ gem.authors = ["Denis Barushev"]
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}/**/*")
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ if File.exist?('VERSION')
46
+ version = File.read('VERSION')
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "capone #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/lib/capone.rb ADDED
@@ -0,0 +1,9 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "Capone requires Capistrano 2"
3
+ end
4
+
5
+ Capistrano::Configuration.instance.load do
6
+ Dir["#{File.dirname(__FILE__)}/../recipes/*.rb"].each do |recipe|
7
+ load(recipe)
8
+ end
9
+ end
data/recipes/backup.rb ADDED
@@ -0,0 +1,17 @@
1
+ namespace :capone do
2
+ namespace :backup do
3
+ desc <<-DESC
4
+ Backup all.
5
+ DESC
6
+ task :default do
7
+ mysql
8
+ end
9
+
10
+ desc <<-DESC
11
+ Backup MySQL database.
12
+ DESC
13
+ task :mysql, :roles => :db, :only => { :primary => true } do
14
+ run "echo 'Not implemented yet.'"
15
+ end
16
+ end
17
+ end
data/recipes/deploy.rb ADDED
@@ -0,0 +1,27 @@
1
+ namespace :capone do
2
+ namespace :deploy do
3
+ desc <<-DESC
4
+ Create MySQL user and database using data from config/database.yml.
5
+ DESC
6
+ task :setup_db, :roles => :db, :only => { :primary => true } do
7
+ config = YAML::load(File.open("config/database.yml"))[rails_env]
8
+ root_password = Capistrano::CLI.password_prompt(prompt="Enter a root password for MySQL: ")
9
+
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;\""
11
+ end
12
+
13
+ desc <<-DESC
14
+ Install gems needed by application.
15
+ DESC
16
+ task :install_gems, :roles => :app do
17
+ run "rake gems:install -f #{release_path}/Rakefile RAILS_ENV=#{rails_env}"
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
26
+ end
27
+ end
data/recipes/git.rb ADDED
@@ -0,0 +1,14 @@
1
+ namespace :capone do
2
+ namespace :git do
3
+ desc <<-DESC
4
+ Creates a remote repository and adds it as origin to the local repository.
5
+ DESC
6
+ task :remote do
7
+ run "mkdir ~/git/#{application}.git && cd ~/git/#{application}.git && git --bare init"
8
+
9
+ cmd = "git remote add origin #{repository} && git push origin master"
10
+ puts cmd
11
+ `#{cmd}`
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,105 @@
1
+ namespace :capone do
2
+ namespace :install do
3
+ desc <<-DESC
4
+ Install all software for all servers.
5
+ DESC
6
+ task :default do
7
+ update::software
8
+ app
9
+ web
10
+ db
11
+ end
12
+
13
+ desc <<-DESC
14
+ Install all software for app server.
15
+ DESC
16
+ task :app, :roles => :app do
17
+ git
18
+ ruby
19
+ rubygems
20
+ gems
21
+ mongrel
22
+ end
23
+
24
+ desc <<-DESC
25
+ Install all software for web server.
26
+ DESC
27
+ task :web, :roles => :web do
28
+ nginx
29
+ end
30
+
31
+ desc <<-DESC
32
+ Install all software for db server.
33
+ DESC
34
+ task :db, :roles => :db do
35
+ mysql
36
+ end
37
+
38
+ desc <<-DESC
39
+ Install Subversion.
40
+ DESC
41
+ task :subversion, :roles => :app do
42
+ sudo "aptitude install -y subversion"
43
+ end
44
+
45
+ desc <<-DESC
46
+ Install git.
47
+ DESC
48
+ task :git, :roles => :app do
49
+ sudo "aptitude install -y git-core"
50
+ end
51
+
52
+ desc <<-DESC
53
+ Install Ruby.
54
+ DESC
55
+ task :ruby, :roles => :app do
56
+ sudo "aptitude install -y ruby ruby1.8-dev irb irb1.8 rdoc rdoc1.8 libopenssl-ruby1.8 libreadline-ruby1.8"
57
+ end
58
+
59
+ desc <<-DESC
60
+ Install RubyGems.
61
+ DESC
62
+ task :rubygems, :roles => :app do
63
+ sudo "aptitude install -y libgems-ruby1.8 rubygems"
64
+ sudo "gem update --system --no-rdoc --no-ri"
65
+ sudo "ln -fs /usr/bin/gem1.8 /usr/bin/gem"
66
+ end
67
+
68
+ desc <<-DESC
69
+ Install common gems.
70
+ DESC
71
+ task :gems, :roles => :app do
72
+ sudo "aptitude install -y build-essential libmysqlclient15-dev"
73
+ sudo "gem install rake mysql --no-rdoc --no-ri"
74
+ end
75
+
76
+ desc <<-DESC
77
+ Install Mongrel.
78
+ DESC
79
+ task :mongrel, :roles => :app do
80
+ sudo "gem install mongrel mongrel_cluster --no-rdoc --no-ri"
81
+
82
+ sudo "ln -sf /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/mongrel_cluster"
83
+ sudo "chmod +x /etc/init.d/mongrel_cluster"
84
+ sudo "/usr/sbin/update-rc.d mongrel_cluster defaults"
85
+ sudo "mkdir /etc/mongrel_cluster"
86
+
87
+ sudo "mkdir -p -m 750 /var/www/apps"
88
+ sudo "chown deploy:deploy /var/www/apps"
89
+ end
90
+
91
+ desc <<-DESC
92
+ Install nginx.
93
+ DESC
94
+ task :nginx, :roles => :web do
95
+ sudo "aptitude install -y nginx"
96
+ end
97
+
98
+ desc <<-DESC
99
+ Install MySQL.
100
+ DESC
101
+ task :mysql, :roles => :db do
102
+ sudo "aptitude install -y mysql-server"
103
+ end
104
+ end
105
+ 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
data/recipes/update.rb ADDED
@@ -0,0 +1,26 @@
1
+ namespace :capone do
2
+ namespace :update do
3
+ desc <<-DESC
4
+ Update all.
5
+ DESC
6
+ task :default do
7
+ software
8
+ gems
9
+ end
10
+
11
+ desc <<-DESC
12
+ Update system software.
13
+ DESC
14
+ task :software do
15
+ sudo "aptitude update"
16
+ sudo "aptitude safe-upgrade -y"
17
+ end
18
+
19
+ desc <<-DESC
20
+ Update installed gems.
21
+ DESC
22
+ task :gems do
23
+ sudo "gem update --no-rdoc --no-ri"
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
@@ -0,0 +1,17 @@
1
+ desc "Init Capone"
2
+ task :capone do
3
+ puts "Generating configs..."
4
+
5
+ files = ["Capfile", "config/deploy.rb"]
6
+
7
+ for file in files do
8
+ if File.exists? "#{RAILS_ROOT}/#{file}"
9
+ puts "#{RAILS_ROOT}/#{file} already exists"
10
+ else
11
+ File.copy "#{RAILS_ROOT}/vendor/plugins/capone/templates/#{file}", "#{RAILS_ROOT}/#{file}"
12
+ end
13
+ end
14
+ end
15
+
16
+ namespace :capone do
17
+ end
data/templates/Capfile ADDED
@@ -0,0 +1,3 @@
1
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2
+ Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
3
+ load 'config/deploy'
@@ -0,0 +1,29 @@
1
+ require "mongrel_cluster/recipes"
2
+ require "capone"
3
+
4
+ set :application, "set your application name here"
5
+ set :repository, "someuser@somehost:git/#{application}.git"
6
+ set :scm, :git
7
+
8
+ set :user, "deploy"
9
+ set :use_sudo, false
10
+
11
+ set :deploy_to, "/var/www/apps/#{application}"
12
+
13
+ set :mongrel_conf, "#{deploy_to}/current/config/mongrel_cluster.yml"
14
+
15
+ set :rails_env, "production"
16
+
17
+ role :app, "your app-server here"
18
+ role :web, "your web-server here"
19
+ role :db, "your db-server here", :primary => true
20
+
21
+ after "deploy:setup", "capone:deploy:setup_db"
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"
28
+
29
+ # after "deploy:symlink", "capone:whenever:update_crontab"
@@ -0,0 +1,18 @@
1
+ ---
2
+ cwd: <%= @deploy_to %>/current
3
+ <% if @mongrel_log_file %>
4
+ log_file: <%= @mongrel_log_file %>
5
+ <% end %>
6
+ port: <%= @mongrel_port %>
7
+ environment: <%= @mongrel_environment %>
8
+ address: <%= @mongrel_address %>
9
+ <% if @mongrel_pid_file %>
10
+ pid_file: <%= @mongrel_pid_file %>
11
+ <% end %>
12
+ servers: <%= @mongrel_servers %>
13
+ <% if @mongrel_user %>
14
+ user: <%= @mongrel_user %>
15
+ <% end %>
16
+ <% if @mongrel_group %>
17
+ group: <%= @mongrel_group %>
18
+ <% end %>
@@ -0,0 +1,57 @@
1
+ set daemon 60
2
+ set logfile syslog facility log_daemon
3
+ set mailserver localhost
4
+ set mail-format { from: monit@localhost }
5
+ set alert root@localhost
6
+
7
+ check process sshd with pidfile /var/run/sshd.pid
8
+ start program "/etc/init.d/ssh start"
9
+ stop program "/etc/init.d/ssh stop"
10
+ if failed port 22 protocol ssh then restart
11
+ if 5 restarts within 5 cycles then timeout
12
+
13
+ check process mysql with pidfile /var/run/mysqld/mysqld.pid
14
+ group database
15
+ start program = "/etc/init.d/mysql start"
16
+ stop program = "/etc/init.d/mysql stop"
17
+ if failed host 127.0.0.1 port 3306 then restart
18
+ if 5 restarts within 5 cycles then timeout
19
+
20
+ check process httpd with pidfile /usr/local/apache2/logs/httpd.pid
21
+ group www-data
22
+ start program "/usr/local/apache2/bin/apachectl start"
23
+ stop program "/usr/local/apache2/bin/apachectl stop"
24
+ if failed host localhost port 80 protocol http
25
+ and request "/" then alert
26
+ if cpu is greater than 60% for 2 cycles then alert
27
+ if cpu > 80% for 5 cycles then restart
28
+ if children > 250 then restart
29
+ if loadavg(5min) greater than 10 for 8 cycles then alert
30
+ if 3 restarts within 5 cycles then timeout
31
+
32
+ check process mongrel_8000 with pidfile /var/rails/MYAPP/log/mongrel.8000.pid
33
+ group root
34
+ if failed host 127.0.0.1 port 8000 protocol http
35
+ and request "/" then alert
36
+ if cpu is greater than 60% for 2 cycles then alert
37
+ if cpu > 80% for 5 cycles then restart
38
+ if loadavg(5min) greater than 10 for 8 cycles then restart
39
+ if 3 restarts within 5 cycles then timeout
40
+
41
+ check process mongrel_8001 with pidfile /var/rails/MYAPP/log/mongrel.8001.pid
42
+ group root
43
+ if failed host 127.0.0.1 port 8001 protocol http
44
+ and request "/" then alert
45
+ if cpu is greater than 60% for 2 cycles then alert
46
+ if cpu > 80% for 5 cycles then alert
47
+ if loadavg(5min) greater than 10 for 8 cycles then alert
48
+ if 3 restarts within 5 cycles then timeout
49
+
50
+ check process postfix with pidfile /var/spool/postfix/pid/master.pid
51
+ group mail
52
+ start program = "/etc/init.d/postfix start"
53
+ stop program = "/etc/init.d/postfix stop"
54
+ if failed port 25 protocol smtp then restart
55
+ if 5 restarts within 5 cycles then timeout
56
+
57
+
@@ -0,0 +1,58 @@
1
+ # User and group to run as
2
+ user www-data;
3
+
4
+ # Number of nginx worker processes
5
+ worker_processes 4;
6
+
7
+ # Path to main error log file
8
+ error_log /var/log/nginx/error.log;
9
+
10
+ # Path to the pid-file
11
+ pid /var/run/nginx.pid;
12
+
13
+ events {
14
+ # max_clients = worker_processes * worker_connections
15
+ worker_connections 1024;
16
+ }
17
+
18
+ http {
19
+ # Include mime types config file
20
+ include /etc/nginx/mime.types;
21
+
22
+ # Assigns the default MIME-type to be used for files where
23
+ # the standard MIME map doesn't specify anything
24
+ default_type application/octet-stream;
25
+
26
+ # Define log format for access log
27
+ log_format main '$remote_addr - $remote_user [$time_local] '
28
+ '"$request" $status $body_bytes_sent "$http_referer" '
29
+ '"$http_user_agent" "$http_x_forwarded_for"';
30
+
31
+ # Assigns path, format and size of access log file
32
+ access_log /var/log/nginx/access.log main;
33
+
34
+ # Activate the usage of sendfile()
35
+ sendfile on;
36
+
37
+ # tcp_nodelay on;
38
+ # tcp_nopush on;
39
+
40
+ # Set the timeout for keep-alive connections with the client
41
+ keepalive_timeout 75;
42
+
43
+ # Enable gzip compression
44
+ gzip on;
45
+
46
+ # The compression level, between 1 and 9, where 1 is the least
47
+ # compression (fastest) and 9 is the most (slowest).
48
+ gzip_comp_level 1;
49
+
50
+ # Enable compression for all proxy requests
51
+ gzip_proxied any;
52
+
53
+ # Enable compression for additional MIME-types
54
+ gzip_types text/plain text/html text/css text/javascript application/x-javascript text/xml application/xml application/xml+rss;
55
+
56
+ # Include all virtaul hosts configurations
57
+ include /etc/nginx/sites-enabled/*;
58
+ }
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Denis Barushev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-06 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: barushev@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - lib/capone.rb
30
+ - recipes/backup.rb
31
+ - recipes/deploy.rb
32
+ - recipes/git.rb
33
+ - recipes/install.rb
34
+ - recipes/nginx.rb
35
+ - recipes/update.rb
36
+ - recipes/whenever.rb
37
+ - tasks/capone_tasks.rake
38
+ - templates/Capfile
39
+ - templates/config/deploy.rb
40
+ - templates/config/mongrel_cluster.yml.erb
41
+ - templates/config/monitrc
42
+ - templates/system/nginx.conf
43
+ has_rdoc: true
44
+ homepage: http://github.com/denis/capone
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Capone is the set of rake tasks and capistrano recipes.
71
+ test_files: []
72
+