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(*_args) ⇒ Object
Constructor Details
#initialize(application, n, container) ⇒ Instance
Returns a new instance of Instance.
166 167 168 169 170 |
# File 'lib/jarl/application.rb', line 166 def initialize(application, n, container) @application = application @n = n @container = container end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
160 161 162 |
# File 'lib/jarl/application.rb', line 160 def application @application end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
160 161 162 |
# File 'lib/jarl/application.rb', line 160 def container @container end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
160 161 162 |
# File 'lib/jarl/application.rb', line 160 def n @n end |
Instance Method Details
#full_name ⇒ Object
176 177 178 |
# File 'lib/jarl/application.rb', line 176 def full_name n ? "#{application.full_name}.#{n}" : application.full_name end |
#hostname ⇒ Object
180 181 182 |
# File 'lib/jarl/application.rb', line 180 def hostname n ? "#{application.hostname}-#{n}" : application.hostname end |
#running? ⇒ Boolean
172 173 174 |
# File 'lib/jarl/application.rb', line 172 def running? !@container.nil? end |
#ssh(command = nil) ⇒ Object
222 223 224 225 |
# File 'lib/jarl/application.rb', line 222 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
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/jarl/application.rb', line 189 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 ) end |
#stop! ⇒ Object
184 185 186 187 |
# File 'lib/jarl/application.rb', line 184 def stop! return unless running? @container.stop! end |
#tail_log(*_args) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/jarl/application.rb', line 204 def tail_log(*_args) return unless running? color_code = Console::Colors::SEQUENCE[application.serial % Console::Colors::SEQUENCE.size] begin IO.popen "docker logs -f #{container.id}", 'r' 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 |