安装thin sudo gem install thin
安装god sudo gem install god
配置god
# configure variables list below
app_dir = "项目路径"
service = "项目名称"
num_servers = 5 // 开启服务器的个数
port = 9000 // 端口号
#user = "rocket_finance"
#group = "rocket_finance"
pid_path = "#{app_dir}/tmp/pids/thin.pid" pid存放的路径
(0...num_servers).each do |i|
number = port + i
God.watch do |w|
w.group = "thin-#{service}"
w.name = w.group + "-#{number}"
w.interval = 30.seconds
#w.uid = user
#w.gid = group
ext = File.extname(pid_path)
w.pid_file = pid_path.gsub(/#{ext}$/, ".#{number}#{ext}")
w.start = "thin start -c #{app_dir} -p #{number} -o #{number}"
w.start_grace = 10.seconds
w.stop = "thin stop -c #{app_dir} -P #{w.pid_file}"
w.stop_grace = 10.seconds
w.restart = "thin restart -c #{app_dir} -p #{number} -o #{number} -P #{w.pid_file}"
w.behavior(:clean_pid_file)
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false
#c.notify = 'developers'
end
end
w.restart_if do |restart|
restart.condition(:memory_usage) do |c|
c.above = 150.megabytes
c.times = [3,5] # 3 out of 5 intervals
#c.notify = 'developers'
end
restart.condition(:cpu_usage) do |c|
c.above = 50.percent
c.times = 5
#c.notify = 'developers'
end
end
w.lifecycle do |on|
on.condition(:flapping) do |c|
c.to_state = [:start, :restart]
c.times = 5
c.within = 5.minutes
c.transition = :unmonitored
c.retry_in = 10.minutes
c.retry_times = 5
c.retry_within = 2.hours
#c.notify = 'developers'
end
end
end
运行 god -c config/thin.god -D
OK
god status
thin-test-9000: up
thin-test-9001: up
thin-test-9002: up
thin-test-9003: up
thin-test-9004: up