Sha256: 2c57c4baadb552dbdfbf735f9abef0b9f50f0c5b9b8ca2736bab40278bd6606b

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

module Freyr
  class CLI < Thor
    
    desc 'list', 'lists all available services:'
    method_option :ping, :type => :boolean, :default => false, :aliases => '-p', :desc => 'also ping each service which can ping'
    def list
      strs = list_all_services(:ping => options.ping?)
      
      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
    
    desc 'tail [SERVICE=dirname]', 'read stdout of the service'
    method_option :lines, :type => :numeric, :default => 50, :desc => 'Number of lines to show on initial tail'
    method_option :'no-follow', :type => :boolean, :default => false, :desc => 'Disable auto follow, just print tail and exit'
    def tail(name=nil)
      services = get_from_name(name)
      if !services.empty?
        
        services.first.tail!(options.lines, !options['no-follow'])
      else
        say "Can't find the #{name} service", :red
      end
    end
    
    desc 'ping', 'see the response from pinging the url'
    def ping(name=nil)
      service = get_from_name(name).first
      
      if service
        if service.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
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
freyr-0.3.2 lib/freyr/cli/monitor.rb
freyr-0.3.0 lib/freyr/cli/monitor.rb