Class: VncTools::Server
- Inherits:
-
Object
- Object
- VncTools::Server
- Defined in:
- lib/vnctools/server.rb
Defined Under Namespace
Classes: Error
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#display ⇒ Object
readonly
Returns the value of attribute display.
Class Method Summary collapse
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #dead? ⇒ Boolean
- #force_kill ⇒ Object
-
#initialize(display = nil) ⇒ Server
constructor
A new instance of Server.
- #pid_path ⇒ Object
- #start ⇒ Object
- #stop(force = false) ⇒ Object
Constructor Details
#initialize(display = nil) ⇒ Server
Returns a new instance of Server.
32 33 34 |
# File 'lib/vnctools/server.rb', line 32 def initialize(display = nil) @display = display end |
Class Attribute Details
.executable ⇒ Object
21 22 23 |
# File 'lib/vnctools/server.rb', line 21 def executable @executable ||= find_executable end |
Instance Attribute Details
#display ⇒ Object (readonly)
Returns the value of attribute display.
30 31 32 |
# File 'lib/vnctools/server.rb', line 30 def display @display end |
Class Method Details
.all ⇒ Object
15 16 17 |
# File 'lib/vnctools/server.rb', line 15 def all displays.map { |display| new ":#{display}" } end |
.displays ⇒ Object
11 12 13 |
# File 'lib/vnctools/server.rb', line 11 def displays Dir[File.("~/.vnc/*.pid")].map { |e| e[/(\d+)\.pid/, 1] }.compact end |
.find_executable ⇒ Object
25 26 27 |
# File 'lib/vnctools/server.rb', line 25 def find_executable `which tightvncserver vncserver xtightvncserver`.each_line.map(&:strip).first || 'tightvncserver' end |
Instance Method Details
#alive? ⇒ Boolean
63 64 65 66 67 68 |
# File 'lib/vnctools/server.rb', line 63 def alive? pid_path.exist? && Process.kill(0, Integer(pid_path.read)) rescue Errno::ESRCH pid_path.delete if pid_path.exist? false end |
#dead? ⇒ Boolean
70 71 72 |
# File 'lib/vnctools/server.rb', line 70 def dead? !alive? end |
#force_kill ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/vnctools/server.rb', line 53 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 |
#pid_path ⇒ Object
74 75 76 |
# File 'lib/vnctools/server.rb', line 74 def pid_path @pid_path ||= Pathname.new(File.("~/.vnc/#{host}#{display}.pid")) end |
#start ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vnctools/server.rb', line 36 def start if display server(display, *launch_arguments) else output = server(*launch_arguments) rx = /desktop is #{host}(\S+)/ @display = output[rx, 1] @display or raise Error, "could not find display in #{output.inspect} =~ #{rx.source}" end end |
#stop(force = false) ⇒ Object
47 48 49 50 51 |
# File 'lib/vnctools/server.rb', line 47 def stop(force = false) server "-kill", display.to_s rescue Error force_kill if force end |