-
Notifications
You must be signed in to change notification settings - Fork 12
/
zk-config
executable file
·68 lines (62 loc) · 1.47 KB
/
zk-config
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
#!/bin/bash
HOSTNAME=`hostname`
IFS=" "
IPS=`hostname -i`
echo "HOSTNAME==>$HOSTNAME";
echo "IPS==>$IPS";
read -r -a IP_ADDRESSES <<< "$IPS"
ZK_CONF_DIR="/config"
ZK_CONF_FILE="zoo.cfg"
MYID_REGEX="\\.([0-9]{1,3})="
function extractMyId {
if [[ $1 =~ $MYID_REGEX ]]
then
echo "${BASH_REMATCH[1]}"
else
echo "NaN"
fi
}
while read line
do
if [[ $line = dataDir=* ]];
then
IFS="="
read -r key ZK_DATADIR <<< "$line"
[[ -d "$ZK_DATADIR" ]] || mkdir -p "$ZK_DATADIR"
fi
if [[ $line = dynamicConfigFile=* ]];
then
IFS="="
read -r key ZK_DYNAMIC_CONFIG_FILE <<< "$line"
fi
done < "$ZK_CONF_DIR/$ZK_CONF_FILE"
#echo "ZK_DATADIR:$ZK_DATADIR";
#echo "ZK_DYNAMIC_CONFIG_FILE:$ZK_DYNAMIC_CONFIG_FILE";
#echo "HOSTNAME:$HOSTNAME"
#echo "IPS:$IPS"
if [ ! -f "$ZK_DATADIR/myid" ]; then
while read line
do
echo "READING CONFIGLINE: $line"
if [[ $line == *"$HOSTNAME"* ]];
then
MYID=`extractMyId "$line"`;
echo $MYID >> "$ZK_DATADIR/myid"
echo "Writing myid $MYID to $ZK_DATADIR/myid"
break;
else
#for ip in `ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`
for ip in ${IP_ADDRESSES[@]}
do
if [[ $line == *"$ip"* ]];
then
MYID=`extractMyId "$line"`;
echo $MYID >> "$ZK_DATADIR/myid"
echo "Writing myid $MYID to $ZK_DATADIR/myid"
break;
fi
done
fi
done < "$ZK_DYNAMIC_CONFIG_FILE"
fi
exit 0