Class: ImageServer::Spawner
- Inherits:
-
Object
- Object
- ImageServer::Spawner
- Defined in:
- lib/image_server/spawner.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#server ⇒ Object
Returns the value of attribute server.
-
#started ⇒ Object
Returns the value of attribute started.
Instance Method Summary collapse
- #give_feedback ⇒ Object
-
#initialize(configuration: ImageServer.configuration) ⇒ Spawner
constructor
A new instance of Spawner.
- #kill_at_exit ⇒ Object
- #seconds ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #starting ⇒ Object
Constructor Details
#initialize(configuration: ImageServer.configuration) ⇒ Spawner
Returns a new instance of Spawner.
8 9 10 |
# File 'lib/image_server/spawner.rb', line 8 def initialize(configuration: ImageServer.configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/image_server/spawner.rb', line 6 def configuration @configuration end |
#pid ⇒ Object
Returns the value of attribute pid.
6 7 8 |
# File 'lib/image_server/spawner.rb', line 6 def pid @pid end |
#server ⇒ Object
Returns the value of attribute server.
6 7 8 |
# File 'lib/image_server/spawner.rb', line 6 def server @server end |
#started ⇒ Object
Returns the value of attribute started.
6 7 8 |
# File 'lib/image_server/spawner.rb', line 6 def started @started end |
Instance Method Details
#give_feedback ⇒ Object
40 41 42 43 |
# File 'lib/image_server/spawner.rb', line 40 def give_feedback logger.info("image server is starting on port #{configuration.port}...") while starting logger.info "image server took #{seconds} seconds to start" end |
#kill_at_exit ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/image_server/spawner.rb', line 31 def kill_at_exit at_exit do if pid logger.info 'image server is stopping' `pkill -TERM -P #{pid}` # also stops child processes end end end |
#seconds ⇒ Object
45 46 47 |
# File 'lib/image_server/spawner.rb', line 45 def seconds '%.3f' % (Time.now - started) end |
#start ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/image_server/spawner.rb', line 12 def start unless started? self.started = Time.now self.pid = fork do $stderr.reopen('/dev/null') $stdout.reopen('/dev/null') server_exec.run end kill_at_exit give_feedback end end |
#started? ⇒ Boolean
25 26 27 28 29 |
# File 'lib/image_server/spawner.rb', line 25 def started? Net::HTTP.get_response(URI.parse("#{configuration.upload_host}:#{configuration.port}/status_check")) rescue StandardError nil end |
#starting ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/image_server/spawner.rb', line 49 def starting response = started? return false unless response raise 'Unable to start image server' unless response.kind_of?(Net::HTTPSuccess) false rescue Errno::ECONNREFUSED true end |