Class: Sunshine::Server
Overview
An abstract class to wrap simple server software setup and start/stop.
Child classes are expected to at least provide a start and stop bash script by either overloading the start_cmd and stop_cmd methods, or by setting may also be specified if restart requires more functionality than simply calling start_cmd && stop_cmd.
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server_name ⇒ Object
readonly
Returns the value of attribute server_name.
-
#sigkill ⇒ Object
Returns the value of attribute sigkill.
Attributes inherited from Daemon
#app, #bin, #config_file, #config_path, #config_template, #name, #pid, #processes, #restart_cmd, #server_apps, #start_cmd, #status_cmd, #sudo, #target, #timeout
Class Method Summary collapse
- .binder_methods ⇒ Object
-
.passenger_root(shell) ⇒ Object
Gets the root of the installer passenger gem.
Instance Method Summary collapse
-
#initialize(app, options = {}) ⇒ Server
constructor
Server objects need only an App object to be instantiated.
-
#setup ⇒ Object
Add passenger information to the binder at setup time.
-
#stop_cmd ⇒ Object
Default server stop command.
-
#supports_rack? ⇒ Boolean
Defines if this server supports interfacing with rack.
-
#use_passenger? ⇒ Boolean
Check if passenger is required to run the application.
Methods inherited from Daemon
#config_file_path, #config_template_files, #each_server_app, #has_setup?, #log_file, #log_files, #restart, #start, #stop, underscore, #upload_config_files
Constructor Details
#initialize(app, options = {}) ⇒ Server
Server objects need only an App object to be instantiated. All Daemon init options are supported plus the following:
- :port
-
port_num - the port to run the server on
defaults to 80
- :server_name
-
myserver.com - host name used by server
defaults to nil
By default, servers also assign the option :role => :web.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sunshine/daemons/server.rb', line 34 def initialize app, ={} [:role] ||= :web super app, @port = [:port] || 80 @server_name = [:server_name] @sigkill = 'QUIT' @supports_rack = false end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
19 20 21 |
# File 'lib/sunshine/daemons/server.rb', line 19 def port @port end |
#server_name ⇒ Object (readonly)
Returns the value of attribute server_name.
19 20 21 |
# File 'lib/sunshine/daemons/server.rb', line 19 def server_name @server_name end |
#sigkill ⇒ Object
Returns the value of attribute sigkill.
20 21 22 |
# File 'lib/sunshine/daemons/server.rb', line 20 def sigkill @sigkill end |
Class Method Details
.binder_methods ⇒ Object
14 15 16 |
# File 'lib/sunshine/daemons/server.rb', line 14 def self.binder_methods [:server_name, :port].concat super end |
.passenger_root(shell) ⇒ Object
Gets the root of the installer passenger gem.
58 59 60 61 62 63 64 65 66 |
# File 'lib/sunshine/daemons/server.rb', line 58 def self.passenger_root shell str = shell.call "gem list passenger -d" version = $1 if str =~ /passenger\s\((.*)\)$/ gempath = $1 if str =~ /Installed\sat:\s(.*)$/ return unless version && gempath File.join(gempath, "gems/passenger-#{version}") end |
Instance Method Details
#setup ⇒ Object
Add passenger information to the binder at setup time.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sunshine/daemons/server.rb', line 72 def setup super do |server_app, binder| binder.forward :use_passenger? binder.set :passenger_root do Server.passenger_root server_app.shell end yield(server_app, binder) if block_given? end end |
#stop_cmd ⇒ Object
Default server stop command.
89 90 91 92 |
# File 'lib/sunshine/daemons/server.rb', line 89 def stop_cmd "test -f #{@pid} && kill -#{@sigkill} $(cat #{@pid}) && sleep 1 && "+ "rm -f #{@pid} || echo 'No #{@name} process to stop for #{@app.name}';" end |
#supports_rack? ⇒ Boolean
Defines if this server supports interfacing with rack.
98 99 100 |
# File 'lib/sunshine/daemons/server.rb', line 98 def supports_rack? @supports_rack end |