lib/vnctools/server.rb in vnctools-0.0.6 vs lib/vnctools/server.rb in vnctools-0.0.7
- old
+ new
@@ -1,6 +1,7 @@
require "socket"
+require 'pathname'
module VncTools
class Server
class Error < StandardError
@@ -35,11 +36,27 @@
output = server(*launch_arguments)
@display = output[/desktop is #{host}(\S+)/, 1]
end
end
- def stop
+ def stop(force = false)
server "-kill", display.to_s
+ rescue Error
+ force_kill if force
+ end
+
+ def force_kill
+ if pid_path.exist?
+ Process.kill(9, Integer(pid_path.read))
+ pid_path.delete if pid_path.exist?
+ end
+ rescue Errno::ESRCH
+ # already gone
+ pid_path.delete if pid_path.exist?
+ end
+
+ def pid_path
+ @pid_path ||= Pathname.new(File.expand_path("~/.vnc/#{host}#{display}.pid"))
end
private
def launch_arguments