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)


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

def running?
  return false unless File.exist?(config.pid_file)

  pid = read_pid
  return false unless pid

  process_alive?(pid)
end

#startObject



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

def start
  ensure_not_running!
  generate_config_ru
  start_server
end

#start_foregroundObject



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

def start_foreground
  ensure_not_running!
  generate_config_ru
  start_server_foreground
end

#statusObject



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

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

#stopObject



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

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

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