Skip to content

Instantly share code, notes, and snippets.

@dstrelau
Created January 28, 2010 23:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dstrelau/289261 to your computer and use it in GitHub Desktop.
Save dstrelau/289261 to your computer and use it in GitHub Desktop.
Bluepill.define_process_condition(:running_time) do
def initialize(options = {})
@below = options[:below]
end
def run(pid)
started = `ps -p #{pid} -o command`.match(/since (\d+)/)[1].to_i
Time.now - Time.at(started)
rescue
0
end
def check(value)
value.seconds < @below
end
end
Bluepill.application('MyApp') do |app|
app.working_dir = "/var/rails"
app.process("resque-worker") do |p|
p.start_command = "/usr/bin/rake RAILS_ENV=staging QUEUES=critical,high,low resque:work"
p.stop_command = "kill {{PID}}"
p.daemonize = true
p.pid_file = "/var/rails/tmp/pids/resque.pid"
p.start_grace_time = 10.seconds
p.stop_grace_time = 5.seconds
p.restart_grace_time = 15.seconds
p.monitor_children do |c|
c.stop_command = "kill -USR1 {{PID}}"
c.checks :mem_usage, :every => 30.seconds, :below => 80.megabytes, :fires => :stop
c.checks :running_time, :every => 30.seconds, :below => 10.minutes, :fires => :stop
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment