service_manager 0.6 → 0.6.2
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.
- data/lib/service_manager/service.rb +29 -7
- metadata +6 -5
@@ -1,16 +1,17 @@
|
|
1
1
|
require "thread"
|
2
|
+
require "timeout"
|
2
3
|
class ServiceManager::Service
|
3
4
|
CHDIR_SEMAPHORE = Mutex.new
|
4
|
-
|
5
|
+
ANSI_COLOR_RESET = 0
|
5
6
|
|
6
|
-
attr_accessor :name, :host, :port, :cwd, :reload_uri, :start_cmd, :process, :loaded_cue, :timeout, :color
|
7
|
+
attr_accessor :name, :host, :port, :cwd, :reload_uri, :start_cmd, :process, :loaded_cue, :timeout, :color, :pid_file
|
7
8
|
|
8
9
|
class ServiceDidntStart < Exception; end
|
9
10
|
|
10
11
|
def initialize(options = {})
|
11
12
|
options.each { |k,v| send("#{k}=", v) }
|
12
13
|
self.host ||= "localhost"
|
13
|
-
self.color ||=
|
14
|
+
self.color ||= ANSI_COLOR_RESET
|
14
15
|
self.timeout ||= 30
|
15
16
|
raise ArgumentError, "You need to provide a name for this app service" unless name
|
16
17
|
end
|
@@ -20,7 +21,7 @@ class ServiceManager::Service
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def server_info_hash
|
23
|
-
{:name => name, :host => host, :port => port}
|
24
|
+
{:name => name, :host => host, :port => port, :pid_file => pid_file}
|
24
25
|
end
|
25
26
|
|
26
27
|
def watch_for_cue
|
@@ -92,12 +93,23 @@ class ServiceManager::Service
|
|
92
93
|
|
93
94
|
# detects if the service is running on the configured host and port (will return true if we weren't the ones who started it)
|
94
95
|
def running?
|
95
|
-
|
96
|
+
if pid_file
|
97
|
+
running_via_pid_file?
|
98
|
+
else
|
99
|
+
TCPSocket.listening_service?(:port => port, :host => host)
|
100
|
+
end
|
96
101
|
end
|
97
102
|
|
98
103
|
protected
|
104
|
+
|
105
|
+
def running_via_pid_file?
|
106
|
+
Process.kill(0, File.read(pid_file).to_i)
|
107
|
+
rescue Errno::ESRCH, Errno::ENOENT
|
108
|
+
return false
|
109
|
+
end
|
110
|
+
|
99
111
|
def colorize(output)
|
100
|
-
"\e[0;#{color}m#{output}\e[0;#{
|
112
|
+
"\e[0;#{color}m#{output}\e[0;#{ANSI_COLOR_RESET}m"
|
101
113
|
end
|
102
114
|
|
103
115
|
def colorized_service_name
|
@@ -115,11 +127,21 @@ protected
|
|
115
127
|
else
|
116
128
|
start_output_stream_thread
|
117
129
|
begin
|
118
|
-
|
130
|
+
if pid_file
|
131
|
+
wait_for_server_with_timeout
|
132
|
+
else
|
133
|
+
TCPSocket.wait_for_service_with_timeout({:host => host, :port => port, :timeout => timeout})
|
134
|
+
end
|
119
135
|
rescue SocketError
|
120
136
|
raise ServiceDidntStart
|
121
137
|
end
|
122
138
|
end
|
123
139
|
true
|
124
140
|
end
|
141
|
+
|
142
|
+
def wait_for_server_with_timeout
|
143
|
+
Timeout::timeout(timeout) do
|
144
|
+
sleep 0.25 while !running_via_pid_file?
|
145
|
+
end
|
146
|
+
end
|
125
147
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 3
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Tim Harper
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-07-28 00:00:00 -06:00
|
18
19
|
default_executable: start_services
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
requirements: []
|
98
99
|
|
99
100
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.5.0
|
101
102
|
signing_key:
|
102
103
|
specification_version: 3
|
103
104
|
summary: service_manager
|