hookit 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5c3f231b006d73bcced104ed279d8badd17ae9d
4
- data.tar.gz: 4f31cb12066a30328060d4d967c8d17ffafbb774
3
+ metadata.gz: be8d878c31cfb5843f20a99980f9f2fa7491c6b6
4
+ data.tar.gz: ce6373de03a2d8276e0b2409b080752d769dd08d
5
5
  SHA512:
6
- metadata.gz: b57bc696382a86fd72e81acb87875787c0fbe9c80b0d8019b242544c31c9cdf16f7ced569532949e3ff018fe73e783b0d13f154c2d8b9a0c5a499240dfcb3060
7
- data.tar.gz: d8fb49dc30e0f57b09d48117094979bd8caec876a7445ce82597480ae3c0c940f6185962358c015f5eb10f88a82da4e64411c9a580d327545f503efaa1d1241e
6
+ metadata.gz: 6bd3cd48a338e2c33b8dec7e3a8bc111ad48cc971bccef2b4e685391e1bbd9f53e6d7959dcc2951065a88e72f9fac1f551ae6d10aec1f65dc5884f974b6d190e
7
+ data.tar.gz: 9fdb4ddb415236a49171454b59eb9354bdf50579429c491112c3b3cebba0fc22614ab26285491926e179d72146f63ee85ffe69b8312807cf132db3b84647e156
data/lib/hookit/error.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Hookit
2
2
  module Error
3
+ class MissingConfiguration < StandardError; end
3
4
  class UnexpectedExit < StandardError; end
4
5
  class UnknownAction < StandardError; end
5
6
  class UnsupportedPlatform < StandardError; end
@@ -0,0 +1,19 @@
1
+ module Hookit
2
+ module Platform
3
+ class Docker < Base
4
+
5
+ def detect?
6
+ ! `cat /proc/self/cgroup 2>/dev/null | grep docker`.empty?
7
+ end
8
+
9
+ def name
10
+ 'docker'
11
+ end
12
+
13
+ def os
14
+ 'linux'
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,5 @@
1
1
  require 'hookit/platform/base'
2
+ require 'hookit/plaftorm/docker'
2
3
  require 'hookit/platform/smartos'
3
4
  require 'hookit/platform/ubuntu'
4
5
 
@@ -1,2 +1,3 @@
1
+ Hookit.platforms.register(:docker) { Hookit::Platform::Docker }
1
2
  Hookit.platforms.register(:smartos) { Hookit::Platform::Smartos }
2
3
  Hookit.platforms.register(:ubuntu) { Hookit::Platform::Ubuntu }
@@ -95,6 +95,12 @@ module Hookit
95
95
  def run_command!(cmd, expect_code=0)
96
96
  `#{cmd}`
97
97
  code = $?.exitstatus
98
+
99
+ # break early if the caller doesn't want to validate the exit code
100
+ if expect_code == false
101
+ return
102
+ end
103
+
98
104
  if code != expect_code
99
105
  raise Hookit::Error::UnexpectedExit, "#{cmd} failed with exit code '#{code}'"
100
106
  end
@@ -19,6 +19,8 @@ module Hookit
19
19
  init(:smf)
20
20
  when 'ubuntu'
21
21
  init(:upstart)
22
+ when 'docker'
23
+ init(:runit)
22
24
  end
23
25
  end
24
26
  end
@@ -47,9 +49,40 @@ module Hookit
47
49
  when :smf
48
50
  run_command! "svcadm enable -s #{"-r" if recursive} #{service_name}"
49
51
  when :runit
50
- run_command! "sv start #{service_name}"
52
+ # fail fast if we don't have an runit run configuration
53
+ if not File.exist?("/etc/service/#{service_name}/run")
54
+ raise Hookit::Error::MissingConfiguration "Expecting service configuration file at: /etc/service/#{service_name}/run"
55
+ end
56
+
57
+ # register and potentially start the service
58
+ run_command! "sv start #{service_name}", false
59
+
60
+ # runit can take up to 5 seconds to register the service before the
61
+ # service starts to run. We'll keep checking the status for up to
62
+ # 6 seconds, after which time we'll raise an exception.
63
+ registered = false
64
+
65
+ 6.times do
66
+ # check the status
67
+ `sv status #{service_name}`
68
+ if $?.exitstatus == 0
69
+ registered = true
70
+ break
71
+ end
72
+
73
+ sleep 1
74
+ end
75
+
76
+ if registered
77
+ # just in case the service is registered but not started, try
78
+ # to start the service one more time
79
+ run_command! "sv start #{service_name}"
80
+ else
81
+ raise Hookit::Error::UnexpectedExit "Service #{service_name} did not register within 6 seconds."
82
+ end
83
+
51
84
  else
