Jordan Halterman | 00e92da | 2018-05-22 23:05:52 -0700 | [diff] [blame] | 1 | #!/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 | |
| 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 | |
| 35 | # Select the target |
| 36 | if [ "${1}" = "--cell" ]; then |
| 37 | nodes=$(env | sort | egrep "^OCC[0-9]+" | cut -d= -f2) |
| 38 | else |
| 39 | nodes=$(find_node ${1:-$OCI}) |
| 40 | fi |
| 41 | |
pierventre | 59d88b5 | 2021-05-04 16:48:36 +0200 | [diff] [blame] | 42 | # Define the java options for atomix |
pierventre | b59c51d | 2021-05-06 09:27:00 +0200 | [diff] [blame] | 43 | JAVA_OPTS="${JAVA_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200}" |
pierventre | 59d88b5 | 2021-05-04 16:48:36 +0200 | [diff] [blame] | 44 | if [ ! -z "$ONOS_YOURKIT" ]; then |
pierventre | b59c51d | 2021-05-06 09:27:00 +0200 | [diff] [blame] | 45 | JAVA_OPTS+=" -agentpath:$ATOMIX_INSTALL_DIR/libyjpagent.so=listen=all" |
pierventre | 59d88b5 | 2021-05-04 16:48:36 +0200 | [diff] [blame] | 46 | fi |
| 47 | |
Jordan Halterman | 00e92da | 2018-05-22 23:05:52 -0700 | [diff] [blame] | 48 | case $2 in |
| 49 | start) |
| 50 | # Execute the remote commands |
| 51 | for node in $nodes; do |
pierventre | 59d88b5 | 2021-05-04 16:48:36 +0200 | [diff] [blame] | 52 | ssh $ONOS_USER@${node} "JAVA_OPTS=\"${JAVA_OPTS}\" nohup $ATOMIX_INSTALL_DIR/bin/atomix-agent -c $ATOMIX_INSTALL_DIR/atomix.json >/dev/null 2>&1 &" |
Jordan Halterman | 00e92da | 2018-05-22 23:05:52 -0700 | [diff] [blame] | 53 | done |
| 54 | ;; |
| 55 | stop) |
| 56 | # Execute the remote commands |
| 57 | for node in $nodes; do |
| 58 | ssh -tt $ONOS_USER@${node} " |
Jordan Halterman | 0b3ad5b | 2018-08-06 12:15:08 -0700 | [diff] [blame] | 59 | pid=\$(ps -ef | grep AtomixAgent | grep -v grep | cut -c10-15 | tr -d ' ') |
Jordan Halterman | 00e92da | 2018-05-22 23:05:52 -0700 | [diff] [blame] | 60 | if [ -n \"\$pid\" ]; then |
| 61 | echo \"Killing Atomix process \$pid on \$(hostname)...\" |
| 62 | kill -9 \$pid |
| 63 | else |
| 64 | echo \"Atomix process is not running...\" |
| 65 | exit 1 |
| 66 | fi |
| 67 | " |
| 68 | done |
| 69 | ;; |
| 70 | *) |
| 71 | echo "error: $2 is not a valid command" |
| 72 | echo "" |
| 73 | print_usage |
| 74 | ;; |
| 75 | esac |