guard-spork 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/guard/spork.rb +3 -0
- data/lib/guard/spork/runner.rb +11 -1
- data/lib/guard/spork/spork_instance.rb +50 -15
- data/lib/guard/spork/version.rb +1 -1
- metadata +34 -2
data/README.md
CHANGED
data/lib/guard/spork.rb
CHANGED
data/lib/guard/spork/runner.rb
CHANGED
@@ -62,7 +62,17 @@ module Guard
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def ps_spork_pids
|
65
|
-
|
65
|
+
unless SporkInstance.windows?
|
66
|
+
`ps aux | awk '/spork/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i }
|
67
|
+
else
|
68
|
+
Sys::ProcTable.ps.reduce([]) do |spork_pids, process|
|
69
|
+
spork_process = process.cmdline =~ /spork/ ||
|
70
|
+
process.cmdline =~ /ring_server/ ||
|
71
|
+
process.cmdline =~ /magazine_slave_provider/
|
72
|
+
spork_pids << process.pid if spork_process
|
73
|
+
spork_pids
|
74
|
+
end
|
75
|
+
end
|
66
76
|
end
|
67
77
|
|
68
78
|
def find_instances(type = nil)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Guard
|
2
2
|
class Spork
|
3
3
|
class SporkInstance
|
4
|
-
attr_reader :type, :env, :port, :options, :pid
|
4
|
+
attr_reader :type, :env, :port, :options, :pid, :process
|
5
5
|
|
6
6
|
def initialize(type, port, env, options)
|
7
7
|
@type = type
|
@@ -26,24 +26,39 @@ module Guard
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def start
|
29
|
-
|
30
|
-
|
29
|
+
cmd = [command]
|
30
|
+
|
31
|
+
if self.class.windows?
|
32
|
+
cmd = ["cmd", "/C"] + cmd
|
31
33
|
end
|
34
|
+
|
35
|
+
@process = ChildProcess.build *cmd
|
36
|
+
@process.environment.merge!(env)
|
37
|
+
@process.io.inherit!
|
38
|
+
@process.start
|
39
|
+
@pid = @process.pid
|
32
40
|
end
|
33
41
|
|
34
42
|
def stop
|
35
|
-
|
43
|
+
unless self.class.windows?
|
44
|
+
process.stop
|
45
|
+
else
|
46
|
+
kill_all_child_processes
|
47
|
+
end
|
36
48
|
end
|
37
49
|
|
38
50
|
def alive?
|
39
|
-
|
40
|
-
::Process.waitpid(pid, ::Process::WNOHANG).nil?
|
51
|
+
pid && process.alive?
|
41
52
|
end
|
42
53
|
|
43
54
|
def running?
|
44
|
-
return false unless
|
55
|
+
return false unless alive?
|
45
56
|
TCPSocket.new('localhost', port).close
|
46
|
-
|
57
|
+
if self.class.windows?
|
58
|
+
running_on_windows?
|
59
|
+
else
|
60
|
+
true
|
61
|
+
end
|
47
62
|
rescue Errno::ECONNREFUSED
|
48
63
|
false
|
49
64
|
end
|
@@ -67,13 +82,8 @@ module Guard
|
|
67
82
|
parts.join(" ")
|
68
83
|
end
|
69
84
|
|
70
|
-
def
|
71
|
-
|
72
|
-
exec environment, command
|
73
|
-
else
|
74
|
-
environment.each_pair { |key, value| ENV[key] = value }
|
75
|
-
exec command
|
76
|
-
end
|
85
|
+
def self.windows?
|
86
|
+
RUBY_PLATFORM =~ /mswin|msys|mingw/
|
77
87
|
end
|
78
88
|
|
79
89
|
private
|
@@ -86,6 +96,31 @@ module Guard
|
|
86
96
|
options[:foreman]
|
87
97
|
end
|
88
98
|
|
99
|
+
def kill_all_child_processes
|
100
|
+
all_pids_for(pid).each do |pid|
|
101
|
+
Process.kill 9, pid
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def all_pids_for(parent_pid)
|
106
|
+
pids = [parent_pid]
|
107
|
+
Sys::ProcTable.ps do |process|
|
108
|
+
pids += all_pids_for(process.pid) if process.ppid == parent_pid
|
109
|
+
end
|
110
|
+
pids
|
111
|
+
end
|
112
|
+
|
113
|
+
def running_on_windows?
|
114
|
+
DRb.start_service
|
115
|
+
# make sure that ringfinger is not taken from cache, because it won't
|
116
|
+
# work after guard-spork has been restarted
|
117
|
+
Rinda::RingFinger.class_variable_set :@@finger, nil
|
118
|
+
ts = Rinda::RingFinger.primary
|
119
|
+
ts.read_all([:name, :MagazineSlave, nil, nil]).size > 0
|
120
|
+
rescue DRb::DRbConnError
|
121
|
+
false
|
122
|
+
end
|
123
|
+
|
89
124
|
end
|
90
125
|
end
|
91
126
|
end
|
data/lib/guard/spork/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-spork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
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: 2012-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|
@@ -43,6 +43,38 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.8.4
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: childprocess
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sys-proctable
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
- !ruby/object:Gem::Dependency
|
47
79
|
name: bundler
|
48
80
|
requirement: !ruby/object:Gem::Requirement
|