relauncher.rb (run this)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# listen on 3000 server = TCPServer('localhost', 3000) # prepare initial mtime and child vm mtime = File('server.rb') vm = JRuby('server.rb') vm << JRuby while true # accept connections sock = server # check mtime and reload VM if changed new_mtime = File('server.rb') if mtime != new_mtime mtime = new_mtime vm << 'quit' t = Time vm = JRuby('server.rb') vm << JRuby puts "reloaded in seconds" end # handle request in child vm request = sock("\r\n\r\n") vm << request response = JRuby sock(response) sock end |
server.rb (touch to cause reload on next request)
1 2 3 4 5 6 7 8 9 10 11 |
parent_id = JRuby header = "HTTP/1.1 200 OK\r\nDate: Mon, 01 Dec 2008 01:52:09 GMT\r\nContent-Type: text/html\r\nConnection: close\r\n" while true request = JRuby break if request == 'quit' # just dumping request back at the moment response = "Content-Length: \r\n\r\n<pre></pre>" JRuby(parent_id, response) end |

