-
Notifications
You must be signed in to change notification settings - Fork 0
/
zookeeper-cdh3.rb
128 lines (107 loc) · 3.62 KB
/
zookeeper-cdh3.rb
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require 'formula'
class ZookeeperCdh3 < Formula
homepage 'http://zookeeper.apache.org/'
url 'http://archive.cloudera.com/cdh/3/zookeeper-3.3.5-cdh3u5.tar.gz'
sha1 '609acae3f4c5cdb0af9082673ec37643abf9935e'
head 'http://svn.apache.org/repos/asf/zookeeper/trunk'
if build.head?
depends_on :automake
depends_on :libtool
end
option "c", "Build C bindings."
option "perl", "Build Perl bindings."
option "python", "Build Python bindings."
def shim_script target
<<-EOS.undent
#!/usr/bin/env bash
. "#{etc}/zookeeper/defaults"
cd "#{libexec}/bin"
./#{target} "$@"
EOS
end
def default_zk_env
<<-EOS.undent
export ZOOCFGDIR="#{etc}/zookeeper"
EOS
end
def default_log4j_properties
<<-EOS.undent
log4j.rootCategory=WARN, zklog
log4j.appender.zklog = org.apache.log4j.FileAppender
log4j.appender.zklog.File = #{var}/log/zookeeper/zookeeper.log
log4j.appender.zklog.Append = true
log4j.appender.zklog.layout = org.apache.log4j.PatternLayout
log4j.appender.zklog.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
EOS
end
def install
# Don't try to build extensions for PPC
if Hardware.is_32_bit?
ENV['ARCHFLAGS'] = "-arch i386"
else
ENV['ARCHFLAGS'] = "-arch i386 -arch x86_64"
end
# Prep work for svn compile.
if build.head?
system "ant", "compile_jute"
cd "src/c" do
system "autoreconf", "-if"
end
end
build_python = build.include? "python"
build_perl = build.include? "perl"
build_c = build_python || build_perl || build.include?("c")
# Build & install C libraries.
cd "src/c" do
system "./configure", "--disable-dependency-tracking",
"--prefix=#{prefix}",
"--without-cppunit"
system "make install"
end if build_c
# Install Python bindings
cd "src/contrib/zkpython" do
system "python", "src/python/setup.py", "build"
system "python", "src/python/setup.py", "install", "--prefix=#{prefix}"
end if build_python
# Install Perl bindings
cd "src/contrib/zkperl" do
system "perl", "Makefile.PL", "PREFIX=#{prefix}",
"--zookeeper-include=#{include}/c-client-src",
"--zookeeper-lib=#{lib}"
system "make install"
end if build_perl
# Remove windows executables
rm_f Dir["bin/*.cmd"]
# Install Java stuff
if build.head?
system "ant"
libexec.install %w(bin src/contrib src/java/lib)
libexec.install Dir['build/*.jar']
else
libexec.install %w(bin contrib lib)
libexec.install Dir['*.jar']
end
# Create necessary directories
bin.mkpath
(etc+'zookeeper').mkpath
(var+'log/zookeeper').mkpath
(var+'run/zookeeper/data').mkpath
# Install shim scripts to bin
Dir["#{libexec}/bin/*.sh"].map { |p| Pathname.new p }.each { |path|
next if path == libexec+'bin/zkEnv.sh'
script_name = path.basename
bin_name = path.basename '.sh'
(bin+bin_name).write shim_script(script_name)
}
# Install default config files
defaults = etc/'zookeeper/defaults'
defaults.write(default_zk_env) unless defaults.exist?
log4j_properties = etc/'zookeeper/log4j.properties'
log4j_properties.write(default_log4j_properties) unless log4j_properties.exist?
unless (etc/'zookeeper/zoo.cfg').exist?
inreplace 'conf/zoo_sample.cfg',
/^dataDir=.*/, "dataDir=#{var}/run/zookeeper/data"
(etc/'zookeeper').install 'conf/zoo_sample.cfg'
end
end
end