Class: ActiveMatrix::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/active_matrix/cli.rb

Overview

Command-line interface for ActiveMatrix daemon

Examples:

Start the daemon

bundle exec activematrix start

Start with options

bundle exec activematrix start --workers 3 --probe-port 3042

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


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

def self.exit_on_failure?
  true
end

Instance Method Details

#reloadObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/active_matrix/cli.rb', line 88

def reload
  pid = read_pid
  unless pid
    say 'Daemon not running', :red
    exit 1
  end

  begin
    Process.kill('HUP', pid)
    say 'Reload signal sent', :green
  rescue Errno::ESRCH
    say 'Process not running', :red
    exit 1
  rescue Errno::EPERM
    say 'Permission denied', :red
    exit 1
  end
end

#startObject



34
35
36
37
38
39
40
41
# File 'lib/active_matrix/cli.rb', line 34

def start
  boot_rails
  configure_from_options

  daemonize if options[:daemon] || options[:pidfile]

  run_daemon
end

#statusObject



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/active_matrix/cli.rb', line 74

def status
  # Try HTTP probe first
  if (probe_status = fetch_probe_status)
    display_status(probe_status)
  elsif (pid = read_pid)
    say "Daemon running (PID: #{pid}), but health probe not responding", :yellow
  else
    say 'Daemon not running', :red
    exit 1
  end
end

#stopObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_matrix/cli.rb', line 46

def stop
  pidfile = options[:pidfile]

  unless File.exist?(pidfile)
    say "PID file not found: #{pidfile}", :red
    exit 1
  end

  pid = File.read(pidfile).to_i
  say "Stopping ActiveMatrix daemon (PID: #{pid})..."

  begin
    Process.kill('TERM', pid)
    wait_for_shutdown(pid, options[:timeout])
    say 'Daemon stopped successfully', :green
  rescue Errno::ESRCH
    say 'Process not running, cleaning up PID file', :yellow
    File.delete(pidfile)
  rescue Errno::EPERM
    say "Permission denied to stop process #{pid}", :red
    exit 1
  end
end

#versionObject



108
109
110
# File 'lib/active_matrix/cli.rb', line 108

def version
  say "ActiveMatrix #{ActiveMatrix::VERSION}"
end