首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ruby守护进程和bluepill监控

Ruby守护进程和bluepill监控
EN

Stack Overflow用户
提问于 2011-07-14 00:13:59
回答 1查看 1.4K关注 0票数 2

我正在尝试创建一个自定义守护进程,让它每隔60秒运行一次,并使用bluepill启动/停止和监控它。

有人能告诉我怎么做更容易吗?或者你能告诉我我做错了什么吗?

目前,bluepill正在启动守护进程,以便它运行,但似乎不知道它正在运行,因为持续尝试停止和启动它。

下面是我的.pill文件中的代码

代码语言:javascript
复制
app.process("get_dropboxes") do |process|

   process.working_dir = RAILS_ROOT
   process.pid_file = File.join(RAILS_ROOT, "tmp", "pids", "get_dropbox.pid")  
   process.start_command = "/usr/bin/env RAILS_ENV=#{RAILS_ENV} bundle exec lib/daemons/get_dropbox_ctl start"
   process.stop_command = "/usr/bin/env RAILS_ENV=#{RAILS_ENV} bundle exec lib/daemons/get_dropbox_ctl stop"

   process.start_grace_time = 10.seconds
   process.stop_grace_time = 10.seconds
   process.restart_grace_time = 10.seconds

   process.checks :cpu_usage, :every => 30.seconds, :below => 20, :times => [3,5]
   process.checks :mem_usage, :every => 30.seconds, :below => 350.megabytes, :times => [3,5]

 end

这是我的get_dropbox_ctl文件

代码语言:javascript
复制
#!/usr/bin/env ruby
require 'rubygems'
require "daemons"
require 'yaml'
require 'erb'

gem 'activesupport', '>=3.0.0'
require 'active_support'

# For some reason, ActiveSupport 3.0.0 doesn't load.
# Load needed extension directly for now.
require "active_support/core_ext/object"
require "active_support/core_ext/hash"

options = YAML.load(
  ERB.new(
    IO.read(
      File.dirname(__FILE__) + "/../../config/daemons.yml"
  )).result).with_indifferent_access

options[:dir_mode] = options[:dir_mode].to_sym

Daemons.run File.dirname(__FILE__) + "/get_dropbox.rb", options

这是我的get_dropbox.rb文件

代码语言:javascript
复制
#!/usr/bin/env ruby

# You might want to change this
ENV["RAILS_ENV"] ||= "production"

require 'net/pop'
require File.dirname(__FILE__) + "/../../config/application"
Rails.application.require_environment!

$running = true
Signal.trap("TERM") do 
  $running = false
end

while($running) do


  # do stuff .......

  sleep 60
end

我得到的日志

代码语言:javascript
复制
[2011-07-13T16:55:00.464202 #32257]  WARN -- : [domain.com:get_dropboxes] pid_file /var/www/domain.com/current/tmp/pids/get_dropbox.pid does not exist or cannot be read
W, [2011-07-13T16:55:00.464315 #32257]  WARN -- : [domain.com:get_dropboxes] pid_file /var/www/domain.com/current/tmp/pids/get_dropbox.pid does not exist or cannot be read
W, [2011-07-13T16:55:00.464505 #32257]  WARN -- : [domain.com:get_dropboxes] Executing start command: /usr/bin/env RAILS_ENV=production bundle exec lib/daemons/get_dropbox_ctl start
I, [2011-07-13T16:55:01.602210 #32257]  INFO -- : [domain.com:get_dropboxes] Going from down => starting

当然还有比这更简单的方法吗?

EN

回答 1

Stack Overflow用户

发布于 2011-07-15 21:08:31

我不确定这是否是您要找的,但据我所知,您可以跳过守护进程文件,使用bluepill。只要您指定一个pidfile,您就可以设置process.daemonize = true,它将为您创建一个守护进程。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6682091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档