码迷,mamicode.com
首页 > 其他好文 > 详细

Debian rails Puma god 开机启动

时间:2014-05-09 00:52:01      阅读:1277      评论:0      收藏:0      [点我收藏+]

标签:local   puma   linux   rails   god   

1、安装 god

gem install god

2、设置环境变量 以及开机启动的rc.local 文件 ,其内容如下

PATH=$PATH:/zhiyisoft/bin god -c /etc/god/god.god

备注: 请将 ruby bin目录下的所有文件链接到 /zhiyisoft/bin 下面,否则将无法运行

如果是  rvm ,请执行下方命令
 1、 rvm wrapper 2.0.0@rails3 boot up god
 2、 /usr/local/rvm/bin/bootup_god  或者 $HOME/.rvm/bin/bootup_god 替换rc.local

3、创建 /etc/god/god.god文件

rails_env = ENV[‘RAILS_ENV‘] || ‘development‘
rails_root = ENV[‘RAILS_ROOT‘] || "/zhiyisoft/app/phonebook"
project_name = "phonebook"

# 以上部分为配置,请根据情况修改

God.watch do |w|
w.name = "#{project_name}"
 w.interval = 30.seconds # default

 w.start = "cd #{rails_root} && bundle exec puma --config #{rails_root}/config/puma.conf -e #{rails_env} -d; echo $?;"

 w.stop = "kill -TERM `cat #{rails_root}/tmp/puma.pid`"

 w.restart = "kill -USR2 `cat #{rails_root}/tmp/puma.pid`"

 w.start_grace = 10.seconds
 w.restart_grace = 10.seconds
 w.pid_file = "#{rails_root}/tmp/puma.pid"

 w.uid = "root"
 w.gid = "root"

 w.behavior(:clean_pid_file)

 w.start_if do |start|
   start.condition(:process_running) do |c|
     c.interval = 5.seconds
     c.running = false
   end
 end

 w.restart_if do |restart|
   restart.condition(:memory_usage) do |c|
     c.above = 300.megabytes
     c.times = [3, 5] # 3 out of 5 intervals
   end

   restart.condition(:cpu_usage) do |c|
     c.above = 50.percent
     c.times = 5
   end
 end
 # lifecycle
 w.lifecycle do |on|
   on.condition(:flapping) do |c|
     c.to_state = [:start, :restart]
     c.times = 5
     c.within = 5.minute
     c.transition = :unmonitored
     c.retry_in = 10.minutes
     c.retry_times = 5
     c.retry_within = 2.hours
   end
 end
end

God.watch do |w|
 w.dir = "#{rails_root}"
w.name = "#{project_name}_clear"
 w.interval = 60.seconds
 w.env = {"RAILS_ENV"=>rails_env}

 w.uid = ‘root‘
 w.gid = ‘root‘

 w.start = "bundle exec rake daemon:clear_queue"
 w.keepalive
end

4、项目里面创建 config/puma.conf 其内容如下

rails_env = ENV[‘RAILS_ENV‘] || ‘development‘

threads 4,16

#bind  "unix:///tmp/puma.sock"
bind "tcp://0.0.0.0:9090"
pidfile "/tmp/pid"
state_path "/tmp/state"

activate_control_app

备注 :此文件需要按需调整

本文出自 “天边一抹云” 博客,请务必保留此出处http://tianbymy.blog.51cto.com/1928962/1408478

Debian rails Puma god 开机启动,布布扣,bubuko.com

Debian rails Puma god 开机启动

标签:local   puma   linux   rails   god   

原文地址:http://tianbymy.blog.51cto.com/1928962/1408478

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!