blob: d65b521832a79c37294382c826fb4c3d039937dd [file] [log] [blame]
tom1a2908c2014-09-23 16:37:39 -07001#!/bin/bash
Pavlin Radoslavov91413792014-10-15 11:00:32 -07002# -----------------------------------------------------------------------------
tom1a2908c2014-09-23 16:37:39 -07003# Remotely administers the ONOS service on the specified node.
Pavlin Radoslavov91413792014-10-15 11:00:32 -07004# -----------------------------------------------------------------------------
tom1a2908c2014-09-23 16:37:39 -07005
6[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7. $ONOS_ROOT/tools/build/envDefaults
Jonathan Hart1a4d3592015-08-31 10:59:16 +02008. $ONOS_ROOT/tools/test/bin/find-node.sh
tom1a2908c2014-09-23 16:37:39 -07009
Pavlin Radoslavovcaf19cf2014-10-16 17:29:13 -070010function 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
30if [ "${1}" = "-h" -o "${1}" = "--help" ]; then
31 print_usage
32 exit 0
33fi
34
Bob Lantz641d5452016-03-04 19:39:17 -080035case $2 in
Jonathan Hartaf53b602015-04-03 16:25:37 -070036 start|stop|restart|status)
Jonathan Hartaf53b602015-04-03 16:25:37 -070037 # Select the target
38 if [ "${1}" = "--cell" ]; then
Claudine Chiu45312d02016-06-15 13:17:12 +000039 nodes=$(env | sort | egrep "^OC[0-9]+" | cut -d= -f2)
Jonathan Hartaf53b602015-04-03 16:25:37 -070040 else
Jonathan Hart1a4d3592015-08-31 10:59:16 +020041 nodes=$(find_node ${1:-$OCI})
Jonathan Hartaf53b602015-04-03 16:25:37 -070042 fi
43
44 # Execute the remote commands
45 for node in $nodes; do
Bob Lantz7c751b52016-04-15 15:42:28 -070046 ssh -tt $ONOS_USER@${node} "sudo service onos ${2:-status}"
Jonathan Hartaf53b602015-04-03 16:25:37 -070047 done
48 ;;
49 *)
50 echo "error: $2 is not a valid command"
51 echo ""
52 print_usage
53 ;;
54esac