-
Notifications
You must be signed in to change notification settings - Fork 8
/
mongrel_cluster.rb
66 lines (46 loc) · 2.13 KB
/
mongrel_cluster.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Create init script
namespace :mongrel_cluster do
desc <<-DESC
Create monit configuration for mongrel cluster.
mongrel_size: Number of mongrels.
set :mongrel_size, 3
mongrel_port: Starting port for mongrels. If there are 3 mongrels with port 9000, then instances
will be at 9000, 9001, and 9002
set :mongrel_port, 9000
mongrel_config_script: Config script to load with mongrel.
set :mongrel_config_script, "config/mongrel_handler.rb"
DESC
task :setup_monit do
# See http://www.igvita.com/2006/11/07/monit-makes-mongrel-play-nice/
# TODO: For depends on memcached setting
# See http://blog.labratz.net/articles/2007/5/1/monit-for-your-uptime
# Settings
fetch(:mongrel_size)
fetch(:mongrel_port)
fetch_or_default(:mongrel_config_script, nil)
processes = []
ports = (0...mongrel_size).collect { |i| mongrel_port + i }
ports.each do |port|
pid_path = "#{shared_path}/pids/mongrel.#{port}.pid"
default_options = [
[ "-d" ],
[ "-e", "production" ],
[ "-a", "127.0.0.1" ],
[ "-c", current_path ],
[ "--user", user ],
[ "--group", user ],
[ "-p", port ],
[ "-P", pid_path ],
[ "-l", "log/mongrel.#{port}.log" ]
]
default_options << [ "-S", mongrel_config_script ] if mongrel_config_script
start_options = default_options.collect { |a| a.join(" ") }.join(" ")
#start_options = "-d -e production -a 127.0.0.1 -c #{current_path} --user #{user} --group #{user} -p #{port} -P #{pid_path} -l log/mongrel.#{port}.log"
stop_options = "-p #{port} -P #{pid_path}"
processes << { :port => port, :start_options => start_options, :stop_options => stop_options, :name => "/usr/bin/mongrel_rails", :pid_path => pid_path }
end
set :processes, processes
put template.load("mongrel/mongrel_cluster.monitrc.erb"), "/tmp/mongrel_cluster_#{application}.monitrc"
sudo "install -o root /tmp/mongrel_cluster_#{application}.monitrc /etc/monit/mongrel_cluster_#{application}.monitrc"
end
end