capistrano-recipes 0.5.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,125 @@
1
+ # God Monitoring Tool
2
+ # God is a Process Monitoring Framework written in Ruby
3
+ # More info at http://god.rubyforge.org/
4
+ #------------------------------------------------------------------------------
5
+ Capistrano::Configuration.instance.load do
6
+ _cset(:god_local_config) { "#{templates_path}/app.god.erb" }
7
+ _cset(:god_remote_config) { "#{shared_path}/config/app.god" }
8
+
9
+ namespace :god do
10
+
11
+ desc "|DarkRecipes| Parses and uploads god configuration for this app"
12
+ task :setup, :roles => :app do
13
+ generate_config(god_local_config, god_remote_config)
14
+ end
15
+
16
+ _cset(:bin_god) { defined?(:rvm_ruby_string) ? 'bootup_god' : 'god' }
17
+ _cset(:server_name) { "#{application}-#{app_server}" }
18
+ _cset(:god_init_local) { "#{docs_path}/god/god.init" }
19
+ _cset :god_init_temp, '/tmp/god.init'
20
+ _cset :god_init_remote, '/etc/init.d/god'
21
+ _cset(:god_defo_local) { "#{docs_path}/god/god"}
22
+ _cset :god_defo_temp, '/tmp/god'
23
+ _cset :god_defo_remote, '/etc/default/god'
24
+ _cset(:god_conf_local) { "#{docs_path}/god/god.conf" }
25
+ _cset :god_conf_temp, '/tmp/god.conf'
26
+ _cset :god_conf_remote, '/etc/god/god.conf'
27
+
28
+ task :setup_temp, :roles => :app do
29
+ sudo "rm -f #{god_conf_remote} #{god_init_remote} #{god_defo_remote}"
30
+ end
31
+
32
+ task :setup_conf, :roles => :app do
33
+ upload god_conf_local, god_conf_temp, :via => :scp
34
+ sudo "mkdir -p #{File.dirname(god_conf_remote)}"
35
+ sudo "mv #{god_conf_temp} #{god_conf_remote}"
36
+ end
37
+
38
+ task :setup_init, :roles => :app do
39
+ upload god_init_local, god_init_temp, :via => :scp
40
+ sudo "mv #{god_init_temp} #{god_init_remote}"
41
+ # Allow executing the init.d script
42
+ sudo "chmod +x #{god_init_remote}"
43
+ # Make it run at bootup
44
+ sudo "update-rc.d god defaults"
45
+ end
46
+
47
+ task :setup_defo, :roles => :app do
48
+ upload god_defo_local, god_defo_temp, :via => :scp
49
+ sudo "mv #{god_defo_temp} #{god_defo_remote}"
50
+ end
51
+
52
+ desc "|DarkRecipes| Bootstraps god on your server. Be careful with this."
53
+ task :bootstrap, :roles => :app do
54
+ setup_temp
55
+ setup_defo
56
+ setup_init
57
+ setup_conf
58
+
59
+ puts "God is bootstrapped. To remove use 'cap god:implode'"
60
+ end
61
+
62
+ desc "|DarkRecipes| (Seppuku) Completely remove god from the system init"
63
+ task :implode, :roles => :app do
64
+ # Removing any system startup links for /etc/init.d/god ...
65
+ sudo "update-rc.d -f god remove"
66
+
67
+ # Suicide follows.
68
+ sudo "rm -f #{god_conf_remote}"
69
+ sudo "rm -f #{god_defo_remote}"
70
+ sudo "rm -f #{god_init_remote}"
71
+ puts "God is no more."
72
+ end
73
+
74
+ desc "|DarkRecipes| Use god to restart the app"
75
+ namespace :restart do
76
+ task :default, :roles => :app, :except => { :no_release => true } do
77
+ sudo "#{bin_god} restart #{application}"
78
+ end
79
+
80
+ desc "|DarkRecipes| Restarts the app server"
81
+ task :app, :roles => :app, :except => { :no_release => true } do
82
+ sudo "#{bin_god} restart #{application}-#{app_server.to_s.downcase}"
83
+ end
84
+ end
85
+
86
+ desc "|DarkRecipes| Fetches the log for the whole group"
87
+ task :log, :roles => :app do
88
+ sudo "#{bin_god} log #{application}"
89
+ end
90
+
91
+ desc "|DarkRecipes| Reload config"
92
+ task :reload, :roles => :app do
93
+ sudo "#{bin_god} load #{god_remote_config}"
94
+ end
95
+
96
+ desc "|DarkRecipes| Start god service"
97
+ task :start, :roles => :app do
98
+ sudo "service god start"
99
+ end
100
+
101
+ desc "|DarkRecipes| Stops god service"
102
+ task :stop, :roles => :app do
103
+ sudo "service god stop"
104
+ end
105
+
106
+ desc "|DarkRecipes| Quit god, but not the processes it's monitoring"
107
+ task :quit, :roles => :app do
108
+ sudo "#{bin_god} quit"
109
+ end
110
+
111
+ desc "|DarkRecipes| Terminate god and all monitored processes"
112
+ task :terminate, :roles => :app do
113
+ sudo "#{bin_god} terminate"
114
+ end
115
+
116
+ desc "|DarkRecipes| Describe the status of the running tasks"
117
+ task :status, :roles => :app do
118
+ sudo "#{bin_god} status"
119
+ end
120
+ end
121
+
122
+ after 'deploy:setup' do
123
+ god.setup if Capistrano::CLI.ui.agree("Create app.god in app's shared path? [Yn]")
124
+ end if is_using('god', :monitorer)
125
+ end
@@ -0,0 +1,14 @@
1
+ # Common hooks for all scenarios.
2
+ Capistrano::Configuration.instance.load do
3
+ after 'deploy:setup' do
4
+ app.setup
5
+ bundler.setup if Capistrano::CLI.ui.agree("Do you need to install the bundler gem? [Yn]")
6
+ end
7
+
8
+ after "deploy:update_code" do
9
+ symlinks.make
10
+ bundler.install
11
+ end
12
+ end
13
+
14
+
@@ -1,15 +1,15 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
  namespace :log do
