Class: Jarl::Application::Instance
- Inherits:
-
Object
- Object
- Jarl::Application::Instance
- Defined in:
- lib/jarl/application.rb
Overview
Application::Instance represents a single running instance of the application
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
Instance Method Summary collapse
- #full_name ⇒ Object
- #hostname ⇒ Object
-
#initialize(application, n, container) ⇒ Instance
constructor
A new instance of Instance.
- #running? ⇒ Boolean
- #ssh(command = nil) ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #tail_log(since = nil) ⇒ Object
Constructor Details
#initialize(application, n, container) ⇒ Instance
Returns a new instance of Instance.
178 179 180 181 182 |
# File 'lib/jarl/application.rb', line 178 def initialize(application, n, container) @application = application @n = n @container = container end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
172 173 174 |
# File 'lib/jarl/application.rb', line 172 def application @application end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
172 173 174 |
# File 'lib/jarl/application.rb', line 172 def container @container end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
172 173 174 |
# File 'lib/jarl/application.rb', line 172 def n @n end |
Instance Method Details
#full_name ⇒ Object
188 189 190 |
# File 'lib/jarl/application.rb', line 188 def full_name n ? "#{application.full_name}.#{n}" : application.full_name end |
#hostname ⇒ Object
192 193 194 |
# File 'lib/jarl/application.rb', line 192 def hostname n ? "#{application.hostname}-#{n}" : application.hostname end |
#running? ⇒ Boolean
184 185 186 |
# File 'lib/jarl/application.rb', line 184 def running? !@container.nil? end |
#ssh(command = nil) ⇒ Object
236 237 238 239 |
# File 'lib/jarl/application.rb', line 236 def ssh(command = nil) fail "Failed to open SSH, no running container for '#{full_name}'" unless running? container.open_ssh_session!(Jarl.config.params, command) end |
#start! ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/jarl/application.rb', line 201 def start! return if running? # puts esc_yellow("Starting #{application.name}.#{n}") if n Docker.start( name: full_name, hostname: hostname, image: application.image_name, volumes: application.volumes, ports: application.ports, environment: application.environment, command: application.command, logging: application.logging ) end |
#stop! ⇒ Object
196 197 198 199 |
# File 'lib/jarl/application.rb', line 196 def stop! return unless running? @container.stop! end |
#tail_log(since = nil) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/jarl/application.rb', line 217 def tail_log(since = nil) return unless running? color_code = Console::Colors::SEQUENCE[application.serial % Console::Colors::SEQUENCE.size] begin cmd = "docker logs #{since ? "--since #{since}" : nil} -f #{container.id}" IO.popen(cmd, 'r', external_encoding: Encoding::UTF_8) do |p| str = '<<< STARTED >>>' while str str = p.gets str.split("\n").each do |s| puts "#{esc_color color_code, full_name}: #{s}" end end end rescue Interrupt # end end |