Sha256: 08d79cf1abc7c0d619235a1edfa8a4b1314316dd14ecb533beec8b7c82a8512b

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

module Freyr
  class CLI < Thor
    # TODO: DRY up start/restart/stop commands
    
    desc 'start [SERVICE=dirname]', 'Start particular service'
    def start(name=nil)
      services = get_from_name(name)
      if !services.empty?
        Freyr.logger.debug('starting services') {services.inspect}
        names = services.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
      end
    rescue AdminRequired
      say "Please run in sudo to launch #{name}.", :red
    end
    
    desc 'stop [SERVICE=dirname]', 'Stop particular service'
    def stop(name=nil)
      services = get_from_name(name)
      if !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
      end  
    rescue AdminRequired
      say "Please run in sudo to stop #{name}.", :red
    end
    
    desc 'restart [SERVICE=dirname]', 'restart particular service'
    def restart(name=nil)
      services = get_from_name(name)
      if !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
      end
      
    rescue AdminRequired
      say "Please run in sudo to launch #{name}.", :red
    end
    
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
freyr-0.4.2 lib/freyr/cli/launching.rb
freyr-0.4.1 lib/freyr/cli/launching.rb
freyr-0.4.0 lib/freyr/cli/launching.rb
freyr-0.3.13 lib/freyr/cli/launching.rb
freyr-0.3.12 lib/freyr/cli/launching.rb
freyr-0.3.11 lib/freyr/cli/launching.rb
freyr-0.3.9 lib/freyr/cli/launching.rb
freyr-0.3.8 lib/freyr/cli/launching.rb