Class: Gemkeeper::ServerManager
- Inherits:
-
Object
- Object
- Gemkeeper::ServerManager
- Defined in:
- lib/gemkeeper/server_manager.rb
Overview
Owns the rackup/puma lifecycle so CLI commands delegate process management here.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ ServerManager
constructor
A new instance of ServerManager.
- #running? ⇒ Boolean
- #start ⇒ Object
- #start_foreground ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(config) ⇒ ServerManager
Returns a new instance of ServerManager.
10 11 12 |
# File 'lib/gemkeeper/server_manager.rb', line 10 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/gemkeeper/server_manager.rb', line 8 def config @config end |
Instance Method Details
#running? ⇒ Boolean
45 46 47 48 49 50 51 52 |
# File 'lib/gemkeeper/server_manager.rb', line 45 def running? return false unless File.exist?(config.pid_file) pid = read_pid return false unless pid process_alive?(pid) end |
#start ⇒ Object
14 15 16 17 |
# File 'lib/gemkeeper/server_manager.rb', line 14 def start ensure_not_running! RackupProcess.new(config).start end |
#start_foreground ⇒ Object
19 20 21 22 |
# File 'lib/gemkeeper/server_manager.rb', line 19 def start_foreground ensure_not_running! RackupProcess.new(config).start_foreground end |
#status ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/gemkeeper/server_manager.rb', line 37 def status if running? { running: true, pid: read_pid, url: config.geminabox_url } else { running: false } end end |
#stop ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gemkeeper/server_manager.rb', line 24 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 |