thin+god搭建rails服务器集群

安装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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值