-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkhgetmc
More file actions
executable file
·201 lines (167 loc) · 4.41 KB
/
khgetmc
File metadata and controls
executable file
·201 lines (167 loc) · 4.41 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
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
#!/bin/bash
set -x
# FIXME:
# there is big sequential loops here probably
# does not matter right now as aoe id's
# only range from {0..9} * {0..15}
export BIGPHYS=1200
function interactive
{
message="$1 ... Press <enter> ..."
echo $message
read
}
function usage
{
echo "$0 [-c <num>] [-r khroot] [-u user] [-n netid]"
echo " -w no windows"
echo " -c number"
echo " -r khroot directory"
echo " -u khuser"
echo " -n netid"
echo " -d do not delete old mcinfo files"
}
VERBOSITY=0
FETCHMEMCINFO=1
MCMINCS=1024
MCMAXCS=131072
MCFACTOR=16
origargs="$@"
optcount=0
while getopts "wn:u:r:c:ds:S:f:h" OPT
do
case $OPT in
("w") NOWINDOWS=1; (( optcount=optcount + 1));;
("n") MCNETID="$OPTARG"; (( optcount=optcount + 2));;
("u") KHUSER="$OPTARG"; (( optcount=optcount + 2));;
("r") KHROOT="$OPTARG"; (( optcount=optcount + 2));;
("c") NUM="$OPTARG"; (( optcount=optcount + 2));;
("d") NODELOLDMCINFO=1; (( optcount=optcount + 1));;
("s") MCMINCS="$OPTARG"; (( optcount=optcount + 1));;
("S") MCMAXCS="$OPTARG"; (( optcount=optcount + 1));;
("f") MCFACTOR="$OPTARG"; (( optcount=optcount + 1));;
("h") usage; exit -1;;
esac
done
let MCMINCS+=200
let MCMAXCS+=200
if [[ -z $KHROOT ]]
then
KHROOT=$HOME/khroot
fi
APPDIR=$KHROOT/appliances/memcapp
export PATH=$PATH:$KHROOT/scripts
if [[ -z $KHUSER ]]
then
if [[ -a /proc/device-tree/u-boot-env/khctluser ]]
then
KHUSER=$(cat /proc/device-tree/u-boot-env/khctluser)
else
KHUSER=$USER
fi
fi
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 [[ -z $NUM ]]
then
NUM=1
fi
MCKERN=$APPDIR/memcapp-uImage
MCAPP=$APPDIR/memcapp.gz.uimg
if [[ ! -a $MCKERN ]]
then
echo "ERROR: $MCKERN does not exist"
exit 0
fi
if [[ ! -a $MCAPP ]]
then
echo "ERROR: $MCAPP does not exist"
exit 0
fi
if [[ -z $MCAPP || -z $KHUSER ]]
then
echo "ERROR: Could not determine values" >&2
exit -1
fi
if [[ -z $NODELOLDMCINFO ]]
then
uptime=$(ssh root@$khctlserver cat /proc/uptime)
let uptime=$(echo $uptime | cut '-d.' -f1 )/60
find -L $MEMCINFODIR -name memc-\*.info -type f -mmin +$uptime -exec rm {} \;
fi
whenout=/tmp/$KHUSER.$$.wout
if [[ -z $MCNETID ]]
then
if [[ -a /proc/device-tree/u-boot-env/mc_iface && -a /proc/device-tree/u-boot-env/bg_${mceth}_netid ]]
then
mceth=$(cat /proc/device-tree/u-boot-env/mc_iface)
mcnetid=$(cat /proc/device-tree/u-boot-env/bg_${mceth}_netid)
mcs=$(khget -n $MCNETID $KHUSER $NUM)
else
mcs=$(khget -p 1 $KHUSER $NUM)
fi
else
mcs=$(khget -n $MCNETID $KHUSER $NUM)
fi
# FIXME: HERE IS THE LOOP SEE TOP COMMENT
# all the ids first to ensure that
# we have enough ids
if (( $? != 0 ))
then
echo "ERROR: failed to acquire $NUM nodes for memcached servers" >&2
exit -1
fi
mcscon=$(echo "$mcs" | khdo concmd "echo %con%")
echo "MCS INFO: $mcs" >&2
if [[ -n $MCKERN ]]
then
echo "$mcs" | khdo loadkernel $MCKERN
fi
echo "$mcs" | khdo loadramdisk $MCAPP
nodes=$(echo "$mcs" | khdo pernodecmd "echo %node%")
i=0
for n in $nodes
do
configline="itest \$bgp_rank == $n && setenv mc_eth eth0"
echo "$mcs" | khdo write "$configline"
(( i++ ))
done
nodes=$(echo $nodes)
nodes=${nodes// /-}
echo "$mcs" > $MEMCINFODIR/memc-$nodes.info
echo "$mcs" | khdo write "setenv mc_server 1"
echo "$mcs" | khdo write "setenv mc_chunksize $MCMINCS"
echo "$mcs" | khdo write "setenv mc_maxchunksize $MCMAXCS"
echo "$mcs" | khdo write "setenv mc_factor $MCFACTOR"
let BIGPHYS*=256
echo "$mcs" | 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 "$mcs" | khdo write 'setenv ramfsarg $ramfsaddr'
echo "$mcs" | khdo write "run boot"
if [[ -z $NOWINDOWS ]]
then
echo "$mcs" | khdo concmd "khxcon -s "mc${khctlserver##*.}" %con% \"-geometry 80x6+0+700\" &"
fi
echo "$mcs"