Class: VncTools::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/vnctools/server.rb

Defined Under Namespace

Classes: Error

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display = nil) ⇒ Server

Returns a new instance of Server.



28
29
30
# File 'lib/vnctools/server.rb', line 28

def initialize(display = nil)
  @display = display
end

Class Attribute Details

.executableObject



21
22
23
# File 'lib/vnctools/server.rb', line 21

def executable
  @executable ||= "tightvncserver"
end

Instance Attribute Details

#displayObject (readonly)

Returns the value of attribute display.



26
27
28
# File 'lib/vnctools/server.rb', line 26

def display
  @display
end

Class Method Details

.allObject



15
16
17
# File 'lib/vnctools/server.rb', line 15

def all
  displays.map { |display| new ":#{display}" }
end

.displaysObject



11
12
13
# File 'lib/vnctools/server.rb', line 11

def displays
  Dir[File.expand_path("~/.vnc/*.pid")].map { |e| e[/(\d+)\.pid/, 1] }.compact
end

Instance Method Details

#force_killObject



48
49
50
51
52
53
54
55
56
# File 'lib/vnctools/server.rb', line 48

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_pathObject



58
59
60
# File 'lib/vnctools/server.rb', line 58

def pid_path
  @pid_path ||= Pathname.new(File.expand_path("~/.vnc/#{host}#{display}.pid"))
end

#startObject



32
33
34
35
36
37
38
39
40
# File 'lib/vnctools/server.rb', line 32

def start
  if display
    server(display, *launch_arguments)
  else
    output = server(*launch_arguments)
    @display = output[/desktop is #{host}(\S+)/, 1]
    @display or raise Error, "could not find display in #{output.inspect}"
  end
end

#stop(force = false) ⇒ Object



42
43
44
45
46
# File 'lib/vnctools/server.rb', line 42

def stop(force = false)
  server "-kill", display.to_s
rescue Error
  force_kill if force
end