vnctools 0.0.6 → 0.0.7
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/vnctools/server.rb +18 -1
- data/lib/vnctools/version.rb +1 -1
- data/spec/vnctools/server_spec.rb +14 -0
- metadata +1 -1
data/lib/vnctools/server.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "socket"
|
2
|
+
require 'pathname'
|
2
3
|
|
3
4
|
module VncTools
|
4
5
|
class Server
|
@@ -37,8 +38,24 @@ module VncTools
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
def stop
|
41
|
+
def stop(force = false)
|
41
42
|
server "-kill", display.to_s
|
43
|
+
rescue Error
|
44
|
+
force_kill if force
|
45
|
+
end
|
46
|
+
|
47
|
+
def force_kill
|
48
|
+
if pid_path.exist?
|
49
|
+
Process.kill(9, Integer(pid_path.read))
|
50
|
+
pid_path.delete if pid_path.exist?
|
51
|
+
end
|
52
|
+
rescue Errno::ESRCH
|
53
|
+
# already gone
|
54
|
+
pid_path.delete if pid_path.exist?
|
55
|
+
end
|
56
|
+
|
57
|
+
def pid_path
|
58
|
+
@pid_path ||= Pathname.new(File.expand_path("~/.vnc/#{host}#{display}.pid"))
|
42
59
|
end
|
43
60
|
|
44
61
|
private
|
data/lib/vnctools/version.rb
CHANGED
@@ -18,6 +18,20 @@ module VncTools
|
|
18
18
|
server.stop
|
19
19
|
end
|
20
20
|
|
21
|
+
it "forcefully stops the server" do
|
22
|
+
server.should_receive(:`).with("tightvncserver -kill :5 2>&1")
|
23
|
+
server.stub :last_status => mock(:success? => false)
|
24
|
+
server.stub :display => ":5"
|
25
|
+
|
26
|
+
mock_pathname = mock('Pathname:5.pid', :exist? => true)
|
27
|
+
Pathname.should_receive(:new).with("#{ENV['HOME']}/.vnc/#{Socket.gethostname}:5.pid").and_return(mock_pathname)
|
28
|
+
mock_pathname.should_receive(:read).and_return 123123
|
29
|
+
mock_pathname.should_receive(:delete)
|
30
|
+
Process.should_receive(:kill).with(9, 123123)
|
31
|
+
|
32
|
+
server.stop(true)
|
33
|
+
end
|
34
|
+
|
21
35
|
it "raises Server::Error if the server could not be started" do
|
22
36
|
server.should_receive(:`).and_return("oops")
|
23
37
|
server.stub :last_status => mock(:success? => false)
|