Class: HttpServerManager::Server
- Inherits:
-
Object
- Object
- HttpServerManager::Server
- Defined in:
- lib/http_server_manager/server.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(options) ⇒ Server
constructor
A new instance of Server.
- #logger ⇒ Object
- #restart! ⇒ Object
- #start! ⇒ Object
- #status ⇒ Object
- #stop! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options) ⇒ Server
Returns a new instance of Server.
7 8 9 10 11 12 13 |
# File 'lib/http_server_manager/server.rb', line 7 def initialize() @name = [:name] @host = [:host] @port = [:port] @timeout_in_seconds = [:timeout_in_seconds] || (ENV["timeout"] ? ENV["timeout"].to_i : 20) @deletable_artifacts = [ pid_file_path ] end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/http_server_manager/server.rb', line 5 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/http_server_manager/server.rb', line 5 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/http_server_manager/server.rb', line 5 def port @port end |
Instance Method Details
#logger ⇒ Object
50 51 52 |
# File 'lib/http_server_manager/server.rb', line 50 def logger HttpServerManager.logger end |
#restart! ⇒ Object
37 38 39 40 |
# File 'lib/http_server_manager/server.rb', line 37 def restart! stop! start! end |
#start! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/http_server_manager/server.rb', line 15 def start! if running? logger.info "#{@name} already running on #{@host}:#{@port}" else ensure_directories_exist pid = Process.spawn(start_command, [:out, :err] => [ log_file_path, "w" ]) create_pid_file(pid) Wait.until_true!(description: "#{@name} is running", timeout_in_seconds: @timeout_in_seconds) { running? } logger.info "#{@name} started on #{@host}:#{@port}" end end |
#status ⇒ Object
42 43 44 |
# File 'lib/http_server_manager/server.rb', line 42 def status running? ? :started : :stopped end |
#stop! ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/http_server_manager/server.rb', line 27 def stop! if running? Process.kill_tree(9, current_pid) FileUtils.rm_f(@deletable_artifacts) logger.info "#{@name} stopped" else logger.info "#{@name} not running" end end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/http_server_manager/server.rb', line 46 def to_s "#{@name} on #{@host}:#{@port}" end |