Remove necessity to specify pid_file for process centric conditions
[god.git] / lib / god / behavior.rb
blob7c767ab83ffda07aaad703d0ebc73656d6eae038
1 module God
2   
3   class Behavior < Base
4     attr_accessor :watch
5     
6     # Generate a Behavior of the given kind. The proper class if found by camel casing the
7     # kind (which is given as an underscored symbol).
8     #   +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Behaviors::FooBar)
9     def self.generate(kind, watch)
10       sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
11       b = God::Behaviors.const_get(sym).new
12       b.watch = watch
13       b
14     rescue NameError
15       raise NoSuchBehaviorError.new("No Behavior found with the class name God::Behaviors::#{sym}")
16     end
17     
18     # Override this method in your Behaviors (optional)
19     #
20     # Called once after the Condition has been sent to the block and attributes have been
21     # set. Do any post-processing on attributes here
22     def prepare
23       
24     end
25     
26     # Override this method in your Behaviors (optional)
27     #
28     # Called once during evaluation of the config file. Return true if valid, false otherwise
29     #
30     # A convenience method 'complain' is available that will print out a message and return false,
31     # making it easy to report multiple validation errors:
32     #
33     #   def valid?
34     #     valid = true
35     #     valid &= complain("You must specify the 'pid_file' attribute for :memory_usage") if self.pid_file.nil?
36     #     valid &= complain("You must specify the 'above' attribute for :memory_usage") if self.above.nil?
37     #     valid
38     #   end
39     def valid?
40       true
41     end
42     
43     #######
44     
45     def before_start
46     end
47     
48     def after_start
49     end
50     
51     def before_restart
52     end
53     
54     def after_restart
55     end
56     
57     def before_stop
58     end
59     
60     def after_stop
61     end
62     
63     protected
64     
65     def complain(text)
66       Syslog.err(text)
67       puts text
68       false
69     end
70   end
71   
72 end