Class: Rackdapter::ApplicationInstance
- Inherits:
-
Object
- Object
- Rackdapter::ApplicationInstance
- Defined in:
- lib/rackdapter/spawner.rb
Instance Method Summary collapse
- #ensure_running ⇒ Object
-
#initialize(application, port) ⇒ ApplicationInstance
constructor
A new instance of ApplicationInstance.
- #restart ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(application, port) ⇒ ApplicationInstance
Returns a new instance of ApplicationInstance.
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rackdapter/spawner.rb', line 103 def initialize(application, port) @application = application @port = port @backend = case @application.type when "merb" MerbBackend when "rails" RailsBackend when "proxy" ProxyBackend end end |
Instance Method Details
#ensure_running ⇒ Object
116 117 118 |
# File 'lib/rackdapter/spawner.rb', line 116 def ensure_running start end |
#restart ⇒ Object
141 142 143 144 145 |
# File 'lib/rackdapter/spawner.rb', line 141 def restart puts "Initiating restart of #{@application.name}:#{@port}" stop start end |
#running? ⇒ Boolean
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rackdapter/spawner.rb', line 147 def running? return false unless @pid found = false `ps`.each_line do |line| if line =~ /^ *(#{@pid}) / found = true break end end found end |
#start ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/rackdapter/spawner.rb', line 120 def start return if running? @pid = fork do @backend.spawn(@application, @port) end puts "Starting #{@application.name}:#{@port} with pid #{@pid}" Process.detach(@pid) end |
#stop ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rackdapter/spawner.rb', line 129 def stop if running? puts "Stopping #{@application.name}:#{@port}" begin Process.kill("TERM", @pid) rescue puts "Process #{@pid} not found" end @pid = nil end end |