gpt4 book ai didi

ruby-on-rails - Ruby 守护进程和 bluepill 监控

转载 作者:太空宇宙 更新时间:2023-11-03 16:57:21 27 4
gpt4 key购买 nike

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

谁能告诉我如何更轻松地做到这一点,或者你能告诉我我做错了什么吗?

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

这是我的 .pill 文件中的代码

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 文件

#!/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 文件

#!/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

我得到的日志

[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

肯定有比这更简单的方法吗?

最佳答案

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

关于ruby-on-rails - Ruby 守护进程和 bluepill 监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6682091/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com