require 'rake/clean' namespace :zookeeper do ZK_VERSION = "3.3.3" ZK_TARBALL = "zookeeper-#{ZK_VERSION}.tar.gz" task :download => "tmp/#{ZK_TARBALL}" directory 'tmp' file "tmp/#{ZK_TARBALL}" => "tmp" do puts "*** Downloading Zookeeper" sh "curl http://archive.apache.org/dist/zookeeper/zookeeper-#{ZK_VERSION}/#{ZK_TARBALL} -o tmp/#{ZK_TARBALL}" end task :install => :download do puts "*** Unpacking Zookeeper" rm_rf "zookeeper" if File.exists? "zookeeper" sh "tar -zxvf tmp/#{ZK_TARBALL}" mv "zookeeper-#{ZK_VERSION}", "zookeeper" home = File.expand_path("../../zookeeper", __FILE__) # Create base configuration data = File.join(home, "data") mkdir_p data config = File.join(home, "conf", "zoo.cfg") rm_r File.join(home, "conf", "zoo_sample.cfg") File.open(config, "w") do |file| # Maybe some kind soul will move this ugly heredoc into a template file << <<-ZK_CONFIG # The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. dataDir=#{data} # the port at which the clients will connect clientPort=2181 ZK_CONFIG end end task :start => :zookeeper do puts "*** Starting Zookeeper" sh "cd zookeeper && bin/zkServer.sh start" end end file 'zookeeper' do Rake::Task['zookeeper:install'].invoke end CLEAN.include "tmp", "zookeeper"