Permalink
Browse files

Wait until Cassandra starts listening.

  • Loading branch information...
jarib committed Oct 19, 2012
1 parent 21c6630 commit ab97de3ee4d7e2ac440cf541c9d60b2285dfcb58
Showing with 22 additions and 1 deletion.
  1. +22 −1 Rakefile
View
@@ -78,18 +78,39 @@ def running?(pid_file = nil)
false
end
+def listening?(host, port)
+ TCPSocket.new(host, port).close
+ true
+rescue Errno::ECONNREFUSED => e
+ false
+end
+
namespace :cassandra do
desc "Start Cassandra"
task :start, [:daemonize] => :java do |t, args|
args.with_defaults(:daemonize => true)
setup_cassandra_version
-
env = setup_environment
Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
sh("env #{env} bin/cassandra #{'-f' unless args.daemonize} -p #{CASSANDRA_PIDFILE}")
end
+
+ if args.daemonize
+ end_time = Time.now + 30
+ host = '127.0.0.1'
+ port = 9160
+
+ until Time.now >= end_time || listening?(host, port)
+ puts "waiting for 127.0.0.1:9160"
+ sleep 0.1
+ end
+
+ unless listening?(host, port)
+ raise "timed out waiting for cassandra to start"
+ end
+ end
end
desc "Stop Cassandra"

0 comments on commit ab97de3

Please sign in to comment.