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 +4 -4
- data/lib/hookit/error.rb +1 -0
- data/lib/hookit/platform/docker.rb +19 -0
- data/lib/hookit/platform.rb +1 -0
- data/lib/hookit/platforms.rb +1 -0
- data/lib/hookit/resource/base.rb +6 -0
- data/lib/hookit/resource/service.rb +38 -5
- data/lib/hookit/resource/socket.rb +13 -2
- data/lib/hookit/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be8d878c31cfb5843f20a99980f9f2fa7491c6b6
|
4
|
+
data.tar.gz: ce6373de03a2d8276e0b2409b080752d769dd08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bd3cd48a338e2c33b8dec7e3a8bc111ad48cc971bccef2b4e685391e1bbd9f53e6d7959dcc2951065a88e72f9fac1f551ae6d10aec1f65dc5884f974b6d190e
|
7
|
+
data.tar.gz: 9fdb4ddb415236a49171454b59eb9354bdf50579429c491112c3b3cebba0fc22614ab26285491926e179d72146f63ee85ffe69b8312807cf132db3b84647e156
|
data/lib/hookit/error.rb
CHANGED
data/lib/hookit/platform.rb
CHANGED
data/lib/hookit/platforms.rb
CHANGED
data/lib/hookit/resource/base.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
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
|
data/lib/hookit/version.rb
CHANGED
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.
|
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-
|
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
|