52
- Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
85
+ raise Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
53
86
  end
54
87
  end
55
88
 
@@ -60,7 +93,7 @@ module Hookit
60
93
  when :runit
61
94
  run_command! "sv stop #{service_name}"
62
95
  else
63
- Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
96
+ raise Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
64
97
  end
65
98
  end
66
99
 
@@ -71,7 +104,7 @@ module Hookit
71
104
  when :runit
72
105
  disable!; enable!
73
106
  else
74
- Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
107
+ raise Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
75
108
  end
76
109
  end
77
110
 
@@ -80,7 +113,7 @@ module Hookit
80
113
  when :smf
81
114
  run_command! "svcadm refresh #{service_name}"
82
115
  else
83
- Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
116
+ raise Hookit::Error::UnsupportedOption "Unsupported init schema '#{init}'"
84
117
  end
85
118
  end
86
119
 
@@ -14,6 +14,15 @@ module Hookit
14
14
  service name unless service
15
15
  max_checks 3 unless max_checks
16
16
  super
17
+
18
+ case platform.os
19
+ when 'sun'
20
+ @active_com=`netstat -an | egrep '\*\.#{port}' | grep LISTEN`
21
+ @inactive_com=`netstat -an | grep 'ESTABLISHED' | awk '{ print $1 }' | grep "$(ifconfig #{interface} | grep inet | awk '{ print $2 }')\.#{port}"`
22
+ else
23
+ @active_com=`netstat -an | egrep ':#{port}' | grep LISTEN`
24
+ @inactive_com=`netstat -an | grep 'ESTABLISHED' | awk '{ print $4 }' | grep "$(ifconfig #{interface} | awk '/inet addr/ { print $2}' | cut -f2 -d':' | tr -d '\n'):#{port}"`
25
+ end
17
26
  end
18
27
 
19
28
  def run(action)
@@ -33,9 +42,10 @@ module Hookit
33
42
  # increment check
34
43
  registry("#{service}.listening", registry("#{service}.listening").to_i + 1)
35
44
 
36
- if `netstat -an | grep '\*\.#{port}' | grep LISTEN`.empty?
45
+ if `#{@active_com}`.empty?
37
46
  count = registry("#{service}.listening").to_i
38
47
  if count <= max_checks
48
+ sleep 1
39
49
  exit(count + 10)
40
50
  else
41
51
  $stderr.puts "ERROR: timed out waiting for #{service} to listen"
@@ -49,8 +59,9 @@ module Hookit
49
59
  # increment check
50
60
  registry("#{service}.no_connections", registry("#{service}.no_connections").to_i + 1)
51
61
 
52
- unless `netstat -an | grep 'ESTABLISHED' | awk '{ print $1 }' | grep "$(ifconfig #{interface} | grep inet | awk '{ print $2 }')\.#{port}"`.empty?
62
+ unless `#{@inactive_com}`.empty?
53
63
  count = registry("#{service}.no_connections").to_i
64
+ sleep 1
54
65
  if count <= max_checks
55
66
  exit(count + 10)
56
67
  end
@@ -1,3 +1,3 @@
1
1
  module Hookit
2
- VERSION = "0.9.2"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Flint
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-08 00:00:00.000000000 Z
12
+ date: 2015-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -153,6 +153,7 @@ files:
153
153
  - lib/hookit/logvac.rb
154
154
  - lib/hookit/platform.rb
155
155
  - lib/hookit/platform/base.rb
156
+ - lib/hookit/platform/docker.rb
156
157
  - lib/hookit/platform/smartos.rb
157
158
  - lib/hookit/platform/ubuntu.rb
158
159
  - lib/hookit/platforms.rb