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_loggers, log_aip_activity, log_preservation_attempt, log_preservation_event, log_preservation_fail_and_retry, log_preservation_failure, log_preservation_success, #logger, preservation_success_to_json, reopen

Constructor Details

#initializeCLI

Returns a new instance of CLI.



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

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



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

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



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

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



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

def start_server
  setup_signal_traps

  setup_log
  print_banner

  run_tick_loop
end