Class: PushmiPullyu::CLI

Inherits:
Object
  • Object
show all
Includes:
Logging, Singleton
Defined in:
lib/pushmi_pullyu/cli.rb

Overview

CLI runner

Constant Summary collapse

COMMANDS =
['start', 'stop', 'restart', 'reload', 'run', 'zap', 'status'].freeze

Instance Method Summary collapse

Methods included from Logging

initialize_logger, log_aip_activity, log_preservation_event, #logger, reopen

Constructor Details

#initializeCLI

Returns a new instance of CLI.


16
17
18
19
# File 'lib/pushmi_pullyu/cli.rb', line 16

def initialize
  PushmiPullyu.server_running = true # set to false by interrupt signal trap
  PushmiPullyu.reset_logger = false # set to true by SIGHUP trap
end

Instance Method Details

#parse(argv = ARGV) ⇒ Object


21
22
23
24
25
26
27
# File 'lib/pushmi_pullyu/cli.rb', line 21

def parse(argv = ARGV)
  opts = parse_options(argv)
  opts[:daemonize] = true if COMMANDS.include? argv[0]
  opts = parse_config(opts[:config_file]).merge(opts) if opts[:config_file]

  PushmiPullyu.options = opts
end

#runObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pushmi_pullyu/cli.rb', line 29

def run
  configure_rollbar
  begin
    if options[:daemonize]
      start_server_as_daemon
    else
      # If we're running in the foreground sync the output.
      $stdout.sync = $stderr.sync = true
      start_server
    end
  # rubocop:disable Lint/RescueException
  rescue Exception => e
    Rollbar.error(e)
    raise e
  end
  # rubocop:enable Lint/RescueException
end

#start_serverObject


47
48
49
50
51
52
53
54
# File 'lib/pushmi_pullyu/cli.rb', line 47

def start_server
  setup_signal_traps

  setup_log
  print_banner

  run_tick_loop
end