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