3
- desc "Tail application log file for the specified environment, e.g. cap staging log:tail"
3
+ desc "|DarkRecipes| Tail all application log files"
4
4
  task :tail, :roles => :app do
5
- run "tail -f #{shared_path}/log/#{environment}.log" do |channel, stream, data|
5
+ run "tail -f #{shared_path}/log/*.log" do |channel, stream, data|
6
6
  puts "#{channel[:host]}: #{data}"
7
7
  break if stream == :err
8
8
  end
9
9
  end
10
10
 
11
11
  desc <<-DESC
12
- Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
12
+ |DarkRecipes| Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
13
13
  DESC
14
14
  task :rotate, :roles => :app do
15
15
  rotate_script = %Q{#{shared_path}/log/#{environment}.log {
@@ -0,0 +1,52 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ # Where your nginx lives. Usually /opt/nginx or /usr/local/nginx for source compiled.
4
+ set :nginx_path_prefix, "/opt/nginx" unless exists?(:nginx_path_prefix)
5
+
6
+ # Path to the nginx erb template to be parsed before uploading to remote
7
+ set(:nginx_local_config) { "#{templates_path}/nginx.conf.erb" } unless exists?(:nginx_local_config)
8
+
9
+ # Path to where your remote config will reside (I use a directory sites inside conf)
10
+ set(:nginx_remote_config) do
11
+ "#{nginx_path_prefix}/conf/sites/#{application}.conf"
12
+ end unless exists?(:nginx_remote_config)
13
+
14
+ # Nginx tasks are not *nix agnostic, they assume you're using Debian/Ubuntu.
15
+ # Override them as needed.
16
+ namespace :nginx do
17
+ desc "|DarkRecipes| Parses and uploads nginx configuration for this app."
18
+ task :setup, :roles => :app , :except => { :no_release => true } do
19
+ generate_config(nginx_local_config, nginx_remote_config)
20
+ end
21
+
22
+ desc "|DarkRecipes| Parses config file and outputs it to STDOUT (internal task)"
23
+ task :parse, :roles => :app , :except => { :no_release => true } do
24
+ puts parse_config(nginx_local_config)
25
+ end
26
+
27
+ desc "|DarkRecipes| Restart nginx"
28
+ task :restart, :roles => :app , :except => { :no_release => true } do
29
+ sudo "service nginx restart"
30
+ end
31
+
32
+ desc "|DarkRecipes| Stop nginx"
33
+ task :stop, :roles => :app , :except => { :no_release => true } do
34
+ sudo "service nginx stop"
35
+ end
36
+
37
+ desc "|DarkRecipes| Start nginx"
38
+ task :start, :roles => :app , :except => { :no_release => true } do
39
+ sudo "service nginx start"
40
+ end
41
+
42
+ desc "|DarkRecipes| Show nginx status"
43
+ task :status, :roles => :app , :except => { :no_release => true } do
44
+ sudo "service nginx status"
45
+ end
46
+ end
47
+
48
+ after 'deploy:setup' do
49
+ nginx.setup if Capistrano::CLI.ui.agree("Create nginx configuration file? [Yn]")
50
+ end if is_using_nginx
51
+ end
52
+
@@ -1,18 +1,18 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
  namespace :passenger do
3
- desc "Restart Rails app running under Phusion Passenger by touching restart.txt"
3
+ desc "|DarkRecipes| Restart Rails app running under Phusion Passenger by touching restart.txt"
4
4
  task :bounce, :roles => :app do
5
5
  run "#{sudo} touch #{current_path}/tmp/restart.txt"
6
6
  end
7
7
 
8
- desc "Inspect Phusion Passenger's memory usage. Assumes binaries are located in /opt/ruby-enterprise."
8
+ desc "|DarkRecipes| Inspect Phusion Passenger's memory usage."
9
9
  task :memory, :roles => :app do
10
- run "#{sudo} /opt/ruby-enterprise/bin/passenger-memory-stats"
10
+ run "sudo passenger-memory-stats"
11
11
  end
12
12
 
13
- desc "Inspect Phusion Passenger's internal status. Assumes binaries are located in /opt/ruby-enterprise."
13
+ desc "|DarkRecipes| Inspect Phusion Passenger's internal status."
14
14
  task :status, :roles => :app do
15
- run "#{sudo} /opt/ruby-enterprise/bin/passenger-status"
15
+ run "sudo passenger-status"
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,48 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :resque do
3
+ namespace :worker do
4
+ desc "|DarkRecipes| List all workers"
5
+ task :list, :roles => :app do
6
+ run "cd #{current_path} && #{sudo} resque list"
7
+ end
8
+
9
+ desc "|DarkRecipes| Starts the workers"
10
+ task :start, :roles => :app do
11
+ run "cd #{current_path} && #{sudo} god start #{resque_service}"
12
+ end
13
+
14
+ desc "|DarkRecipes| Stops the workers"
15
+ task :stop, :roles => :app do
16
+ run "cd #{current_path} && #{sudo} god stop #{resque_service}"
17
+ end
18
+
19
+ desc "|DarkRecipes| Restart all workers"
20
+ task :restart, :roles => :app do
21
+ run "cd #{current_path} && #{sudo} god restart #{resque_service}"
22
+ end
23
+ end
24
+
25
+ namespace :web do
26
+ desc "|DarkRecipes| Starts the resque web interface"
27
+ task :start, :roles => :app do
28
+ run "cd #{current_path}; resque-web -p 9000 -e #{rails_env} "
29
+ end
30
+
31
+ desc "|DarkRecipes| Stops the resque web interface"
32
+ task :stop, :roles => :app do
33
+ run "cd #{current_path}; resque-web -K"
34
+ end
35
+
36
+ desc "|DarkRecipes| Restarts the resque web interface "
37
+ task :restart, :roles => :app do
38
+ stop
39
+ start
40
+ end
41
+
42
+ desc "|DarkRecipes| Shows the status of the resque web interface"
43
+ task :status, :roles => :app do
44
+ run "cd #{current_path}; resque-web -S"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :sphinx do
3
+ desc "|DarkRecipes| Generates Configuration file for TS"
4
+ task :config, :roles => :app do
5
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:config"
6
+ end
7
+
8
+ desc "|DarkRecipes| Starts TS"
9
+ task :start, :roles => :app do
10
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:start"
11
+ end
12
+
13
+ desc "|DarkRecipes| Stops TS"
14
+ task :stop, :roles => :app do
15
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:stop"
16
+ end
17
+
18
+ desc "|DarkRecipes| Rebuild TS"
19
+ task :rebuild, :roles => :app do
20
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:rebuild"
21
+ end
22
+
23
+ desc "|DarkRecipes| Indexes TS"
24
+ task :index, :roles => :app do
25
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:in"
26
+ end
27
+
28
+ desc "|DarkRecipes| Re-establishes symlinks"
29
+ task :symlinks do
30
+ run <<-CMD
31
+ rm -rf #{current_path}/db/sphinx && ln -nfs #{shared_path}/db/sphinx #{current_path}/db/sphinx
32
+ CMD
33
+ end
34
+ end
35
+
36
+
37
+ end
38
+
@@ -0,0 +1,27 @@
1
+ Capistrano::Configuration.instance.load do
2
+ # These are set to the same structure in shared <=> current
3
+ set :normal_symlinks, %w(tmp log config/database.yml) unless exists?(:normal_symlinks)
4
+
5
+ # Weird symlinks go somewhere else. Weird.
6
+ set :weird_symlinks, { 'bundle' => 'vendor/bundle',
7
+ 'pids' => 'tmp/pids' } unless exists?(:weird_symlinks)
8
+
9
+ namespace :symlinks do
10
+ desc "|DarkRecipes| Make all the symlinks in a single run"
11
+ task :make, :roles => :app, :except => { :no_release => true } do
12
+ commands = normal_symlinks.map do |path|
13
+ "rm -rf #{current_path}/#{path} && \
14
+ ln -s #{shared_path}/#{path} #{current_path}/#{path}"
15
+ end
16
+
17
+ commands += weird_symlinks.map do |from, to|
18
+ "rm -rf #{current_path}/#{to} && \
19
+ ln -s #{shared_path}/#{from} #{current_path}/#{to}"
20
+ end
21
+
22
+ run <<-CMD
23
+ cd #{current_path} && #{commands.join(" && ")}
24
+ CMD
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,82 @@
1
+ Capistrano::Configuration.instance.load do
2
+ # Number of workers (Rule of thumb is 2 per CPU)
3
+ # Just be aware that every worker needs to cache all classes and thus eat some
4
+ # of your RAM.
5
+ set :unicorn_workers, 8 unless exists?(:unicorn_workers)
6
+
7
+ # Workers timeout in the amount of seconds below, when the master kills it and
8
+ # forks another one.
9
+ set :unicorn_workers_timeout, 30 unless exists?(:unicorn_workers_timeout)
10
+
11
+ # Workers are started with this user/group
12
+ # By default we get the user/group set in capistrano.
13
+ set(:unicorn_user) { user } unless exists?(:unicorn_user)
14
+ set(:unicorn_group) { group } unless exists?(:unicorn_group)
15
+
16
+ # The wrapped bin to start unicorn
17
+ # This is necessary if you're using rvm
18
+ set :unicorn_bin, 'bundle exec unicorn' unless exists?(:unicorn_bin)
19
+ set :unicorn_socket, File.join(sockets_path,'unicorn.sock') unless exists?(:unicorn_socket)
20
+
21
+ # Defines where the unicorn pid will live.
22
+ set(:unicorn_pid) { File.join(pids_path, "unicorn.pid") } unless exists?(:unicorn_pid)
23
+
24
+ # Our unicorn template to be parsed by erb
25
+ # You may need to generate this file the first time with the generator
26
+ # included in the gem
27
+ set(:unicorn_local_config) { File.join(templates_path, "unicorn.rb.erb") }
28
+
29
+ # The remote location of unicorn's config file. Used by god to fire it up
30
+ set(:unicorn_remote_config) { "#{shared_path}/config/unicorn.rb" }
31
+
32
+ def unicorn_start_cmd
33
+ "cd #{current_path} && #{unicorn_bin} -c #{unicorn_remote_config} -E #{rails_env} -D"
34
+ end
35
+
36
+ def unicorn_stop_cmd
37
+ "kill -QUIT `cat #{unicorn_pid}`"
38
+ end
39
+
40
+ def unicorn_restart_cmd
41
+ "kill -USR2 `cat #{unicorn_pid}`"
42
+ end
43
+
44
+ # Unicorn
45
+ #------------------------------------------------------------------------------
46
+ namespace :unicorn do
47
+ desc "|DarkRecipes| Starts unicorn directly"
48
+ task :start, :roles => :app do
49
+ run unicorn_start_cmd
50
+ end
51
+
52
+ desc "|DarkRecipes| Stops unicorn directly"
53
+ task :stop, :roles => :app do
54
+ run unicorn_stop_cmd
55
+ end
56
+
57
+ desc "||DarkRecipes|| Restarts unicorn directly"
58
+ task :restart, :roles => :app do
59
+ run unicorn_restart_cmd
60
+ end
61
+
62
+ desc <<-EOF
63
+ |DarkRecipes| Parses the configuration file through ERB to fetch our variables and \
64
+ uploads the result to #{unicorn_remote_config}, to be loaded by whoever is booting \
65
+ up the unicorn.
66
+ EOF
67
+ task :setup, :roles => :app , :except => { :no_release => true } do
68
+ # TODO: refactor this to a more generic setup task once we have more socket tasks.
69
+ commands = []
70
+ commands << "mkdir -p #{sockets_path}"
71
+ commands << "chown #{user}:#{group} #{sockets_path} -R"
72
+ commands << "chmod +rw #{sockets_path}"
73
+
74
+ run commands.join(" && ")
75
+ generate_config(unicorn_local_config,unicorn_remote_config)
76
+ end
77
+ end
78
+
79
+ after 'deploy:setup' do
80
+ unicorn.setup if Capistrano::CLI.ui.agree("Create unicorn configuration file? [Yn]")
81
+ end if is_using_unicorn
82
+ end
@@ -0,0 +1,3 @@
1
+ module CapistranoRecipes
2
+ VERSION = "0.8.0"
3
+ end
metadata CHANGED
@@ -1,29 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ hash: 63
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Phil Misiowiec
14
+ - Leonardo Bighetti
8
15
  autorequire:
9
16
  bindir: bin
10
17
  cert_chain: []
11
18
 
12
- date: 2009-10-01 00:00:00 -07:00
19
+ date: 2011-03-26 00:00:00 -07:00
13
20
  default_executable:
14
21
  dependencies:
15
22
  - !ruby/object:Gem::Dependency
16
23
  name: capistrano
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
20
27
  requirements:
21
28
  - - ">="
22
29
  - !ruby/object:Gem::Version
30
+ hash: 9
31
+ segments:
32
+ - 2
33
+ - 5
34
+ - 9
23
35
  version: 2.5.9
24
- version:
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: capistrano-ext
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 29
47
+ segments:
48
+ - 1
49
+ - 2
50
+ - 1
51
+ version: 1.2.1
52
+ type: :runtime
53
+ version_requirements: *id002
25
54
  description: Extend the Capistrano gem with these useful recipes
26
- email: phil@webficient.com
55
+ email:
56
+ - github@webficient.com
27
57
  executables: []
28
58
 
29
59
  extensions: []
@@ -33,43 +63,67 @@ extra_rdoc_files:
33
63
  - README.rdoc
34
64
  files:
35
65
  - .gitignore
66
+ - Gemfile
36
67
  - LICENSE
37
68
  - README.rdoc
38
69
  - Rakefile
39
- - VERSION.yml
40
70
  - capistrano-recipes.gemspec
71
+ - doc/god/god
72
+ - doc/god/god.conf
73
+ - doc/god/god.init
74
+ - generators/app.god.erb
75
+ - generators/nginx.conf.erb
76
+ - generators/unicorn.rb.erb
41
77
  - lib/capistrano_recipes.rb
42
78
  - lib/helpers.rb
79
+ - lib/recipes/application.rb
80
+ - lib/recipes/bluepill.rb
81
+ - lib/recipes/bundler.rb
43
82
  - lib/recipes/db.rb
44
83
  - lib/recipes/deploy.rb
84
+ - lib/recipes/god.rb
85
+ - lib/recipes/hooks.rb
45
86
  - lib/recipes/log.rb
87
+ - lib/recipes/nginx.rb
46
88
  - lib/recipes/passenger.rb
47
- - lib/recipes/symlink.rb
89
+ - lib/recipes/resque.rb
90
+ - lib/recipes/sphinx.rb
91
+ - lib/recipes/symlinks.rb
92
+ - lib/recipes/unicorn.rb
93
+ - lib/version.rb
48
94
  has_rdoc: true
49
- homepage: http://github.com/webficient/capistrano-recipes
95
+ homepage: ""
50
96
  licenses: []
51
97
 
52
98
  post_install_message:
53
- rdoc_options:
54
- - --charset=UTF-8
99
+ rdoc_options: []
100
+
55
101
  require_paths:
56
102
  - lib
57
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
58
105
  requirements:
59
106
  - - ">="
60
107
  - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
61
111
  version: "0"
62
- version:
63
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
64
114
  requirements:
65
115
  - - ">="
66
116
  - !ruby/object:Gem::Version
67
- version: "0"
68
- version:
117
+ hash: 23
118
+ segments:
119
+ - 1
120
+ - 3
121
+ - 6
122
+ version: 1.3.6
69
123
  requirements: []
70
124
 
71
- rubyforge_project:
72
- rubygems_version: 1.3.5
125
+ rubyforge_project: capistrano-recipes
126
+ rubygems_version: 1.6.2
73
127
  signing_key:
74
128
  specification_version: 3
75
129
  summary: Capistrano recipes