summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/tools/test/bin/onos-uninstall
blob: ff8ff536acb7446309646b95c5556fc9ff73964b (plain)
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
#!/bin/bash
# -----------------------------------------------------------------------------
# Remotely stops & uninstalls ONOS on the specified node.
# -----------------------------------------------------------------------------

function _usage () {
cat << _EOF_
usage:
 $(basename $0) [node]

options:
- [node] : The remote instance to uninstall ONOS from.

summary:
 Remotely stops and uninstalls ONOS on the specified node.

 If [node] isn't specified, \$OCI becomes the target.

_EOF_
}

[ "$1" = "-h" ] && _usage && exit 0

[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults

remote=$ONOS_USER@${1:-$OCI}

ssh $remote "
    sudo stop onos 1>/dev/null 2>/dev/null

    # Wait for onos to stop up to 5 seconds
    for i in \$(seq 1 5); do
      [ -z \"\$(ps -ef | grep karaf.jar | grep -v grep)\" ] && break
      sleep 1
    done
    [ -z \"\$(ps -ef | grep karaf.jar | grep -v grep)\" ] || \
        (echo 'ONOS failed to stop.'; status=1)

    # Remove onos directory and init file
    [ -d $ONOS_INSTALL_DIR ] && sudo rm -fr $ONOS_INSTALL_DIR
    [ -f /etc/init/onos.conf ] && sudo rm -f /etc/init/onos.conf

    exit \${status:-0};
"