Skip to content

Instantly share code, notes, and snippets.

@hSATAC
Created October 2, 2014 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hSATAC/ffbf9065b498fdb1ff60 to your computer and use it in GitHub Desktop.
Save hSATAC/ffbf9065b498fdb1ff60 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
require "rubygems"
require "net/http"
require "socket"
SOCKET_PATH = '/Users/cat/kkbox/kktix/unicorn.sock'
def unicorn_ready
return false unless File.exist? SOCKET_PATH
return true if unicorn_return.to_i == 200
end
def unicorn_return
sock = Net::BufferedIO.new(UNIXSocket.new(SOCKET_PATH))
request = Net::HTTP::Get.new("/")
request.exec(sock, "1.1", "/")
begin
response = Net::HTTPResponse.read_new(sock)
end while response.kind_of?(Net::HTTPContinue)
response.reading_body(sock, request.response_body_permitted?) { }
response.code
end
puts "Waiting for unicorn_rails..."
(sleep 1; print ".") until unicorn_ready
`/etc/init.d/nginx start`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment