|
|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ZOOBIN="${BASH_SOURCE-$0}" |
|
|
ZOOBIN="$(dirname "${ZOOBIN}")" |
|
|
ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)" |
|
|
|
|
|
if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then |
|
|
. "$ZOOBINDIR"/../libexec/zkEnv.sh |
|
|
else |
|
|
. "$ZOOBINDIR"/zkEnv.sh |
|
|
fi |
|
|
|
|
|
usage() { |
|
|
|
|
|
|
|
|
|
|
|
printf "usage: $0 <parameters> |
|
|
Optional parameters: |
|
|
-h Display this message |
|
|
--help Display this message |
|
|
--configfile=%-40s ZooKeeper config file |
|
|
--myid=# Set the myid to be used, if any (1-255) |
|
|
--force Force creation of the data/txnlog dirs |
|
|
" "$ZOOCFG" |
|
|
exit 1 |
|
|
} |
|
|
|
|
|
if [ $? != 0 ] ; then |
|
|
usage |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
initialize() { |
|
|
if [ ! -e "$ZOOCFG" ]; then |
|
|
echo "Unable to find config file at $ZOOCFG" |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
ZOO_DATADIR="$(grep "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')" |
|
|
ZOO_DATALOGDIR="$(grep "^[[:space:]]*dataLogDir" "$ZOOCFG" | sed -e 's/.*=//')" |
|
|
|
|
|
if [ -z "$ZOO_DATADIR" ]; then |
|
|
echo "Unable to determine dataDir from $ZOOCFG" |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
if [ $FORCE ]; then |
|
|
echo "Force enabled, data/txnlog directories will be re-initialized" |
|
|
else |
|
|
|
|
|
|
|
|
if [ -d "$ZOO_DATADIR/version-2" ]; then |
|
|
echo "ZooKeeper data directory already exists at $ZOO_DATADIR (or use --force to force re-initialization)" |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
if [ -n "$ZOO_DATALOGDIR" ] && [ -d "$ZOO_DATALOGDIR/version-2" ]; then |
|
|
echo "ZooKeeper txnlog directory already exists at $ZOO_DATALOGDIR (or use --force to force re-initialization)" |
|
|
exit 1 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rm -rf "$ZOO_DATADIR/myid" 2>/dev/null >/dev/null |
|
|
rm -rf "$ZOO_DATADIR/version-2" 2>/dev/null >/dev/null |
|
|
mkdir -p "$ZOO_DATADIR/version-2" |
|
|
|
|
|
if [ -n "$ZOO_DATALOGDIR" ]; then |
|
|
rm -rf "$ZOO_DATALOGDIR/myid" 2>/dev/null >/dev/null |
|
|
rm -rf "$ZOO_DATALOGDIR/version-2" 2>/dev/null >/dev/null |
|
|
mkdir -p "$ZOO_DATALOGDIR/version-2" |
|
|
fi |
|
|
|
|
|
if [ $MYID ]; then |
|
|
echo "Using myid of $MYID" |
|
|
echo $MYID > "$ZOO_DATADIR/myid" |
|
|
else |
|
|
echo "No myid provided, be sure to specify it in $ZOO_DATADIR/myid if using non-standalone" |
|
|
fi |
|
|
|
|
|
touch "$ZOO_DATADIR/initialize" |
|
|
} |
|
|
|
|
|
while [ ! -z "$1" ]; do |
|
|
case "$1" in |
|
|
--configfile) |
|
|
ZOOCFG=$2; shift 2 |
|
|
;; |
|
|
--configfile=?*) |
|
|
ZOOCFG=${1#*=}; shift 1 |
|
|
;; |
|
|
--myid) |
|
|
MYID=$2; shift 2 |
|
|
;; |
|
|
--myid=?*) |
|
|
MYID=${1#*=}; shift 1 |
|
|
;; |
|
|
--force) |
|
|
FORCE=1; shift 1 |
|
|
;; |
|
|
-h) |
|
|
usage |
|
|
;; |
|
|
--help) |
|
|
usage |
|
|
;; |
|
|
*) |
|
|
echo "Unknown option: $1" |
|
|
usage |
|
|
exit 1 |
|
|
;; |
|
|
esac |
|
|
done |
|
|
initialize |
|
|
|