Class: EasyCaddy::Commands::Run

Inherits:
Object
  • Object
show all
Includes:
RegisterHelpers
Defined in:
lib/easy_caddy/commands/run.rb

Overview

Foreground command for Procfile.dev. Registers the project Caddyfile on start, blocks until SIGTERM/SIGINT, then unregisters and exits cleanly.

Instance Method Summary collapse

Constructor Details

#initialize(config_path:, site:) ⇒ Run

Returns a new instance of Run.



13
14
15
16
# File 'lib/easy_caddy/commands/run.rb', line 13

def initialize(config_path:, site:)
  @config_path = config_path
  @site        = site
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/easy_caddy/commands/run.rb', line 18

def call
  @registered_name = register(@config_path, @site)

  cleanup = proc do
    puts "\n  [ecaddy] Shutting down — removing #{@registered_name}..."
    unregister(@registered_name)
    exit 0
  end

  Signal.trap('TERM', &cleanup)
  Signal.trap('INT',  &cleanup)

  puts "  [ecaddy] Watching. Send SIGTERM or Ctrl-C to unregister."
  loop { sleep 5 }
end