From bf0b032b799f25a9d871e235435e48b973e8aea5 Mon Sep 17 00:00:00 2001 From: Gabe Date: Wed, 14 May 2008 16:02:52 -0400 Subject: [PATCH] task arg dsl patch --- lib/capitate/cap_ext/namespace.rb | 34 +++++++++++++++++++++ lib/capitate/cap_ext/task_definition.rb | 22 +++++++++++++ lib/templates/merb/merb-no-http.monitrc.erb | 13 ++++++++ 3 files changed, 69 insertions(+) create mode 100644 lib/capitate/cap_ext/namespace.rb create mode 100644 lib/capitate/cap_ext/task_definition.rb create mode 100644 lib/templates/merb/merb-no-http.monitrc.erb diff --git a/lib/capitate/cap_ext/namespace.rb b/lib/capitate/cap_ext/namespace.rb new file mode 100644 index 0000000..effe7a6 --- /dev/null +++ b/lib/capitate/cap_ext/namespace.rb @@ -0,0 +1,34 @@ +module Capitate + + module CapExt + + module Namespace + + def self.included(base) #:nodoc: + unless base.method_defined?(:task_without_capitate) + base.send :alias_method, :task_without_capitate, :task + base.send :alias_method, :task, :task_with_capitate + end + end + + def task_arg(name, desc, options = {}) + @next_task_arguments ||= [] + @next_task_arguments << options.merge({ :name => name, :desc => desc }) + end + + def task_with_capitate(name, options={}, &block) + task_without_capitate(name, options) do + find_task(name).setup_defaults + block.call + end + task_def = find_task(name) + task_def.arguments = @next_task_arguments + @next_task_arguments = nil + task_def + end + + end + + end + +end \ No newline at end of file diff --git a/lib/capitate/cap_ext/task_definition.rb b/lib/capitate/cap_ext/task_definition.rb new file mode 100644 index 0000000..19be1fd --- /dev/null +++ b/lib/capitate/cap_ext/task_definition.rb @@ -0,0 +1,22 @@ +module Capitate + + module CapExt + + module TaskDefinition + + attr_accessor :arguments + + def setup_defaults + return if arguments.blank? + + arguments.each do |arg| + namespace.fetch_or_default(arg[:name], arg[:default]) if arg.has_key?(:default) + namespace.fetch_or_set(arg[:name], arg[:set]) if arg.has_key?(:set) + end + end + + end + + end + +end \ No newline at end of file diff --git a/lib/templates/merb/merb-no-http.monitrc.erb b/lib/templates/merb/merb-no-http.monitrc.erb new file mode 100644 index 0000000..2b246bf --- /dev/null +++ b/lib/templates/merb/merb-no-http.monitrc.erb @@ -0,0 +1,13 @@ +<% processes.each do |process| %> + +check process <%= merb_application %>_<%= process[:port] %> with pidfile <%= process[:pid_path] %> + group <%= merb_application %> + start program = "<%= process[:start] %>" + stop program = "<%= process[:stop] %>" + if totalmem > 100 Mb then restart + if cpu is greater than 60% for 2 cycles then alert + if cpu > 80% for 5 cycles then restart + if loadavg(5min) greater than 10 for 8 cycles then restart + if 3 restarts within 5 cycles then timeout + +<% end %> \ No newline at end of file