Class: Gemkeeper::ServerManager

Inherits:
Object
  • Object
show all
Defined in:
lib/gemkeeper/server_manager.rb

Overview

Owns the rackup/puma lifecycle so CLI commands delegate process management here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ServerManager

Returns a new instance of ServerManager.



11
12
13
# File 'lib/gemkeeper/server_manager.rb', line 11

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/gemkeeper/server_manager.rb', line 9

def config
  @config
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'lib/gemkeeper/server_manager.rb', line 50

def running?
  if File.exist?(config.pid_file)
    pid = read_pid
    return process_alive?(pid) if pid
  end
  port_open?
end

#startObject



15
16
17
18
# File 'lib/gemkeeper/server_manager.rb', line 15

def start
  ensure_not_running!
  RackupProcess.new(config).start
end

#start_foregroundObject



20
21
22
23
# File 'lib/gemkeeper/server_manager.rb', line 20

def start_foreground
  ensure_not_running!
  RackupProcess.new(config).start_foreground
end

#statusObject



42
43
44
45
46
47
48
# File 'lib/gemkeeper/server_manager.rb', line 42

def status
  if running?
    { running: true, pid: read_pid, url: config.geminabox_url }
  else
    { running: false }
  end
end

#stopObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gemkeeper/server_manager.rb', line 25

def stop
  raise ServerNotRunningError, "Server is not running" unless running?

  pid = read_pid
  unless pid
    raise ServerError, "Server is running but not managed by gemkeeper — use 'brew services stop gemkeeper'"
  end

  Process.kill("TERM", pid)
  wait_for_process_exit(pid)
  cleanup_pid_file
  true
rescue Errno::ESRCH
  cleanup_pid_file
  true
end