首页 > 其他 > 详细

Debian rails Puma god 开机启动

时间:2014-05-09 00:51:42      阅读:560      评论:0      收藏:0      [点我收藏+]

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 开机启动

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!