winton-cookbook 1.0.2 → 1.0.3

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/README.markdown CHANGED
@@ -24,17 +24,17 @@ Install
24
24
 
25
25
  (Goto **Set up a PHP app** if deploying a PHP project)
26
26
 
27
- ### Capify your project
27
+ ### Install gem
28
28
 
29
- capify .
29
+ gem install winton-cookbook
30
30
 
31
- ### Add cookbook as a Git submodule
31
+ ### Capify your project
32
32
 
33
- git submodule add git://github.com:winton/cookbook.git config/cookbook
33
+ capify .
34
34
 
35
35
  ### Copy deploy.rb
36
36
 
37
- Copy **config/cookbook/deploy.rb.example** to **config/deploy.rb**
37
+ Copy **[deploy.rb.example](http://github.com/winton/cookbook/tree/master%2Fdeploy.rb.example?raw=true)** to **config/deploy.rb**
38
38
 
39
39
  Edit **config/deploy.rb** to your liking. Run `cap -T` to check out your new tasks.
40
40
 
data/lib/cookbook.rb ADDED
@@ -0,0 +1,66 @@
1
+ # Require helpers and recipes
2
+
3
+ require File.expand_path('cookbook_helpers.rb', File.dirname(__FILE__))
4
+ Dir[ File.expand_path('recipes/*.rb', File.dirname(__FILE__))].each do |f|
5
+ require f
6
+ end
7
+
8
+
9
+ Capistrano::Configuration.instance(:must_exist).load do
10
+
11
+ ROOT = self
12
+
13
+ # See cookbook hash in config/deploy.rb
14
+
15
+ cookbook[:port] = cookbook[:ssh_port] # Port is too ambiguous for me
16
+ cookbook.each do |key, value| # Merge cookbook with capistrano
17
+ value.respond_to?(:keys) ? value.each { |k, v| set "#{key}_#{k}".intern, v } : set(key, value)
18
+ end
19
+
20
+ # Default values
21
+
22
+ set :port, fetch(:port, 22)
23
+ set :user, fetch(:user, 'deploy')
24
+ set :stage, fetch(:stage, :production)
25
+ set :db_user, fetch(:db_user, 'app')
26
+ set :db_pass, fetch(:db_pass, '')
27
+ set :platform, fetch(:platform, :rails) # Or :php
28
+ set :ssl_cert, fetch(:ssl_cert, false)
29
+ set :use_sudo, fetch(:use_sudo, false)
30
+ set :auth_user, fetch(:auth_user, false)
31
+ set :nginx_dir, fetch(:nginx_dir, '/usr/local/nginx/conf')
32
+ set :mysql_dir, fetch(:mysql_dir, '/etc/mysql')
33
+ set :ultrasphinx, fetch(:ultrasphinx, false)
34
+ set :attachment_fu, fetch(:attachment_fu, false)
35
+ set :asset_packager, fetch(:asset_packager, false)
36
+ set :mongrel_etc_dir, fetch(:mongrel_etc_dir, '/usr/local/etc/mongrel_cluster')
37
+ set :mongrel_gem_dir, fetch(:mongrel_gem_dir, '/usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5')
38
+ set :staging_mongrels, fetch(:staging_mongrels, 1)
39
+ set :production_mongrels, fetch(:production_mongrels, 2)
40
+
41
+ # Git by default
42
+
43
+ set :scm, :git
44
+ set :deploy_via, :remote_cache
45
+ set :repository_cache, 'git_cache'
46
+
47
+ ssh_options[:paranoid] = false
48
+
49
+ # Events
50
+
51
+ on :before, 'setup_stage', :except => [ :staging, :testing ] # Executed before every task
52
+ if platform == :rails
53
+ after 'deploy:update_code', 'rails:setup_git' # Initialize submodules
54
+ after 'deploy:update_code', 'rails:config:to_app' # Copy shared config to app
55
+ if asset_packager
56
+ after 'deploy:update_code', 'rails:config:asset_packager' # Configure attachment_fu
57
+ end
58
+ if attachment_fu
59
+ after 'deploy:update_code', 'rails:config:attachment_fu' # Configure attachment_fu
60
+ end
61
+ if ultrasphinx
62
+ after 'deploy:update_code', 'rails:config:ultrasphinx' # Configure ultrasphinx
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,119 @@
1
+ require 'erb'
2
+
3
+
4
+ # Install
5
+
6
+ def gem_install(name, options='')
7
+ sudo_puts "gem install #{name} #{options}"
8
+ end
9
+
10
+ def unpack_source(source)
11
+ url = eval "sources_#{source}" # see cookbook[:sources]
12
+ name = File.basename url
13
+ src = "/home/#{user}/sources"
14
+ base = nil
15
+ [ 'tar.gz', 'tgz' ].each do |ext|
16
+ base = name[0..((ext.length + 2) * -1)] if name.include?(ext)
17
+ end
18
+ run_each [
19
+ "mkdir -p #{src}",
20
+ "cd #{src} && wget --quiet #{url}",
21
+ "tar -xzvf #{src}/#{name} -C #{src}"
22
+ ]
23
+ "#{src}/#{base}"
24
+ end
25
+
26
+ def install_source(source)
27
+ path = unpack_source source
28
+ yield path
29
+ sudo "rm -Rf #{path}"
30
+ end
31
+
32
+
33
+ # Files
34
+
35
+ def get_ssh_keys
36
+ keys = Dir[File.expand_path('~/.ssh/*.pub')].collect do |f|
37
+ File.open(f).collect { |line| line.strip.empty? ? nil : line.strip }.compact
38
+ end
39
+ keys.flatten.join("\n").strip
40
+ end
41
+
42
+ def upload_from_erb(destination, bind=nil, options={})
43
+ # options[ :chown => owner of file (default: deploy user),
44
+ # :chmod => 0644 etc
45
+ # :folder => 'postfix' etc,
46
+ # :name => name of template if differs from destination ]
47
+ if destination.respond_to?(:uniq)
48
+ destination.each { |d| upload_from_erb d, bind, options }
49
+ else
50
+ template = File.basename destination
51
+ template = template[1..-1] if template[0..0] == '.'
52
+ folder = options[:folder] ? options[:folder] + '/' : ''
53
+ template = File.expand_path("templates/#{folder}#{options[:name]||template}.erb", File.dirname(__FILE__))
54
+ template = File.read template
55
+ sudo "touch #{destination}"
56
+ sudo "chown #{user} #{destination}"
57
+ put ERB.new(template).result(bind || binding), destination
58
+ sudo("chown #{options[:chown]} #{destination}") if options[:chown]
59
+ sudo("chmod #{options[:chmod]} #{destination}") if options[:chmod]
60
+ end
61
+ end
62
+
63
+
64
+ # MySQL
65
+
66
+ def mysql_run(sql)
67
+ if sql.respond_to?(:uniq)
68
+ sql.each { |s| mysql_run s }
69
+ else
70
+ run "echo \"#{sql}\" | #{mysql_call}"
71
+ end
72
+ end
73
+
74
+ def mysql_call
75
+ @mysql_root_password = @mysql_root_password || ask("Password for mysql root:")
76
+ "mysql -u root --password=#{@mysql_root_password}"
77
+ end
78
+
79
+
80
+ # Questions
81
+
82
+ def ask(question, default='')
83
+ question = "\n" + question.join("\n") if question.respond_to?(:uniq)
84
+ answer = Capistrano::CLI.ui.ask(question).strip
85
+ answer.empty? ? default : answer
86
+ end
87
+
88
+ def yes(question)
89
+ question = "\n" + question.join("\n") if question.respond_to?(:uniq)
90
+ question += ' (y/n)'
91
+ ask(question).downcase.include? 'y'
92
+ end
93
+
94
+
95
+ # Runners
96
+
97
+ def run_each(*args, &block)
98
+ cmd = args[0]
99
+ sudo = args[1]
100
+ if cmd.respond_to?(:uniq)
101
+ cmd.each { |c| run_each c, sudo, &block }
102
+ elsif sudo
103
+ sudo(cmd) { |ch, st, data| block.call(data) if block }
104
+ else
105
+ run(cmd) { |ch, st, data| block.call(data) if block }
106
+ end
107
+ end
108
+
109
+ def sudo_each(cmds, &block)
110
+ run_each cmds, true, &block
111
+ end
112
+
113
+ def run_puts(cmds, &block)
114
+ run_each(cmds) { |data| puts data }
115
+ end
116
+
117
+ def sudo_puts(cmds, &block)
118
+ sudo_each(cmds) { |data| puts data }
119
+ end
@@ -0,0 +1,200 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :debian do
4
+ desc "Configure and install a fresh Debian server"
5
+ task :default do
6
+ if yes("Have you created the user defined in config/deploy.rb? (See vendor/plugins/cookbook/README)")
7
+ debian.aptitude.default
8
+ debian.config.default
9
+ debian.install.default
10
+ end
11
+ end
12
+
13
+ namespace :aptitude do
14
+ desc 'Run all tasks'
15
+ task :default do
16
+ aptitude.update
17
+ aptitude.upgrade
18
+ aptitude.essential
19
+ end
20
+
21
+ desc 'Aptitude update'
22
+ task :update do
23
+ sudo_puts 'aptitude update -q -y'
24
+ end
25
+
26
+ desc 'Aptitude upgrade'
27
+ task :upgrade do
28
+ sudo_puts 'aptitude upgrade -q -y'
29
+ end
30
+
31
+ desc 'Aptitude install build-essential'
32
+ task :essential do
33
+ sudo_puts 'aptitude install build-essential -q -y'
34
+ end
35
+ end
36
+
37
+ namespace :config do
38
+ desc 'Run all tasks'
39
+ task :default do
40
+ debian.config.sshd_config
41
+ debian.config.iptables
42
+ debian.config.locales
43
+ debian.config.bash_profile
44
+ end
45
+
46
+ desc "Uploads the bash_profile file in config/cookbook"
47
+ task :bash_profile do
48
+ question = [
49
+ "This task uploads the bash_profile file in config/cookbook.",
50
+ "OK?"
51
+ ]
52
+ if yes(question)
53
+ usr = ask "Update bash_profile for which user? (default: #{user})", user
54
+ upload_from_erb "/home/#{usr}/.bash_profile", binding, :chown => usr, :folder => 'debian'
55
+ end
56
+ end
57
+
58
+ desc "Updates server iptables from the file in config/cookbook"
59
+ task :iptables do
60
+ question = [
61
+ "This task updates your server's iptables with the file in config/cookbook.",
62
+ "OK?"
63
+ ]
64
+ if yes(question)
65
+ upload_from_erb '/etc/iptables.rules', binding, :folder => 'debian'
66
+ sudo_each [
67
+ 'iptables-restore < /etc/iptables.rules',
68
+ 'rm /etc/iptables.rules'
69
+ ]
70
+ end
71
+ end
72
+
73
+ desc "Updates server locales from the file in config/cookbook"
74
+ task :locales do
75
+ question = [
76
+ "This task updates the server's locales from the file in config/cookbook.",
77
+ "OK?"
78
+ ]
79
+ if yes(question)
80
+ upload_from_erb '/etc/locale.gen', binding, :chown => 'root', :chmod => '0644', :folder => 'debian'
81
+ sudo '/usr/sbin/locale-gen'
82
+ end
83
+ end
84
+
85
+ desc "Updates sshd_config from the file in config/cookbook"
86
+ task :sshd_config do
87
+ question = [
88
+ "This task updates your server's sshd_config with the file in config/cookbook.",
89
+ "This task assumes your server's current ssh port is 22.",
90
+ "This task will change your ssh port to the one in config/deploy.rb.",
91
+ "OK?"
92
+ ]
93
+ if yes(question)
94
+ set :port, 22 # Comment out for testing
95
+ upload_from_erb '/etc/ssh/sshd_config', binding, :chown => 'root', :chmod => '0644', :folder => 'debian'
96
+ sudo '/etc/init.d/ssh reload'
97
+ set :port, ssh_port
98
+ end
99
+ end
100
+ end
101
+
102
+ namespace :install do
103
+ desc 'Run all tasks'
104
+ task :default do
105
+ debian.install.git
106
+ debian.install.lighttpd
107
+ debian.install.mysql
108
+ debian.install.nginx
109
+ debian.install.php
110
+ debian.install.ruby
111
+ debian.install.rubygems
112
+ debian.install.sphinx
113
+ debian.install.monit
114
+ end
115
+
116
+ desc "Install Git"
117
+ task :git, :roles => :app do
118
+ install_source(:git) do |path|
119
+ sudo_puts [
120
+ "aptitude install tcl8.4 tk8.4 gettext -q -y",
121
+ "cd #{path} && ./configure && make && sudo make install"
122
+ ]
123
+ end
124
+ end
125
+
126
+ desc "Install Lighttpd" # Lighttpd install is purely for spawn-fcgi
127
+ task :lighttpd, :roles => :app do
128
+ sudo_puts 'aptitude install libpcre3-dev libbz2-dev -q -y'
129
+ install_source(:lighttpd) do |path|
130
+ sudo_puts "cd #{path} && ./configure && make && sudo make install"
131
+ end
132
+ end
133
+
134
+ desc 'Install Monit'
135
+ task :monit, :roles => :db do
136
+ sudo_puts 'aptitude install monit -q -y'
137
+ monit.config.default
138
+ end
139
+
140
+ desc 'Install MySQL'
141
+ task :mysql, :roles => :db do
142
+ sudo_puts 'aptitude install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby -q -y'
143
+ ROOT.mysql.config
144
+ puts [
145
+ '',
146
+ "It is highly recommended you run mysql_secure_installation manually.",
147
+ "See http://dev.mysql.com/doc/refman/5.1/en/mysql-secure-installation.html",
148
+ ''
149
+ ].join("\n")
150
+ ROOT.mysql.create.user
151
+ end
152
+
153
+ desc 'Install Nginx'
154
+ task :nginx, :roles => :app do
155
+ # apache2-utils for htpasswd, rest for nginx build
156
+ sudo_puts 'aptitude install apache2-utils libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev -q -y'
157
+ install_source(:nginx) do |path|
158
+ sudo_puts "cd #{path} && ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module && make && sudo make install"
159
+ end
160
+ upload_from_erb '/etc/init.d/nginx', binding, :chown => 'root', :chmod => '+x', :folder => 'nginx'
161
+ sudo '/usr/sbin/update-rc.d -f nginx defaults'
162
+ ROOT.nginx.config.run_once.default
163
+ end
164
+
165
+ desc "Install PHP"
166
+ task :php, :roles => :app do
167
+ sudo_puts 'aptitude install php5-cli php5-cgi php5-mysql php5-xcache -q -y'
168
+ upload_from_erb [
169
+ '/usr/local/bin/php-fastcgi',
170
+ '/etc/init.d/init-fastcgi'
171
+ ], binding, :chown => 'root', :chmod => '+x', :folder => 'php'
172
+ sudo '/usr/sbin/update-rc.d -f init-fastcgi defaults'
173
+ end
174
+
175
+ desc 'Install Ruby'
176
+ task :ruby, :roles => :app do
177
+ install_source(:ruby) do |path|
178
+ sudo_puts "cd #{path} && ./configure && make && sudo make install"
179
+ end
180
+ end
181
+
182
+ desc 'Install RubyGems'
183
+ task :rubygems, :roles => :app do
184
+ install_source(:rubygems) do |path|
185
+ sudo_puts "cd #{path} && ruby setup.rb"
186
+ end
187
+ gems.update
188
+ gems.install
189
+ end
190
+
191
+ desc 'Install Sphinx'
192
+ task :sphinx, :roles => :app do
193
+ install_source(:sphinx) do |path|
194
+ sudo_puts "cd #{path} && ./configure && make && sudo make install"
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ end
@@ -0,0 +1,50 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :deploy do
4
+ desc "Restart mongrel cluster"
5
+ task :restart, :roles => :app, :except => { :no_release => true } do
6
+ mongrel.restart if platform == :rails
7
+ end
8
+
9
+ desc "Start mongrel cluster"
10
+ task :start, :roles => :app do
11
+ mongrel.start if platform == :rails
12
+ end
13
+
14
+ desc "Stop mongrel cluster"
15
+ task :stop, :roles => :app do
16
+ mongrel.stop if platform == :rails
17
+ end
18
+
19
+ desc "Deploy a fresh app"
20
+ task :create, :roles => :app do
21
+ mysql.create.db
22
+ sudo_each [
23
+ "mkdir -p #{base_dir}",
24
+ "chown -R #{user}:#{user} #{base_dir}"
25
+ ]
26
+ deploy.setup
27
+ if platform == :rails
28
+ mongrel.config.default
29
+ nginx.config.default
30
+ rails.config.default
31
+ deploy.cold
32
+ elsif platform == :php
33
+ php.config.default
34
+ deploy.default
35
+ end
36
+ nginx.restart
37
+ end
38
+
39
+ desc "Stop servers and destroy all files"
40
+ task :destroy, :roles => :app do
41
+ deploy.stop
42
+ mongrel.config.destroy if platform == :rails
43
+ sudo "rm -Rf #{deploy_to}"
44
+ nginx.config.destroy
45
+ nginx.restart
46
+ mysql.destroy.db
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,77 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :gems do
4
+ desc "List gems on remote server"
5
+ task :list, :roles => :app do
6
+ run_puts "gem list"
7
+ end
8
+
9
+ desc "Update gems on remote server"
10
+ task :update, :roles => :app do
11
+ sudo_each [
12
+ "gem update --system",
13
+ "gem update"
14
+ ]
15
+ end
16
+
17
+ namespace :install do
18
+ desc 'Install all standard gems'
19
+ task :default, :roles => :app do
20
+ gems.install.haml
21
+ gems.install.hpricot
22
+ gems.install.mime_types
23
+ gems.install.mongrel
24
+ gems.install.rails
25
+ end
26
+
27
+ desc 'Install Chronic'
28
+ task :chronic, :roles => :app do
29
+ gem_install :chronic
30
+ end
31
+
32
+ desc 'Install gchart'
33
+ task :gchart, :roles => :app do
34
+ gem_install :googlecharts
35
+ end
36
+
37
+ desc 'Install HAML'
38
+ task :haml, :roles => :app do
39
+ gem_install :haml, '--no-ri'
40
+ end
41
+
42
+ desc 'Install Hpricot'
43
+ task :hpricot, :roles => :app do
44
+ gem_install :hpricot
45
+ end
46
+
47
+ desc 'Install Json'
48
+ task :json, :roles => :app do
49
+ gem_install :json
50
+ end
51
+
52
+ desc 'Install Mime-types'
53
+ task :mime_types, :roles => :app do
54
+ gem_install 'mime-types'
55
+ end
56
+
57
+ desc 'Install Mongrel'
58
+ task :mongrel, :roles => :app do
59
+ gem_install :mongrel
60
+ gem_install :mongrel_cluster
61
+ mongrel.config.survive_reboot
62
+ end
63
+
64
+ desc 'Install Rails'
65
+ task :rails, :roles => :app do
66
+ gem_install :rails
67
+ end
68
+ end
69
+
70
+ desc "Uninstall a remote gem"
71
+ task :uninstall, :roles => :app do
72
+ gem_name = ask 'Enter the name of the gem to remove:'
73
+ sudo "gem uninstall #{gem_name}"
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,47 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :log do
4
+ namespace :tail do
5
+ desc "Tail all remote logs"
6
+ task :default, :roles => :app do
7
+ log.tail.nginx
8
+ log.tail.mongrel
9
+ log.tail.production
10
+ end
11
+
12
+ desc "Tail the remote Nginx log"
13
+ task :nginx, :roles => :app do
14
+ puts 'Nginx ' + '=' * 100
15
+ run_puts "tail -100 #{shared_path}/log/nginx.log"
16
+ end
17
+
18
+ desc "Tail the remote Mongrel log"
19
+ task :mongrel, :roles => :app do
20
+ (mongrel_port..(mongrel_port + production_mongrels - 1)).each do |port|
21
+ puts "Mongrel #{port} " + '=' * 100
22
+ run_puts "tail -100 #{shared_path}/log/mongrel.#{port}.log"
23
+ end
24
+ end
25
+
26
+ desc "Tail the remote Rails production log"
27
+ task :production, :roles => :app do
28
+ puts 'Production ' + '=' * 100
29
+ run_puts "tail -100 #{shared_path}/log/production.log"
30
+ end
31
+ end
32
+
33
+ desc "Add logrotate entry for this application"
34
+ task :rotate, :roles => :app do
35
+ upload_from_erb '/etc/rotate.conf', binding, :folder => 'log'
36
+ sudo_each [
37
+ 'cp -f /etc/logrotate.conf /etc/logrotate2.conf',
38
+ 'chmod 777 /etc/logrotate2.conf',
39
+ 'cat /etc/rotate.conf >> /etc/logrotate2.conf',
40
+ 'cp -f /etc/logrotate2.conf /etc/logrotate.conf',
41
+ 'rm -f /etc/logrotate2.conf',
42
+ 'rm -f /etc/rotate.conf'
43
+ ]
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,48 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :mongrel do
4
+ [ :stop, :start, :restart ].each do |t|
5
+ desc "#{t.to_s.capitalize} the mongrel appserver"
6
+ task t, :roles => :app do
7
+ run "mongrel_rails cluster::#{t.to_s} -C #{mongrel_etc_dir}/#{application}_#{stage}.yml"
8
+ end
9
+ end
10
+
11
+ namespace :config do
12
+ desc "Generate remote application config"
13
+ task :default, :roles => :app do
14
+ mongrel.config.cluster
15
+ mongrel.config.nginx
16
+ end
17
+
18
+ desc "Generate remote remote mongrel_cluster config"
19
+ task :cluster, :roles => :app do
20
+ sudo "mkdir -p #{mongrel_etc_dir}"
21
+ upload_from_erb "#{mongrel_etc_dir}/#{application}_#{stage}.yml", binding, :folder => 'mongrel', :name => 'mongrel.yml'
22
+ end
23
+
24
+ desc "Generate remote Nginx vhost"
25
+ task :nginx, :roles => :app do
26
+ upload_from_erb "#{nginx_dir}/vhosts/#{application}_#{stage}.conf", binding, :folder => 'mongrel', :name => 'nginx.vhost'
27
+ end
28
+
29
+ desc "Make our mongrel cluster restart-proof"
30
+ task :survive_reboot, :roles => :app do
31
+ sudo_each [
32
+ "cp -Rf #{mongrel_gem_dir}/resources/mongrel_cluster /etc/init.d/",
33
+ "chmod +x /etc/init.d/mongrel_cluster",
34
+ "/usr/sbin/update-rc.d -f mongrel_cluster defaults"
35
+ ]
36
+ end
37
+
38
+ desc "Destroy all files created by config:create"
39
+ task :destroy, :roles => :app do
40
+ sudo_each [
41
+ "rm -f #{mongrel_etc_dir}/#{application}_#{stage}.yml",
42
+ "rm -f #{nginx_dir}/vhosts/#{application}_#{stage}.conf"
43
+ ]
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,47 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :monit do
4
+ [ :stop, :start, :restart ].each do |t|
5
+ desc "#{t.to_s.capitalize} Monit"
6
+ task t, :roles => :app do
7
+ sudo "/etc/init.d/monit #{t.to_s}"
8
+ end
9
+ end
10
+
11
+ namespace :config do
12
+ desc "Generate remote Monit config files"
13
+ task :default, :roles => :app do
14
+ upload_from_erb [
15
+ '/etc/monit/monitrc',
16
+ '/etc/default/monit'
17
+ ], binding, :chown => 'root', :chmod => '0644', :folder => 'monit'
18
+ monit.config.nginx
19
+ end
20
+
21
+ desc "Add mongrel cluster to monitrc"
22
+ task :mongrel, :roles => :app do
23
+ upload_from_erb '/etc/monit/mongrel', binding, :folder => 'monit'
24
+ sudo_each [
25
+ 'cp -f /etc/monit/monitrc /etc/monit/monitrc2',
26
+ 'chmod 777 /etc/monit/monitrc2',
27
+ 'cat /etc/monit/mongrel >> /etc/monit/monitrc2',
28
+ 'cp -f /etc/monit/monitrc2 /etc/monit/monitrc',
29
+ 'rm -f /etc/monit/mongrel',
30
+ 'rm -f /etc/monit/monitrc2'
31
+ ]
32
+ end
33
+
34
+ desc "Generate remote Nginx vhost"
35
+ task :nginx, :roles => :app do
36
+ if monit_auth_user
37
+ sudo_each [
38
+ "mkdir -p #{nginx_dir}/htpasswd",
39
+ "htpasswd -bc #{nginx_dir}/htpasswd/monit #{monit_auth_user} #{monit_auth_pass}"
40
+ ]
41
+ end
42
+ upload_from_erb "#{nginx_dir}/vhosts/monit.conf", binding, :folder => 'monit', :name => 'nginx.vhost'
43
+ end
44
+ end
45
+ end
46
+
47
+ end