-
Notifications
You must be signed in to change notification settings - Fork 3
/
khmcapp
executable file
·273 lines (234 loc) · 6.8 KB
/
khmcapp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/bash
set -x
function setfdtdate
{
local now=$(date -u)
local year=$(date -u -d "$now" +"%-Y")
local fdtdate="$(printf 'fdt mknode / rtc && fdt set /rtc second "[00 00 00 %02x]" && fdt set /rtc minute "[00 00 00 %02x]" && fdt set /rtc hour "[00 00 00 %02x]" && fdt set /rtc month "[00 00 00 %02x]" && fdt set /rtc mday "[00 00 00 %02x]" && fdt set /rtc year "[00 00 %02x %02x]"\n' `date -u -d "$now" +"%-S %-M %-H %-m %-d"` $(( $year / 256 )) $(( $year % 256 )))"
echo "$1" | khdo write "$fdtdate"
return 1;
}
function interactive
{
if [[ -n $INTERACTIVE ]]
then
message="$1 ... Press <enter> ..."
echo $message
read
fi
}
function usage
{
echo "$0 [-i] [-w] [-L] [-n] [-m number] [-c count] [ -r KHROOT ] [-u username] [-d path] [-p preload] [-P preloadno] [-s seed]"
echo " -i interactive mode"
echo " -w no windows"
echo " -L start up login windows at end of non-interactive mode even if -w specified"
echo " -n netid of existing memcached servers"
echo " -m number of new memcached servers"
echo " -c number of aoe clients"
echo " -r khroot directory"
echo " -u user"
echo " -p preload NFS disk"
echo " -P number of expected disk clients (refcnt)"
echo " -s disk seed"
}
origargs="$@"
optcount=0
export MCPRELOADNO=1
while getopts "iwpP:n:m:c:u:r:s:h" OPT
do
case $OPT in
("i") export INTERACTIVE=1; (( optcount=optcount + 1));;
("w") export NOWINDOWS=1; (( optcount=optcount + 1));;
("p") export MCPRELOAD=1; (( optcount=optcount + 1));;
("P") export MCPRELOADNO="$OPTARG"; (( optcount=optcount + 2));;
("n") export MCNETID="$OPTARG"; (( optcount=optcount + 2));;
("m") export NUMMEMC="$OPTARG"; (( optcount=optcount + 2));;
("c") export NUM="$OPTARG"; (( optcount=optcount + 2));;
("u") export KHUSER="$OPTARG"; (( optcount=optcount + 2));;
("r") export KHROOT="$OPTARG"; (( optcount=optcount + 2));;
("s") export MCSEED="$OPTARG"; (( optcount=optcount + 2));;
("h") usage; exit -1;;
esac
done
shift $optcount
COMMAND=$1
if [[ -z $COMMAND ]]
then
COMMAND="plain"
fi
if [[ -z $KHROOT ]]
then
KHROOT=$HOME/khroot
fi
if [[ -z $KHUSER ]]
then
KHUSER=$USER
fi
if [[ -z $NUM ]]
then
NUM=1
fi
APPDIR=$KHROOT/appliances/memcapp
MCFSSERVER=$USER@172.17.3.12
MCFSPATH=$APPDIR
MCFSTYPE=ssh
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
MEMCINFODIR=$APPDIR/memcinfo${khctlserver##*.}
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
if [[ -n $NOWINDOWS ]]
then
# no windows implies not being interactive
unset INTERACTIVE
fi
IDFILE=$APPDIR/id_dsa
if [[ $COMMAND = "bench" ]]
then
MEMCBENCHCONF=$MEMCINFODIR/memcbench.conf
if [[ ! -a $MEMCBENCHCONF ]]
then
echo "ERROR: config file for memcbench does not exist"
exit 0
fi
if [[ -z $(cat $MEMCBENCHCONF | grep slap) ]]
then
APPKERN=$APPDIR/memcapp-uImage
BIGPHYS=384
else
APPKERN=$APPDIR/memcappbench-uImage
BIGPHYS=650
echo Using special kernel with lots of bigphys...
fi
else
APPKERN=$APPDIR/memcapp-uImage
fi
APPIMG=$APPDIR/memcapp.gz.uimg
if [[ ! -a $IDFILE ]]
then
echo "ERROR: $IDFILE does not exist"
exit 0
fi
if [[ ! -a $APPKERN ]]
then
echo "ERROR: $APPKERN does not exist"
exit 0
fi
if [[ ! -a $APPIMG ]]
then
echo "ERROR: $APPIMG does not exist"
exit 0
fi
interactive "To start by acquiring memcached nodes"
if [[ -n $NUMMEMC ]]
then
whenout=/tmp/$KHUSER.$$.wout
if [[ -z $MCNETID ]]
then
mcs=$(khgetmc -w -u $KHUSER -c $NUMMEMC)
MCNETID=$(echo "$mcs" | khdo pernetcmd "echo %if% %net%" | grep eth0)
MCNETID=${MCNETID##* }
else
mcs=$(khgetmc -n $MCNETID -u $KHUSER -c $NUMMEMC)
fi
if [[ -z $mcs ]]
then
echo "ERROR: failed to acquire $NUM nodes for memcached servers" >&2
exit -1
fi
when "bash-3.1# " /dev/null ssh $mcscon> $whenout &
wpid=$(jobs -p %%)
sleep 0.5
if [[ -z $NOWINDOWS ]]
then
echo "$mcs" | khdo concmd "khxcon -s "mc$COMMAND${khctlserver##*.}" %con% \"-geometry 80x8+0+10\" &"
fi
fi
if [[ -z $MCNETID ]]
then
MCNETID=$(khmcctl -d $MEMCINFODIR "print id")
if [[ -z $MCNETID ]]
then
echo Unspecified list of memcached servers.
exit 1
fi
fi
MCSERVERS=$(khmcctl -d $MEMCINFODIR -n $MCNETID )
if [[ -z $MCSERVERS ]]
then
echo Unspecified list of memcached servers.
exit 1
fi
interactive "To start by acquiring app nodes"
whenout=/tmp/$KHUSER.$$.wout
app=$(khget -x -i -n $MCNETID $KHUSER $NUM)
appcon=$(echo "$app" | khdo concmd "echo %con%")
echo "APP INFO: $app" >&2
echo "$app" | khdo loadkernel $APPKERN
echo "$app" | khdo loadramdisk $APPIMG
echo "$app" | khdo write 'setenv eth1 "$iip $imask" && setenv eth2 "$p0ip $p0mask"'
echo "$app" | khdo write "setenv mc_iface eth2"
echo "$app" | khdo write "setenv mc_fstype $MCFSTYPE"
echo "$app" | khdo write "setenv mc_fsserver $MCFSSERVER"
echo "$app" | khdo write "setenv mc_fspath $MCFSPATH"
echo "$app" | khdo write "setenv mc_infodir memcinfo${khctlserver##*.}"
echo "$app" | khdo write "setenv mc_servers $MCSERVERS"
echo "$app" | khdo write "setenv mc_preloadno $MCPRELOADNO"
echo "$app" | khdo write "setenv mc_seed $MCSEED"
case $COMMAND in
("udpsync")
echo "$app" | khdo write "setenv mc_udpsync 1"
;;
("kcompile") echo "$app" | khdo write "setenv mc_kcompile 1" ;;
("chroot") echo "$app" | khdo write "setenv mc_chroot 1" ;;
("bench")
echo "$app" | khdo write "setenv mc_bench 1"
echo "$app" | khdo write "setenv mc_bsyncs $UDPSYNCSERVER"
#echo "$app" | khdo write "setenv mc_bbuffer 1"
while read LINE
do
echo "$app" | khdo write "setenv $LINE"
done < $MEMCBENCHCONF ;;
("plain") echo "$app" | khdo write "setenv mc_plain 1" ;;
esac
if [[ -z $BIGPHYS ]]
then
export BIGPHYS=256
fi
setfdtdate "$app"
let BIGPHYS*=256
echo "$app" | khdo write "setenv bootargs root=/dev/ram0 rw bigphysarea=$BIGPHYS console=bgtty0,\$bgtty_sendid,\$bgtty_rcvid,\$bgtty_dest init=/init ip=\$eth0ip:\$serverip:\$sitegate:\$sitemask::eth0:off"
echo "$app" | khdo write 'setenv ramfsarg $ramfsaddr'
echo "$app" | khdo write "setenv mc_client 1"
echo "$app" | khdo write "run boot"
if [[ -z $INTERACTIVE ]]
then
wait $wpid
echo "$app" | khdo write "hostname APP-$KHUSER"
fi
if [[ -z $NOWINDOWS ]]
then
echo "$app" | khdo concmd -s "mc$COMMAND${khctlserver##*.}" "khxcon %con% \"-geometry 80x8+0+700\" &"
fi
echo "$app" > $MEMCINFODIR/mc$COMMAND${khctlserver##*.}