Class: Skylight::CLI::Doctor

Inherits:
Thor::Group show all
Includes:
Helpers
Defined in:
lib/skylight/cli/doctor.rb

Instance Attribute Summary

Attributes included from Thor::Base

#args, #options, #parent_options

Instance Method Summary collapse

Methods inherited from Thor::Group

class_options_help, desc, get_options_from_invocations, handle_argument_error, help, invocation_blocks, invocations, invoke, invoke_from_option, printable_commands, remove_invocation

Methods included from Thor::Base

included, #initialize, register_klass_file, shell, shell=, subclass_files, subclasses

Instance Method Details

#check_configObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/skylight/cli/doctor.rb', line 83

def check_config
  say "Checking for valid configuration"

  indent do
    config.validate!
    say "Configuration is valid", :green
  rescue ConfigError => e
    encountered_error!

    say "Configuration is invalid", :red
    indent do
      say e.message, :red
      say "This may occur if you are configuring with ENV variables and didn't set them in this shell."
    end

    done!
  end

  puts "\n"
end

#check_daemonObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/skylight/cli/doctor.rb', line 104

def check_daemon
  say "Checking Skylight startup"

  indent do
    # Set this after we validate. It will give us more detailed information on start.
    logger = Logger.new("/dev/null") # Rely on `say` in the formatter instead

    # Log everything
    logger.level = Logger::DEBUG

    # Remove excess formatting
    logger.formatter =
      proc do |severity, _datetime, _progname, msg|
        msg = msg.sub("[SKYLIGHT] [#{Skylight::VERSION}] ", "")
        say "#{severity} - #{msg}" # Definitely non-standard
      end
    config.logger = logger

    config.set(:"daemon.lazy_start", false)

    started = Skylight.start!(config)

    if started
      say "Successfully started", :green
    else
      encountered_error!

      say "Failed to start", :red

      done!
    end

    say "Waiting for daemon... "

    # Doesn't start immediately
    tries = 0
    daemon_running = false
    while tries < 5
      `ps cax | grep skylightd`
      if $CHILD_STATUS.success?
        daemon_running = true
        break
      end

      tries += 1
      sleep 1
    end

    if daemon_running
      say "Success", :green
    else
      encountered_error!

      say "Failed", :red
    end
  end

  say "\n"
end

#check_nativeObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/skylight/cli/doctor.rb', line 56

def check_native
  say "Checking for native agent"

  indent do
    if Skylight.native?
      say "Native agent installed", :green
    else
      encountered_error!

      say "Unable to load native extension", :yellow

      indent do
        install_log = File.expand_path("../../../ext/install.log", __dir__)
        if File.exist?(install_log)
          File.readlines(install_log).each { |line| say line, :red }
        else
          say "Reason unknown", :red
        end
      end

      done!
    end
  end

  say "\n"
end

#check_railsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/skylight/cli/doctor.rb', line 40

def check_rails
  say "Checking for Rails"

  indent do
    if rails?
      say "Rails application detected", :green
    else
      say "No Rails application detected", :yellow
      say "Additional `skylight doctor` checks only work with Rails applications.", :yellow
      done!
    end
  end

  say "\n"
end

#check_sslObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/skylight/cli/doctor.rb', line 10

def check_ssl
  say "Checking SSL"
  http = Util::HTTP.new(config)
  indent do
    req = http.get("/status")
    if req.success?
      say "OK", :green
    else
      encountered_error!
      if req.exception.is_a?(Util::HTTP::StartError) && req.exception.original.is_a?(OpenSSL::SSL::SSLError)
        say "Failed to verify SSL certificate.", :red
        if Util::SSL.ca_cert_file?
          say "Certificates located at #{Util::SSL.ca_cert_file_or_default} may be out of date.", :yellow
          if mac? && rvm_present?
            say "Please update your certificates with RVM by running `rvm osx-ssl-certs update all`.", :yellow
            say "Alternatively, try setting `SKYLIGHT_FORCE_OWN_CERTS=1` in your environment.", :yellow
          else
            say "Please update your local certificates or try setting `SKYLIGHT_FORCE_OWN_CERTS=1` in your " \
                  "environment.",
                :yellow
          end
        end
      else
        say "Unable to reach Skylight servers.", :red
      end
    end
  end
  say "\n"
end

#wrap_upObject



164
165
166
# File 'lib/skylight/cli/doctor.rb', line 164

def wrap_up
  done!
end