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 14 |
# File 'lib/http_server_manager/server.rb', line 7 def initialize() @name = [:name] @host = [:host] @port = [:port] @ping_uri = [:ping_uri] || "/" @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
51 52 53 |
# File 'lib/http_server_manager/server.rb', line 51 def logger HttpServerManager.logger end |
#restart! ⇒ Object
38 39 40 41 |
# File 'lib/http_server_manager/server.rb', line 38 def restart! stop! start! end |
#start! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/http_server_manager/server.rb', line 16 def start! if running? logger.info "#{@name} already running on #{@host}:#{@port}" else ensure_directories_exist pid = Process.spawn(start_command, %i{ 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
43 44 45 |
# File 'lib/http_server_manager/server.rb', line 43 def status running? ? :started : :stopped end |
#stop! ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/http_server_manager/server.rb', line 28 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
47 48 49 |
# File 'lib/http_server_manager/server.rb', line 47 def to_s "#{@name} on #{@host}:#{@port}" end |