tom | 1a2908c | 2014-09-23 16:37: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 administers the ONOS service on the specified node. |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 4 | # ----------------------------------------------------------------------------- |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
Jonathan Hart | 1a4d359 | 2015-08-31 10:59:16 +0200 | [diff] [blame^] | 8 | . $ONOS_ROOT/tools/test/bin/find-node.sh |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 9 | |
Pavlin Radoslavov | caf19cf | 2014-10-16 17:29:13 -0700 | [diff] [blame] | 10 | function print_usage { |
| 11 | command_name=`basename $0` |
| 12 | echo "Remotely administer the ONOS service on a single node or the current ONOS cell." |
| 13 | echo |
| 14 | echo "Usage: $command_name <TARGET> [COMMAND]" |
| 15 | echo " $command_name [-h | --help]" |
| 16 | echo "Options:" |
| 17 | echo " TARGET The target of the command" |
| 18 | echo " COMMAND The command to execute. Default value is 'status'" |
| 19 | echo " [-h | --help] Print this help" |
| 20 | echo "" |
| 21 | echo "TARGET: <hostname | --cell>" |
| 22 | echo " hostname Execute on the specified host name" |
| 23 | echo " --cell Execute on the current ONOS cell" |
| 24 | echo "" |
| 25 | echo "COMMAND: [start|stop|restart|status]" |
| 26 | echo "" |
| 27 | } |
| 28 | |
| 29 | # Print usage |
| 30 | if [ "${1}" = "-h" -o "${1}" = "--help" ]; then |
| 31 | print_usage |
| 32 | exit 0 |
| 33 | fi |
| 34 | |
Jonathan Hart | af53b60 | 2015-04-03 16:25:37 -0700 | [diff] [blame] | 35 | case $2 in |
| 36 | start|stop|restart|status) |
Pavlin Radoslavov | caf19cf | 2014-10-16 17:29:13 -0700 | [diff] [blame] | 37 | |
Jonathan Hart | af53b60 | 2015-04-03 16:25:37 -0700 | [diff] [blame] | 38 | # Select the target |
| 39 | if [ "${1}" = "--cell" ]; then |
| 40 | nodes=$(env | sort | egrep "OC[0-9]+" | cut -d= -f2) |
| 41 | else |
Jonathan Hart | 1a4d359 | 2015-08-31 10:59:16 +0200 | [diff] [blame^] | 42 | nodes=$(find_node ${1:-$OCI}) |
Jonathan Hart | af53b60 | 2015-04-03 16:25:37 -0700 | [diff] [blame] | 43 | fi |
| 44 | |
| 45 | # Execute the remote commands |
| 46 | for node in $nodes; do |
| 47 | ssh $ONOS_USER@${node} "sudo ${2:-status} onos" |
| 48 | done |
| 49 | ;; |
| 50 | *) |
| 51 | echo "error: $2 is not a valid command" |
| 52 | echo "" |
| 53 | print_usage |
| 54 | ;; |
| 55 | esac |