Skip to content

Commit

Permalink
added output_dir, rather than just output to current directory, much …
Browse files Browse the repository at this point in the history
…nicer
  • Loading branch information
phunt committed Aug 7, 2009
1 parent 03fff56 commit 8706964
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
16 changes: 7 additions & 9 deletions README.textile
@@ -1,6 +1,6 @@
h1. Generate configuration for ZooKeeper ensemble

http://hadoop.apache.org/zookeeper/
"http://hadoop.apache.org/zookeeper/":http://hadoop.apache.org/zookeeper/

h2. Summary

Expand All @@ -9,7 +9,7 @@ zkconf.py will generate all of the configuration needed to run a ZooKeeper ensem
h2. Requirements

* Python
* Cheetah templating package are necessary to run this
* "Cheetah":http://www.cheetahtemplate.org templating package are necessary to run this
** On ubuntu "sudo apt-get install python-cheetah"

before using the first time (or on update) run the following command
Expand All @@ -18,17 +18,17 @@ cheetah compile *.tmpl

h2. Usage

zkconf.py [options] zookeeper_trunk_dir
zkconf.py [options] zookeeper_dir output_dir

Where zookeeper_dir is the location of your ZooKeeper trunk (zkconf copies the jars/confs from this directory into the output_dir to make your life easier). And output_dir is the directory to which we will output the generated files (assumption is that this is a non-existent directory - ie zkconf will create it)

example of typical use; 9 server quorum:

bq. zkconf.py --count 9 ~/zookeeper_trunk
bq. zkconf.py --count 9 ~/zookeeper_trunk test9servers

example of using weights/groups (only for flex quorum, not typical); 9 servers with 3 groups

bq. zkconf.py -c 9 --weights="1,1,1,1,1,0,0,0,0" --groups="1:2:3:4:5,6:7,8:9" ~/dev/workspace/gitzk

typically you want to create a new subdir, cd into that subdir, then run zkconf.py -- why? because the generated dirs/files are output the the current directory
bq. zkconf.py -c 9 --weights="1,1,1,1,1,0,0,0,0" --groups="1:2:3:4:5,6:7,8:9" ~/dev/workspace/gitzk testflexquroum

Options:
-h, --help show this help message and exit
Expand All @@ -44,8 +44,6 @@ Options:
quorum only)
--groups=GROUPS comma separated list of groups (flex quorum only)

where zookeeper_trunk_dir is the location of your zookeeper trunk - necessary as the source for jars/conf files

start.sh - start the ensemble (logs are output to the respective server subdir)
stop.sh - stop the ensemble
cli.sh "server:port,server:port,..." - open a client to the server list
Expand Down
31 changes: 18 additions & 13 deletions zkconf.py
Expand Up @@ -10,7 +10,7 @@
from start import start
from stop import stop

usage = "usage: %prog [options] zookeeper_trunk_dir"
usage = "usage: %prog [options] zookeeper_dir output_dir"
parser = OptionParser(usage=usage)
parser.add_option("-c", "--count", dest="count",
default="3", help="ensemble size")
Expand Down Expand Up @@ -42,10 +42,12 @@
else :
options.groups = []

if len(args) != 1:
parser.error("need zookeeper_trunk_dir in order to get jars and conf")
if len(args) != 2:
parser.error("need zookeeper_dir in order to get jars/conf, and output_dir for where to put generated")

if __name__ == '__main__':
os.mkdir(args[1])

serverlist = []
for sid in xrange(1, options.count + 1) :
serverlist.append([sid,
Expand All @@ -54,7 +56,7 @@
options.electionportstart + sid])

for sid in xrange(1, options.count + 1) :
serverdir = "s" + str(sid)
serverdir = os.path.join(args[1], "s" + str(sid))
os.mkdir(serverdir)
os.mkdir(os.path.join(serverdir, "data"))
conf = zoocfg(searchList=[{'sid' : sid,
Expand All @@ -70,21 +72,24 @@
f.write(str(sid))
f.close()

f = open("start.sh", 'w')
startcmd = os.path.join(args[1], "start.sh")
f = open(startcmd, 'w')
f.write(str(start(searchList=[{'serverlist' : serverlist}])))
f.close()
os.chmod("start.sh", 0755)
os.chmod(startcmd, 0755)

f = open("stop.sh", 'w')
stopcmd = os.path.join(args[1], "stop.sh")
f = open(stopcmd, 'w')
f.write(str(stop(searchList=[{'serverlist' : serverlist}])))
f.close()
os.chmod("stop.sh", 0755)
os.chmod(stopcmd, 0755)

shutil.copyfile(os.path.join(args[0], "src", "java", "lib", "log4j-1.2.15.jar"), "log4j.jar")
shutil.copyfile(os.path.join(args[0], "conf", "log4j.properties"), "log4j.properties")
shutil.copyfile(os.path.join(args[0], "zookeeper-dev.jar"), "zookeeper.jar")
shutil.copyfile(os.path.join(args[0], "src", "java", "lib", "log4j-1.2.15.jar"), os.path.join(args[1], "log4j.jar"))
shutil.copyfile(os.path.join(args[0], "conf", "log4j.properties"), os.path.join(args[1], "log4j.properties"))
shutil.copyfile(os.path.join(args[0], "zookeeper-dev.jar"), os.path.join(args[1], "zookeeper.jar"))

f = open("cli.sh", 'w')
clicmd = os.path.join(args[1], "cli.sh")
f = open(clicmd, 'w')
f.write('java -cp zookeeper.jar:log4j.jar:. org.apache.zookeeper.ZooKeeperMain -server $1')
f.close()
os.chmod("cli.sh", 0755)
os.chmod(clicmd, 0755)

0 comments on commit 8706964

Please sign in to comment.