Class: Brick::CLI::Run

Inherits:
Brick::CLI show all
Defined in:
lib/brick/cli/run.rb

Instance Method Summary collapse

Methods inherited from Brick::CLI

category, common_optparser, dependency_loaders, deps, #humanize_exception, inherited, #initialize, list_commands, list_parameters, load_commands, load_deps, logger, run, #run_with_pretty_exceptions, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_loader, subcommand_not_found!, subcommands, subcommands_by_category, unnamed?

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixlib::CLI

#parse_options

Constructor Details

This class inherits a constructor from Brick::CLI

Instance Method Details

#runObject

By default, it’s running in background



44
45
46
47
48
49
50
51
52
53
54
55
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/brick/cli/run.rb', line 44

def run
  #::Brick::CLI::logger.info "hello, #{banner}, option[:no_cache]=#{::Brick::Config.configuration}"
  project_name = ::Brick::Config[:project]
  
  config_file = ::Brick::Config[:config_file]
  
  project_dir = File.dirname(config_file)
  
  detach_mode = ::Brick::Config[:detach_mode]
  
  start_link_mode = ::Brick::Config[:deps]
  
  project = ::Brick::Models::Project.new(project_name,{:config_file => config_file})
  
  entrypoint = ::Brick::Config[:entrypoint]
  
  if @cmd_args.size > 0
    service_name = @cmd_args[0]
  else
    puts "You must specify the servcie name to run"
    exit 1
  end
  
  cmd_array = @cmd_args - [@cmd_args[0]]
  
  
  service = project.get_service service_name
  
  if cmd_array.size >0
    service.service_config_hash["command"] = cmd_array
  end
  
  unless entrypoint.nil?
    service.service_config_hash["entrypoint"] = entrypoint.split(" ")
  end
  
  disable_tty=::Brick::Config[:T]
  
  if disable_tty
    service.service_config_hash["tty"] = false
  else
    service.service_config_hash["tty"] = true
  end
  
  
  
  puts "running service #{service_name}"
  
  if service.running?
    puts "exec #{cmd_array} on running service #{service_name}"
    
    service.exec cmd_array, {:detach => detach_mode}
    
  else
    puts "start service #{service_name}"
    project.run_services(service_name,start_link_mode)
    
    unless service.running?
      raise "#{service_name} is failed to start"
    end
    
    unless detach_mode
      service.attach
    end
  end
  
  ::Brick::Models::Service.wait_for_deamon
  
end