ra-capistrano-recipes 0.7.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
+
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :log do
3
+ desc "|DarkRecipes| Tail all application log files"
4
+ task :tail, :roles => :app do
5
+ run "tail -f #{shared_path}/log/*.log" do |channel, stream, data|
6
+ puts "#{channel[:host]}: #{data}"
7
+ break if stream == :err
8
+ end
9
+ end
10
+
11
+ desc <<-DESC
12
+ |DarkRecipes| Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
13
+ DESC
14
+ task :rotate, :roles => :app do
15
+ rotate_script = %Q{#{shared_path}/log/#{environment}.log {
16
+ daily
17
+ rotate #{ENV['days'] || 7}
18
+ size #{ENV['size'] || "5M"}
19
+ compress
20
+ create 640 #{user} #{ENV['group'] || user}
21
+ missingok
22
+ }}
23
+ put rotate_script, "#{shared_path}/logrotate_script"
24
+ "#{sudo} cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}"
25
+ run "rm #{shared_path}/logrotate_script"
26
+ end
27
+ end
28
+ end
@@ -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
+
@@ -0,0 +1,18 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :passenger do
3
+ desc "|DarkRecipes| Restart Rails app running under Phusion Passenger by touching restart.txt"
4
+ task :bounce, :roles => :app do
5
+ run "#{sudo} touch #{current_path}/tmp/restart.txt"
6
+ end
7
+
8
+ desc "|DarkRecipes| Inspect Phusion Passenger's memory usage."
9
+ task :memory, :roles => :app do
10
+ run "sudo passenger-memory-stats"
11
+ end
12
+
13
+ desc "|DarkRecipes| Inspect Phusion Passenger's internal status."
14
+ task :status, :roles => :app do
15
+ run "sudo passenger-status"
16
+ end
17
+ end
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,39 @@
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
+ after "deploy:migrate" do
37
+ sphinx.rebuild
38
+ end unless is_app_monitored?
39
+ end
@@ -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
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ra-capistrano-recipes
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
+ platform: ruby
12
+ authors:
13
+ - Phil Misiowiec
14
+ - Leonardo Bighetti
15
+ - "Rog\xC3\xA9rio Augusto"
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-02-10 00:00:00 -02:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: capistrano
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 9
32
+ segments:
33
+ - 2
34
+ - 5
35
+ - 9
36
+ version: 2.5.9
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: capistrano-ext
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 29
48
+ segments:
49
+ - 1
50
+ - 2
51
+ - 1
52
+ version: 1.2.1
53
+ type: :runtime
54
+ version_requirements: *id002
55
+ description: Extend the Capistrano gem with these useful recipes
56
+ email: rogerio@depoiseuleio.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - LICENSE
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION.yml
69
+ - dark-capistrano-recipes.gemspec
70
+ - doc/god/god
71
+ - doc/god/god.conf
72
+ - doc/god/god.init
73
+ - generators/app.god.erb
74
+ - generators/nginx.conf.erb
75
+ - generators/unicorn.rb.erb
76
+ - lib/capistrano_recipes.rb
77
+ - lib/helpers.rb
78
+ - lib/recipes/application.rb
79
+ - lib/recipes/bluepill.rb
80
+ - lib/recipes/bundler.rb
81
+ - lib/recipes/db.rb
82
+ - lib/recipes/deploy.rb
83
+ - lib/recipes/god.rb
84
+ - lib/recipes/hooks.rb
85
+ - lib/recipes/log.rb
86
+ - lib/recipes/nginx.rb
87
+ - lib/recipes/passenger.rb
88
+ - lib/recipes/resque.rb
89
+ - lib/recipes/sphinx.rb
90
+ - lib/recipes/symlinks.rb
91
+ - lib/recipes/unicorn.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/rogerio-augusto/capistrano-recipes
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.5.0
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Darkside's Capistrano recipes
126
+ test_files: []
127
+