tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 2 | # ----------------------------------------------------------------------------- |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 3 | # Remotely stops & uninstalls ONOS on the specified node. |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 4 | # ----------------------------------------------------------------------------- |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 5 | |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame] | 6 | function _usage () { |
| 7 | cat << _EOF_ |
| 8 | usage: |
| 9 | $(basename $0) [node] |
| 10 | |
| 11 | options: |
| 12 | - [node] : The remote instance to uninstall ONOS from. |
| 13 | |
| 14 | summary: |
| 15 | Remotely stops and uninstalls ONOS on the specified node. |
| 16 | |
| 17 | If [node] isn't specified, \$OCI becomes the target. |
| 18 | |
| 19 | _EOF_ |
| 20 | } |
| 21 | |
| 22 | [ "$1" = "-h" ] && _usage && exit 0 |
| 23 | |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 24 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 25 | . $ONOS_ROOT/tools/build/envDefaults |
| 26 | |
| 27 | remote=$ONOS_USER@${1:-$OCI} |
| 28 | |
Bob Lantz | 7c751b5 | 2016-04-15 15:42:28 -0700 | [diff] [blame] | 29 | ssh -tt $remote " |
| 30 | sudo service onos stop 1>/dev/null 2>/dev/null |
Brian O'Connor | c045c4a | 2015-09-17 16:09:44 -0700 | [diff] [blame] | 31 | # Wait for onos to stop up to 5 seconds |
| 32 | for i in \$(seq 1 5); do |
| 33 | [ -z \"\$(ps -ef | grep karaf.jar | grep -v grep)\" ] && break |
| 34 | sleep 1 |
| 35 | done |
Thomas Vachuska | 46a4fe2 | 2015-09-29 17:28:30 -0700 | [diff] [blame] | 36 | [ -z \"\$(ps -ef | grep karaf.jar | grep -v grep)\" ] || \ |
| 37 | (echo 'ONOS failed to stop.'; status=1) |
Brian O'Connor | c045c4a | 2015-09-17 16:09:44 -0700 | [diff] [blame] | 38 | |
| 39 | # Remove onos directory and init file |
Thomas Vachuska | 46a4fe2 | 2015-09-29 17:28:30 -0700 | [diff] [blame] | 40 | [ -d $ONOS_INSTALL_DIR ] && sudo rm -fr $ONOS_INSTALL_DIR |
| 41 | [ -f /etc/init/onos.conf ] && sudo rm -f /etc/init/onos.conf |
Bob Lantz | d22c991 | 2016-12-15 14:26:18 -0800 | [diff] [blame] | 42 | [ -f /etc/init.d/onos ] && sudo rm -f /etc/init.d/onos |
| 43 | [ -f /etc/systemd/system/onos.service ] && sudo rm -f /etc/systemd/system/onos.service |
Thomas Vachuska | 46a4fe2 | 2015-09-29 17:28:30 -0700 | [diff] [blame] | 44 | |
| 45 | exit \${status:-0}; |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 46 | " |