@@ -19,18 +19,45 @@ def update(context, name, should)
1919
2020 def run ( action , ens , args = { } )
2121 args . delete ( :ensure )
22- parse_result ( Puppet ::Util ::Execution . execute ( make_cmd ( action , args ) , :failonfail => false , :custom_environment => environment ) , ens )
22+ parse_result ( Puppet ::Util ::Execution . execute ( make_cmd ( action , args ) , :failonfail => true , :custom_environment => environment ) , ens )
23+ end
24+
25+ def config_file
26+ paths = if Process . uid == 0
27+ [
28+ "/etc/choria/server.conf" ,
29+ "/usr/local/etc/choria/server.conf" ,
30+ ]
31+ else
32+ [
33+ "/etc/choria/client.conf" ,
34+ "/usr/local/etc/choria/client.conf" ,
35+ ]
36+ end
37+
38+ paths . each do |p |
39+ return p if File . exist? ( p )
40+ end
41+
42+ raise ( "cannot find configuration path" )
2343 end
2444
2545 def make_cmd ( action , args = { } )
2646 choria = Puppet ::Util . which ( "choria" )
2747 raise ( "cannot find choria executable" ) if choria == ""
2848
29- cmd = [ choria , "gov" , "api" , "--%s" % action ]
30- args . each { |k , v |
31- cmd << "--%s" % k
32- cmd << v unless v . is_a? ( TrueClass )
33- }
49+ cmd = [ choria , "governor" , "api" , "--%s" % action , "--config=%s" % config_file ]
50+
51+ args . each do |k , v |
52+ k = k . to_s . gsub ( "_" , "-" )
53+ if v . is_a? ( TrueClass )
54+ cmd << "--%s" % k
55+ elsif v . is_a? ( FalseClass )
56+ cmd << "--no-%s" % k
57+ else
58+ cmd << "--%s=%s" % [ k , v ]
59+ end
60+ end
3461
3562 cmd . join ( " " )
3663 end
0 commit comments