-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkhmcctl
More file actions
executable file
·157 lines (136 loc) · 2.94 KB
/
khmcctl
File metadata and controls
executable file
·157 lines (136 loc) · 2.94 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
set -x
function usage
{
echo "$0 [-d dir] ['print ip' | 'print id' | 'verbose' | 'deverbose' | 'restart']"
echo " -d memcinfo directory"
echo " -n mcnetid directory"
echo "default command is 'print ip'"
}
function verbose
{
MCLIST=${MCSERVERS},
if [[ $1 = 1 ]]
then
MCCONF=memcached.conf.verbose
else
MCCONF=memcached.conf.normal
fi
while $(echo $MCLIST | grep ',' &> /dev/null)
do
MCS=${MCLIST%%\,*}
$(ssh -q -i $MEMCINFODIR/ids/id_dsa root@$MCS cp $MCCONF memcached.conf 2>&1 > /dev/null) && echo -n . &
MCLIST=${MCLIST#*\,}
done
wait
echo done
}
function restart
{
MCLIST=${MCSERVERS},
while $(echo $MCLIST | grep ',' &> /dev/null)
do
MCS=${MCLIST%%\,*}
$(ssh -q -i $MEMCINFODIR/ids/id_dsa root@$MCS /root/memcached restart 2>&1 > /dev/null) && echo -n . &
MCLIST=${MCLIST#*\,}
done
wait
echo done
}
origargs="$@"
optcount=0
while getopts "d:n:h" OPT
do
case $OPT in
("d") MEMCINFODIR="$OPTARG"; (( optcount=optcount + 2));;
("n") MCNETID="$OPTARG"; (( optcount=optcount + 2));;
("h") usage; exit -1;;
esac
done
shift $optcount
if [[ -z $KHROOT ]]
then
KHROOT=$HOME/khroot
fi
APPDIR=$KHROOT/appliances/memcapp
if [[ -z $MEMCINFODIR ]]
then
if [[ -z $khctlserver ]]
then
if [[ -a /proc/device-tree/u-boot-env/khctleth0ipaddr ]]
then
khctlserver=$(cat /proc/device-tree/u-boot-env/khctleth0ipaddr)
MEMCINFODIR=$APPDIR/memcinfo${khctlserver##*.}
else
echo "ERROR: khctlserver is not set" >&2
exit -1
fi
fi
fi
if [[ ! -d $MEMCINFODIR ]]
then
if [[ ! -h $MEMCINFODIR || ! -d $(readlink $MEMCINFODIR) ]]
then
if [[ ! -e $MEMCINFODIR ]]
then
mkdir $MEMCINFODIR
else
echo "ERROR: $MEMCINFODIR is not a directory" >&2
exit -1
fi
fi
fi
COMMAND=$1
if [[ -z $COMMAND ]]
then
COMMAND="print ip"
fi
if [[ -z $MCNETID && -f /proc/device-tree/u-boot-env/bg_eth2_netid ]]
then
MCNETID=$(cat /proc/device-tree/u-boot-env/bg_eth2_netid)
fi
infofiles=$(find $MEMCINFODIR/ -name memc-\*.info -type f)
for f in $infofiles
do
netidvalid=1
while read line
do
if [[ $netidvalid = 0 ]]
then
continue
fi
if [[ "$line" =~ "^network.*: .*" ]]
then
netid=${line%% :*}
netid=${netid#* }
if [[ -z $MCNETID ]]
then
MCNETID=$netid
else
if [[ $MCNETID != $netid ]]
then
netidvalid=0
continue
else
netidvalid=1
fi
fi
fi
if [[ "$line" =~ "^nodeinfo: .*" ]]
then
ip=${line##*: }
ip=${ip##* }
ip=${ip%% *}
MCSERVERS=${MCSERVERS},$ip
fi
done < $f
done
export MCSERVERS=${MCSERVERS#,}
case $COMMAND in
("print ip") echo $MCSERVERS;;
("print id") echo $MCNETID;;
("verbose") verbose 1;;
("deverbose") verbose 0;;
("restart") restart; ;;
("") echo $MCSERVERS;;
esac