Class: Freyr::CLI
- Inherits:
-
Thor
- Object
- Thor
- Freyr::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/freyr/cli.rb,
lib/freyr/cli/helpers.rb,
lib/freyr/cli/monitor.rb,
lib/freyr/cli/launching.rb,
lib/freyr/cli/management.rb
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #ping(name = nil) ⇒ Object
- #restart(name = nil) ⇒ Object
- #start(name = nil) ⇒ Object
- #stop(name = nil) ⇒ Object
- #tail(name = nil) ⇒ Object
- #version ⇒ Object
Constructor Details
Instance Method Details
#list ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/freyr/cli/monitor.rb', line 7 def list strs = list_all_services(:ping => .ping?, :procinfo => .info?) if strs.empty? say "No services available", :red else say "List of all available services (#{set_color('*', :yellow)} denotes root proc)" strs.each_with_index do |s,i| say s end end end |
#ping(name = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/freyr/cli/monitor.rb', line 35 def ping(name=nil) service = get_from_name(name).first if service if service.info.ping pinger = Pinger.new(service) resp = pinger.ping if pinger.success? say "Up and running", :green elsif pinger.server_error? say "500 Error" elsif resp say "Returned #{resp.code} code", :red else say "Couldn't reach service", :red end else say 'No url to ping for this service' end else say "Can't find the #{name} service", :red end end |
#restart(name = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/freyr/cli/launching.rb', line 49 def restart(name=nil) services = get_from_name(name) if services && !services.empty? Freyr.logger.debug('restarting services') {services.inspect} say "Restarting the " << set_color(services.collect {|s| s.name}.join(', '), :blue) << ' services' names = services.restart list_all_services(:highlight_state => names).each {|l| say(l)} else say "Can't find the #{name} service", :red exit(false) end rescue AdminRequired say "Please run in sudo to launch #{name}.", :red exit(false) end |
#start(name = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/freyr/cli/launching.rb', line 6 def start(name=nil) services = get_from_name(name) if services && !services.empty? Freyr.logger.debug('starting services') {services.inspect} names = services.call_order.collect {|s| s.name} say "Starting the " << set_color(names.join(', '), :blue) << ' services' changed_names = services.run list_all_services(:highlight_state => changed_names).each {|l| say(l)} else say "Can't find the #{name} service", :red exit(false) end rescue AdminRequired say "Please run in sudo to launch #{name}.", :red exit(false) rescue Service::MissingDependency => e say "Missing dependency, could not launch service: #{e.to_s}" exit(false) end |
#stop(name = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/freyr/cli/launching.rb', line 29 def stop(name=nil) services = get_from_name(name) if services && !services.empty? Freyr.logger.debug('stopping services') {services.inspect} names = services.collect {|s| s.name} say "Stopping the " << set_color(names.join(', '), :blue) << ' services' changed_names = services.stop list_all_services(:highlight_state => changed_names).each {|l| say(l)} else say "Can't find the #{name} service", :red exit(false) end rescue AdminRequired say "Please run in sudo to stop #{name}.", :red exit(false) end |
#tail(name = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/freyr/cli/monitor.rb', line 23 def tail(name=nil) services = get_from_name(name) if !services.empty? Freyr.logger.debug('tail args') {"Lines: #{.lines}, following: #{!['no-follow']}"} Freyr.logger.debug('tailing service') {services.first.inspect} services.first.tail!(.lines, !['no-follow']) else say "Can't find the #{name} service", :red end end |