foreman_hooks 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "foreman_hooks"
3
3
 
4
- s.version = "0.3.0"
5
- s.date = "2013-04-06"
4
+ s.version = "0.3.1"
5
+ s.date = "2013-04-07"
6
6
 
7
7
  s.summary = "Run custom hook scripts on Foreman events"
8
8
  s.description = "Plugin engine for Foreman that enables running custom hook scripts on Foreman events"
@@ -1,3 +1,5 @@
1
+ require 'open3'
2
+
1
3
  module ForemanHooks::Util
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -35,7 +37,7 @@ module ForemanHooks::Util
35
37
  @hooks = discover_hooks
36
38
  @hooks.each do |klass,events|
37
39
  events.each do |event,hooks|
38
- logger.info "Finished registering #{hooks.size} hooks for #{Host::Base.to_s}##{event}"
40
+ logger.info "Finished registering #{hooks.size} hooks for #{klass.to_s}##{event}"
39
41
  hooks.sort!
40
42
  end
41
43
  end
@@ -75,13 +77,18 @@ module ForemanHooks::Util
75
77
  end
76
78
 
77
79
  def exec_hook_int(stdin_data, *args)
78
- output = nil
79
- IO.popen(args.push(:err=>[:child, :out]), mode='r+') do |io|
80
- io.write(stdin_data)
81
- io.close_write
82
- output = io.read
80
+ output, status = if Open3.respond_to? :capture2e
81
+ Open3.capture2e(*args.push(:stdin_data => stdin_data))
82
+ else # 1.8
83
+ Open3.popen3(*args) do |stdin,stdout,stderr|
84
+ stdin.write(stdin_data)
85
+ stdin.close
86
+ # we could still deadlock here, it'd ideally select() on stdout+err
87
+ output = stderr.read
88
+ end
89
+ [output, $?]
83
90
  end
84
91
  logger.debug "Hook output: #{output}" if output && !output.empty?
85
- $?
92
+ status
86
93
  end
87
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-06 00:00:00.000000000 Z
12
+ date: 2013-04-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Plugin engine for Foreman that enables running custom hook scripts on
15
15
  Foreman events