blob: 1da285beb2d13b38f5e687c7670367d6c6a7570f [file] [log] [blame]
Jordan Halterman00e92da2018-05-22 23:05:52 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Remotely administers the ONOS service on the specified node.
4# -----------------------------------------------------------------------------
5
6[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7. $ONOS_ROOT/tools/build/envDefaults
8. $ONOS_ROOT/tools/test/bin/find-node.sh
9
10function 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
35# Select the target
36if [ "${1}" = "--cell" ]; then
37 nodes=$(env | sort | egrep "^OCC[0-9]+" | cut -d= -f2)
38else
39 nodes=$(find_node ${1:-$OCI})
40fi
41
42case $2 in
43 start)
44 # Execute the remote commands
45 for node in $nodes; do
Jordan Halterman6aca84c2018-07-31 13:33:13 -070046 ssh $ONOS_USER@${node} "nohup $ATOMIX_INSTALL_DIR/bin/atomix-agent -c $ATOMIX_INSTALL_DIR/atomix.json >/dev/null 2>&1 &"
Jordan Halterman00e92da2018-05-22 23:05:52 -070047 done
48 ;;
49 stop)
50 # Execute the remote commands
51 for node in $nodes; do
52 ssh -tt $ONOS_USER@${node} "
Jordan Halterman6aca84c2018-07-31 13:33:13 -070053 pid=\$(ps -ef | grep atomix | grep -v grep | cut -c10-15 | tr -d ' ')
Jordan Halterman00e92da2018-05-22 23:05:52 -070054 if [ -n \"\$pid\" ]; then
55 echo \"Killing Atomix process \$pid on \$(hostname)...\"
56 kill -9 \$pid
57 else
58 echo \"Atomix process is not running...\"
59 exit 1
60 fi
61 "
62 done
63 ;;
64 *)
65 echo "error: $2 is not a valid command"
66 echo ""
67 print_usage
68 ;;
69esac