onos-run-karaf
2.47 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
#!/bin/bash
# -----------------------------------------------------------------------------
# Runs ONOS from distributable onos.tar.gz
# -----------------------------------------------------------------------------
ONOS_TAR=
cd /tmp
# Kill any running instances
[ -f /tmp/onos.pid ] && kill -9 $(cat /tmp/onos.pid) &>/dev/null
ONOS_DIR=$(tar tf $ONOS_TAR | head -n 1 | cut -d/ -f1)
ONOS_MD5=$ONOS_DIR/CHECKSUM
# Extract MD5 of the ONOS tar file and of the previous installation, if one exists
oldMD5=$(cat $ONOS_MD5 2>/dev/null)
newMD5=$(md5 -q $ONOS_TAR)
# Search for the "clean" argument anywhere on the command-line
echo "$@" | egrep -q "\bclean\b" && clean=true || unset clean
set -e # Do not tolerate any errors from this point onward
# If the previous installation does not exist, or if the ONOS tar changed,
# or if the user asked for clean run, start from scratch.
if [ ! -d $ONOS_DIR -o "$oldMD5" != "$newMD5" -o -d $ONOS_DIR -a -n "$clean" ]; then
echo "Running clean installation..."
# Blitz previously unrolled onos- directory
rm -fr $ONOS_DIR
# Unroll new image from the specified tar file
[ -f $ONOS_TAR ] && tar zxf $ONOS_TAR
# Write out this installation's MD5 checksum
echo "$newMD5" > $ONOS_MD5
# Change into the ONOS home directory
cd $ONOS_DIR
export ONOS_HOME=$PWD
# FIXME: for now we're running using the karaf client; later use raw SSH
unset ONOS_USE_SSH
# Create config/cluster.json (cluster metadata)
IP=${ONOS_IP:-127.0.0.1}
echo "Creating local cluster configs for IP $IP..."
[ -d $ONOS_HOME/config ] || mkdir -p $ONOS_HOME/config
cat > $ONOS_HOME/config/cluster.json <<-EOF
{
"name": "default",
"nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ],
"partitions": [ { "id": 1, "members": [ "$IP" ] } ]
}
EOF
else
# Otherwise, run using the previous installation
echo "Running previous installation..."
# Change into the ONOS home directory
cd $ONOS_DIR
export ONOS_HOME=$PWD
fi
# Start ONOS as a server, but include any specified options
./bin/onos-service server "$@" &>onos.log &
echo "$!" > /tmp/onos.pid
# Hang-on a bit and then start tailing the ONOS log output
RETRY_COUNT=5
echo "Waiting for karaf.log"
until [ $RETRY_COUNT -le 0 ]; do
KARAF_LOG=$(find $ONOS_HOME -type f -name karaf.log)
if [ $KARAF_LOG ]; then
tail -f $KARAF_LOG
return
fi
RETRY_COUNT=$[$RETRY_COUNT-1]
sleep 1
done
echo "Fail to open karaf.log"