Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 2 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 3 | ### Env vars used by this script. (default value) ### |
| 4 | # $ONOS_HOME : path of root directory of ONOS repository (this script's dir) |
| 5 | # $ONOS_CONF_DIR : path of ONOS config directory (~/ONOS/conf) |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 6 | # $ONOS_CONF : path of ONOS node config file (~/ONOS/conf/onos_node.`hostname`.conf or onos_node.conf) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 7 | # $ONOS_PROPS : path of ONOS properties file (~/ONOS/conf/onos.properties) |
| 8 | # $ONOS_LOGBACK : path of logback config file (~/ONOS/conf/logback.`hostname`.xml) |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 9 | # $ONOS_LOGDIR : path of log output directory (~/ONOS/onos-logs) |
| 10 | # $ONOS_LOGBASE : base name of log output file (onos.`hostname`) |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 11 | # $ONOS_DEBUG : option to enable debugger for ONOS (false) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 12 | # $RAMCLOUD_HOME : path of root directory of RAMCloud repository (~/ramcloud) |
| 13 | # $RAMCLOUD_BRANCH : branch name of RAMCloud to use (master) |
Yuta HIGUCHI | fb1905a | 2014-06-09 14:07:34 -0700 | [diff] [blame] | 14 | # $ZK_HOME : path of root directory of ZooKeeper (~/zookeeper-3.4.6) |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 15 | # $ZK_LIB_DIR : path of ZooKeeper library (/var/lib/zookeeper) |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 16 | # $ZK_LOG_DIR : path of ZooKeeper log output directory (~/ONOS/onos-logs/zk-`hostname`) |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 17 | # $JVM_OPTS : JVM options to add when starting ONOS |
| 18 | # $JVM_DEBUG_PORT : port to use for remote debugging ONOS process, when $ONOS_DEBUG is enabled (22007) |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 19 | # $ZK_CONF : path of ZooKeeper config file (~/ONOS/conf/zoo.cfg) |
| 20 | # $HC_CONF : path of Hazelcast config file (~/ONOS/conf/hazelcast.xml) |
| 21 | # $RAMCLOUD_CONF : path of RAMCloud config file (~/ONOS/conf/ramcloud.conf) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 22 | ##################################################### |
| 23 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 24 | ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 25 | ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf} |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 26 | ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.`hostname`.conf} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 27 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 28 | source ${ONOS_HOME}/scripts/common/utils.sh |
| 29 | |
Yuta HIGUCHI | e748ecc | 2014-05-28 13:55:03 -0700 | [diff] [blame] | 30 | confirm-if-root |
| 31 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 32 | if [ ! -f ${ONOS_CONF} ]; then |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 33 | # falling back to default config file |
| 34 | ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf |
| 35 | if [ ! -f ${ONOS_CONF} ]; then |
| 36 | echo "${ONOS_CONF} not found." |
| 37 | exit 1 |
| 38 | fi |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 39 | fi |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 40 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 41 | ### Variables read from ONOS config file ### |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 42 | ONOS_CLUSTER_NAME=$(read-conf ${ONOS_CONF} onos.cluster.name "onos") |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 43 | ONOS_HOST_NAME=$(read-conf ${ONOS_CONF} host.name `hostname`) |
| 44 | ONOS_HOST_IP=$(read-conf ${ONOS_CONF} host.ip) |
| 45 | ONOS_HOST_ROLE=$(read-conf ${ONOS_CONF} host.role) |
| 46 | ONOS_HOST_BACKEND=$(read-conf ${ONOS_CONF} host.backend) |
| 47 | ZK_HOSTS=$(read-conf ${ONOS_CONF} zookeeper.hosts ${ONOS_HOST_NAME}) |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 48 | ZK_CLIENTPORT=$(read-conf ${ONOS_CONF} zookeeper.clientPort 2181) |
| 49 | ZK_PORTS=$(read-conf ${ONOS_CONF} zookeeper.ports 2888:3888) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 50 | RC_COORD_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.coordinator.protocol "fast+udp") |
| 51 | RC_COORD_IP=$(read-conf ${ONOS_CONF} ramcloud.coordinator.ip ${ONOS_HOST_IP}) |
| 52 | RC_COORD_PORT=$(read-conf ${ONOS_CONF} ramcloud.coordinator.port 12246) |
| 53 | RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp") |
| 54 | RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP}) |
| 55 | RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242) |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 56 | HC_HOST_PORT=$(read-conf ${ONOS_CONF} hazelcast.host.port 5701) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 57 | HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members) |
| 58 | HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3") |
| 59 | HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 60 | ############################################ |
| 61 | |
| 62 | |
| 63 | ############## Other variables ############# |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 64 | ONOS_TEMPLATE_DIR=${ONOS_CONF_DIR}/template |
| 65 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 66 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
| 67 | |
Yuta HIGUCHI | fb1905a | 2014-06-09 14:07:34 -0700 | [diff] [blame] | 68 | ZK_HOME=${ZK_HOME:-~/zookeeper-3.4.6} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 69 | ZK_CONF=${ZK_CONF:-${ONOS_CONF_DIR}/zoo.cfg} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 70 | ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 71 | # Adding ONOS_HOST_NAME dir since file name (zookeeper.out) cannot be controlled. |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 72 | ZK_LOG_DIR=${ZK_LOG_DIR:-${ONOS_HOME}/onos-logs/zk-${ONOS_HOST_NAME}} |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 73 | ZK_LIB_DIR=${ZK_LIB_DIR:-/var/lib/zookeeper} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 74 | ZK_MY_ID=${ZK_LIB_DIR}/myid |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 75 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 76 | HC_CONF=${HC_CONF:-${ONOS_CONF_DIR}/hazelcast.xml} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 77 | HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template |
| 78 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 79 | RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 80 | RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log |
| 81 | RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 82 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 83 | RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_CONF_DIR}/ramcloud.conf} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 84 | |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 85 | export LD_LIBRARY_PATH=${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}:$LD_LIBRARY_PATH |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 86 | |
| 87 | ## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 88 | ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_CONF_DIR}/logback.${ONOS_HOST_NAME}.xml} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 89 | ONOS_LOGBACK_BACKUP=${ONOS_LOGBACK}.bak |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 90 | ONOS_LOGBACK_TEMPLATE=${ONOS_TEMPLATE_DIR}/logback.xml.template |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 91 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 92 | LOGBASE=${ONOS_LOGBASE:-onos.${ONOS_HOST_NAME}} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 93 | ONOS_LOG="${LOGDIR}/${LOGBASE}.log" |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 94 | ONOS_LOG_ROLLING_PATTERN="${LOGDIR}/${LOGBASE}.%i.log.gz" |
| 95 | ONOS_STDOUT_LOG="${LOGDIR}/${LOGBASE}.stdout" |
| 96 | ONOS_STDERR_LOG="${LOGDIR}/${LOGBASE}.stderr" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 97 | PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap" |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 98 | LOGS="$ONOS_LOG $ONOS_STDOUT_LOG $ONOS_STDERR_LOG $PCAP_LOG" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 99 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 100 | ONOS_PROPS=${ONOS_PROPS:-${ONOS_CONF_DIR}/onos.properties} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 101 | JMX_PORT=${JMX_PORT:-7189} |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 102 | JVM_DEBUG_PORT=${JVM_DEBUG_PORT:-22007} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 103 | |
| 104 | # Set JVM options |
| 105 | JVM_OPTS="${JVM_OPTS:-}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 106 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 107 | #JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 108 | |
| 109 | # Uncomment or specify appropriate value as JVM_OPTS environment variables. |
| 110 | #JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 111 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 112 | #JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 113 | |
| 114 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC" |
| 115 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC" |
| 116 | JVM_OPTS="$JVM_OPTS -XX:+AggressiveOpts" |
| 117 | |
| 118 | # We may want to remove UseFastAccessorMethods option: http://bugs.java.com/view_bug.do?bug_id=6385687 |
| 119 | JVM_OPTS="$JVM_OPTS -XX:+UseFastAccessorMethods" |
| 120 | |
| 121 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192" |
| 122 | JVM_OPTS="$JVM_OPTS -XX:FreqInlineSize=8192" |
| 123 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500" |
| 124 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 125 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 126 | |
Praseed Balakrishnan | 4fe8081 | 2014-07-24 11:29:19 -0700 | [diff] [blame] | 127 | # This option tells the VM to generate a heap dump when memory allocation cannot be satisfied. |
| 128 | # http://www.oracle.com/technetwork/java/javase/clopts-139448.html#gbzrr |
| 129 | JVM_OPTS="$JVM_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${ONOS_HOME}" |
| 130 | |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 131 | # Workaround for Thread Priority http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html |
| 132 | JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42" |
| 133 | |
| 134 | JVM_OPTS="$JVM_OPTS -XX:+UseCompressedOops" |
| 135 | |
| 136 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT" |
| 137 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false" |
| 138 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" |
| 139 | |
Yuta HIGUCHI | 6bcaf98 | 2014-07-30 15:49:58 -0700 | [diff] [blame] | 140 | JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j -Dhazelcast.jmx=true -Dhazelcast.jmx.detailed=true" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 141 | |
Yuta HIGUCHI | c248d0d | 2014-07-30 16:14:18 -0700 | [diff] [blame] | 142 | # TODO revisit HZ related magic numbers |
| 143 | # HZ Default:1000000 |
| 144 | JVM_OPTS="$JVM_OPTS -Dhazelcast.event.queue.capacity=4000000" |
| 145 | # HZ Default:32 (KB) |
| 146 | JVM_OPTS="$JVM_OPTS -Dhazelcast.socket.receive.buffer.size=4096" |
| 147 | # HZ Default:32 (KB) |
| 148 | JVM_OPTS="$JVM_OPTS -Dhazelcast.socket.send.buffer.size=4096" |
| 149 | |
| 150 | |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 151 | # Uncomment to dump final JVM flags to stdout |
| 152 | #JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal" |
| 153 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 154 | # Set ONOS core main class |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 155 | MAIN_CLASS="net.onrc.onos.core.main.Main" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 156 | |
| 157 | MVN=${MVN:-mvn -o} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 158 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 159 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 160 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 161 | ############# Common functions ############# |
| 162 | function print_usage { |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 163 | local scriptname=`basename $0` |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 164 | local filename=`basename ${ONOS_CONF}` |
| 165 | local usage="Usage: setup/start/stop ONOS on this server. |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 166 | \$ ${scriptname} setup [-f] |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 167 | Set up ONOS node using ${ONOS_CONF} . |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 168 | - generate and replace config file of ZooKeeper. |
| 169 | - create myid in ZooKeeper datadir. |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 170 | - generate and replace config file for Hazelcast. |
| 171 | - generate and replace config file for RAMCloud. |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 172 | - generate and replace logback.${ONOS_HOST_NAME}.xml |
| 173 | If -f option is used, all existing files will be overwritten without confirmation. |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 174 | \$ ${scriptname} start [single-node|coord-node|server-node|coord-and-server-node] |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 175 | Start ONOS node with specific RAMCloud entities |
| 176 | - single-node: start ONOS with stand-alone RAMCloud |
| 177 | - coord-node : start ONOS with RAMCloud coordinator |
| 178 | - server-node: start ONOS with RAMCloud server |
| 179 | - coord-and-server-node: start ONOS with RAMCloud coordinator and server |
| 180 | * Default behavior can be defined by ${filename} |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 181 | \$ ${scriptname} stop |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 182 | Stop all ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 183 | \$ ${scriptname} restart |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 184 | Stop and start currently running ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 185 | \$ ${scriptname} status |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 186 | Show status of ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 187 | \$ ${scriptname} {zk|rc-coord|rc-server|core} {start|stop|restart|status} |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 188 | Control specific ONOS-related process |
| 189 | \$ ${scriptname} rc deldb |
| 190 | Delete data in RAMCloud" |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 191 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 192 | echo "${usage}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Yuta HIGUCHI | b138a8c | 2014-06-19 11:07:20 -0700 | [diff] [blame] | 195 | # rotate-log [log-filename] [max rotations] |
| 196 | # Example: |
| 197 | # foobar.log -> foobar.log.1 |
| 198 | # foobar.log.1 -> foobar.log.2 |
| 199 | # foobar.log.gz -> foobar.log.1.gz |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 200 | function rotate-log { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 201 | local logfile=$1 |
| 202 | local nr_max=${2:-10} |
| 203 | if [ -f $logfile ]; then |
Yuta HIGUCHI | b138a8c | 2014-06-19 11:07:20 -0700 | [diff] [blame] | 204 | # TODO treating only .gz now. probably want more generic solution |
| 205 | local basename=${logfile%%.gz} |
| 206 | local append="" |
| 207 | if [ "$basename" != "$logfile" ]; then |
| 208 | append=".gz" |
| 209 | fi |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 210 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
Yuta HIGUCHI | b138a8c | 2014-06-19 11:07:20 -0700 | [diff] [blame] | 211 | if [ -f ${basename}.${i}${append} ]; then |
| 212 | mv -f ${basename}.${i}${append} ${basename}.`expr $i + 1`${append} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 213 | fi |
| 214 | done |
Yuta HIGUCHI | b138a8c | 2014-06-19 11:07:20 -0700 | [diff] [blame] | 215 | mv ${basename}${append} ${basename}.1${append} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 216 | fi |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | # kill-processes {module-name} {array of pids} |
| 220 | function kill-processes { |
| 221 | # Kill the existing processes |
| 222 | local pids=$2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 223 | if [ ! -z "$pids" ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 224 | echo -n "Stopping $1 ... " |
| 225 | fi |
| 226 | for p in ${pids}; do |
| 227 | if [ x$p != "x" ]; then |
Naoki Shiota | 4b35576 | 2014-05-27 11:46:43 -0700 | [diff] [blame] | 228 | # Check if target process is accesible from current user |
| 229 | kill -0 $p |
| 230 | if [ "$?" -ne 0 ]; then |
| 231 | # Error exit code here means "failed to send signal". |
| 232 | # Supposedly because of permission error. |
| 233 | echo "Failed to kill process (pid: $p)." |
| 234 | echo "Check if current user is the same as process owner." |
| 235 | exit 1 |
| 236 | fi |
| 237 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 238 | ( |
| 239 | # Ask process with SIGTERM first, if that did not kill the process |
| 240 | # wait 1s and if process still exist, force process to be killed. |
| 241 | kill -TERM $p && kill -0 $p && sleep 1 && kill -0 $p && kill -KILL $p |
| 242 | ) 2> /dev/null |
Naoki Shiota | 4b35576 | 2014-05-27 11:46:43 -0700 | [diff] [blame] | 243 | |
| 244 | # Ensure process is killed. |
| 245 | kill -0 $p 2> /dev/null |
| 246 | if [ "$?" -ne 0 ]; then |
| 247 | # Error exit code here means "process not found", i.e. "kill succeeded". |
| 248 | echo "Killed existing process (pid: $p)" |
| 249 | else |
| 250 | # Process still exists. Some unexpected error occurs. |
| 251 | echo "Failed to kill process (pid: $p)." |
| 252 | echo "Unexpected error occurs during process termination." |
| 253 | exit 1 |
| 254 | fi |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 255 | fi |
| 256 | done |
| 257 | } |
| 258 | |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 259 | function handle-error { |
| 260 | set -e |
| 261 | |
| 262 | revert-confs |
| 263 | |
| 264 | set +e |
| 265 | |
| 266 | exit 1 |
| 267 | } |
| 268 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 269 | # revert-confs [error message] |
| 270 | function revert-confs { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 271 | echo -n "ERROR occurred ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 272 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 273 | revert-file `basename ${ZK_CONF}` |
| 274 | revert-file `basename ${HC_CONF}` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 275 | |
| 276 | echo "EXIT" |
| 277 | |
| 278 | if [ ! -z "$1" ]; then |
| 279 | echo $1 |
| 280 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 283 | function create-zk-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 284 | echo -n "Creating ${ZK_CONF} ... " |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 285 | |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 286 | # Create the ZooKeeper lib directory |
Yuta HIGUCHI | b3983b1 | 2014-06-12 14:21:09 -0700 | [diff] [blame] | 287 | if [[ ! ( -w ${ZK_LIB_DIR} && -d ${ZK_LIB_DIR} ) ]]; then |
Naoki Shiota | 7f495cf | 2014-05-21 17:23:25 -0700 | [diff] [blame] | 288 | local SUDO=${SUDO:-sudo} |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 289 | local whoami=`whoami` |
| 290 | { |
Yuta HIGUCHI | b3983b1 | 2014-06-12 14:21:09 -0700 | [diff] [blame] | 291 | ${SUDO} mkdir -p ${ZK_LIB_DIR} |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 292 | ${SUDO} chown ${whoami} ${ZK_LIB_DIR} |
| 293 | } || { |
| 294 | echo "FAILED" |
| 295 | echo "[ERROR] Failed to create directory ${ZK_LIB_DIR}." |
| 296 | echo "[ERROR] Please retry after setting \"env SUDO=sudo\"" |
| 297 | exit 1 |
| 298 | } |
| 299 | fi |
| 300 | |
| 301 | # creation of ZooKeeper config |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 302 | local temp_zk=`begin-conf-creation ${ZK_CONF}` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 303 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 304 | hostarr=`echo ${ZK_HOSTS} | tr "," " "` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 305 | |
| 306 | local i=1 |
| 307 | local myid= |
| 308 | for host in ${hostarr}; do |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 309 | if [ "${host}" = "${ONOS_HOST_NAME}" -o "${host}" = "${ONOS_HOST_IP}" ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 310 | myid=$i |
| 311 | break |
| 312 | fi |
| 313 | i=`expr $i + 1` |
| 314 | done |
| 315 | |
| 316 | if [ -z "${myid}" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 317 | local filename=`basename ${ONOS_CONF}` |
Naoki Shiota | 35f8d5c | 2014-04-08 11:13:18 -0700 | [diff] [blame] | 318 | revert-confs "[ERROR] In ${filename}, zookeeper.hosts must have hostname \"${ONOS_HOST_NAME}\" or IP address" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 319 | fi |
| 320 | |
Yuta HIGUCHI | 6945089 | 2014-04-16 09:10:55 -0700 | [diff] [blame] | 321 | if [ -f "${ZK_MY_ID}" ]; then |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 322 | # sudo will be needed if ZK_MY_ID is already created by other (old) script |
Yuta HIGUCHI | 6945089 | 2014-04-16 09:10:55 -0700 | [diff] [blame] | 323 | local SUDO=${SUDO:-} |
| 324 | { |
| 325 | ${SUDO} mv -f ${ZK_MY_ID} ${ZK_MY_ID}.old |
| 326 | } || { |
| 327 | echo "FAILED" |
| 328 | echo "[ERROR] Failed to rename ${ZK_MY_ID}." |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 329 | echo "[ERROR] Please retry after setting \"env SUDO=sudo\"" |
Yuta HIGUCHI | 6945089 | 2014-04-16 09:10:55 -0700 | [diff] [blame] | 330 | exit 1 |
| 331 | } |
| 332 | fi |
| 333 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 334 | echo ${myid} > ${ZK_MY_ID} |
| 335 | |
| 336 | echo -n "myid is assigned to ${myid} ... " |
| 337 | |
| 338 | while read line; do |
| 339 | if [[ $line =~ ^__HOSTS__$ ]]; then |
| 340 | i=1 |
| 341 | for host in ${hostarr}; do |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 342 | # TODO: ZK ports should be configurable per host |
| 343 | local hostline="server.${i}=${host}:${ZK_PORTS}" |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 344 | echo $hostline |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 345 | i=`expr $i + 1` |
| 346 | done |
| 347 | elif [[ $line =~ __DATADIR__ ]]; then |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 348 | echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 349 | else |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 350 | echo $line |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 351 | fi |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 352 | done < ${ZK_CONF_TEMPLATE} > ${temp_zk} |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 353 | sed -e "s|__CLIENTPORT__|${ZK_CLIENTPORT}|" -i "" ${temp_zk} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 354 | |
| 355 | end-conf-creation ${ZK_CONF} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 356 | |
| 357 | echo "DONE" |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 358 | } |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 359 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 360 | function create-hazelcast-conf { |
| 361 | echo -n "Creating ${HC_CONF} ... " |
| 362 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 363 | local temp_hc=`begin-conf-creation ${HC_CONF}` |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 364 | |
| 365 | # To keep indent of XML file, change IFS |
| 366 | local IFS='' |
| 367 | while read line; do |
| 368 | if [[ $line =~ __HC_NETWORK__ ]]; then |
| 369 | if [ ! -z "${HC_TCPIP_MEMBERS}" ]; then |
| 370 | # temporary change |
| 371 | IFS=' ' |
| 372 | local memberarr=`echo ${HC_TCPIP_MEMBERS} | tr "," " "` |
| 373 | echo '<multicast enabled="false" />' |
| 374 | echo '<tcp-ip enabled="true">' |
| 375 | for member in ${memberarr}; do |
| 376 | echo " <member>${member}</member>" |
| 377 | done |
| 378 | echo '</tcp-ip>' |
| 379 | IFS='' |
| 380 | else |
| 381 | echo '<multicast enabled="true">' |
| 382 | echo " <multicast-group>${HC_MULTICAST_GROUP}</multicast-group>" |
| 383 | echo " <multicast-port>${HC_MULTICAST_PORT}</multicast-port>" |
| 384 | echo '</multicast>' |
| 385 | echo '<tcp-ip enabled="false" />' |
| 386 | fi |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 387 | elif [[ $line =~ __HC_PORT__ ]]; then |
| 388 | echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|" |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 389 | elif [[ $line =~ __HC_CLUSTER__ ]]; then |
| 390 | echo $line | sed -e "s|__HC_CLUSTER__|${ONOS_CLUSTER_NAME}|" |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 391 | else |
| 392 | echo "${line}" |
| 393 | fi |
| 394 | done < ${HC_CONF_TEMPLATE} > ${temp_hc} |
| 395 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 396 | end-conf-creation ${HC_CONF} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 397 | |
| 398 | echo "DONE" |
| 399 | } |
| 400 | |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 401 | function create-ramcloud-conf { |
| 402 | echo -n "Creating ${RAMCLOUD_CONF} ... " |
| 403 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 404 | local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}` |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 405 | |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 406 | local rc_locator=`echo "${ZK_HOSTS}" | sed -e "s/,/:${ZK_CLIENTPORT},/g"` |
| 407 | rc_locator+=":${ZK_CLIENTPORT}" |
| 408 | |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 409 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME}) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 410 | |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 411 | echo "ramcloud.locator=zk:localhost:2181,${rc_locator}" > ${temp_rc} |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 412 | echo "ramcloud.clusterName=${rc_cluster_name}" >> ${temp_rc} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 413 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 414 | end-conf-creation ${RAMCLOUD_CONF} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 415 | |
| 416 | echo "DONE" |
| 417 | } |
| 418 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 419 | function create-logback-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 420 | echo -n "Creating ${ONOS_LOGBACK} ... " |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 421 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 422 | # creation of logback config |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 423 | local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}` |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 424 | |
| 425 | sed -e "s|__FILENAME__|${ONOS_LOG}|" \ |
| 426 | -e "s|__ROLLING_PATTERN__|${ONOS_LOG_ROLLING_PATTERN}|" ${ONOS_LOGBACK_TEMPLATE} > ${temp_lb} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 427 | |
| 428 | end-conf-creation ${ONOS_LOGBACK} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 429 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 430 | echo "DONE" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 433 | function create-confs { |
| 434 | local key |
| 435 | local filename |
| 436 | |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 437 | trap handle-error ERR |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 438 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 439 | echo "Config file : ${ONOS_CONF}" |
| 440 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 441 | if [ "$1" == "-f" ]; then |
| 442 | create-zk-conf |
| 443 | create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 444 | create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 445 | create-logback-conf |
| 446 | else |
| 447 | create-conf-interactive ${ZK_CONF} create-zk-conf |
| 448 | create-conf-interactive ${HC_CONF} create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 449 | create-conf-interactive ${RAMCLOUD_CONF} create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 450 | create-conf-interactive ${ONOS_LOGBACK} create-logback-conf |
| 451 | fi |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 452 | |
| 453 | trap - ERR |
| 454 | } |
| 455 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 456 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 457 | |
| 458 | ###### Functions related to ZooKeeper ###### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 459 | function zk { |
| 460 | case "$1" in |
| 461 | start) |
| 462 | start-zk |
| 463 | ;; |
| 464 | stop) |
| 465 | stop-zk |
| 466 | ;; |
| 467 | stat*) # <- status |
| 468 | status-zk |
| 469 | ;; |
| 470 | re*) # <- restart |
| 471 | stop-zk |
| 472 | start-zk |
| 473 | ;; |
| 474 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 475 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 476 | exit 1 |
| 477 | esac |
| 478 | } |
| 479 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 480 | function load-zk-cfg { |
| 481 | if [ -f "${ZK_CONF}" ]; then |
| 482 | local filename=`basename ${ZK_CONF}` |
| 483 | local dirname=`dirname ${ZK_CONF}` |
| 484 | |
| 485 | # Run ZooKeeper with our configuration |
| 486 | export ZOOCFG=${filename} |
| 487 | export ZOOCFGDIR=${dirname} |
| 488 | fi |
| 489 | } |
| 490 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 491 | function start-zk { |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 492 | echo -n "Starting ZooKeeper ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 493 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 494 | export ZOO_LOG_DIR=${ZK_LOG_DIR} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 495 | mkdir -p ${ZK_LOG_DIR} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 496 | |
| 497 | load-zk-cfg |
Yuta HIGUCHI | f66cf21 | 2014-05-29 23:16:44 -0700 | [diff] [blame] | 498 | |
| 499 | # log4j.properties is read from classpath if not found in CWD. |
| 500 | # Using the ZooKeeper supplied default in ZooKeeper conf dir. |
| 501 | # TODO: To explicitly specify our customized log4j config file: |
| 502 | # export SERVER_JVMFLAGS="-Dlog4j.configuration=${ZK_LOG4J}" |
| 503 | env CLASSPATH="${ZK_HOME}/conf:${CLASSPATH}" ${ZK_HOME}/bin/zkServer.sh start |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | function stop-zk { |
Yuta HIGUCHI | 7c70836 | 2014-06-02 23:15:13 -0700 | [diff] [blame] | 507 | echo -n "Stopping ZooKeeper ... " |
| 508 | load-zk-cfg |
| 509 | |
| 510 | ${ZK_HOME}/bin/zkServer.sh stop |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | function status-zk { |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 514 | load-zk-cfg |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 515 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 516 | ${ZK_HOME}/bin/zkServer.sh status |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 517 | } |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 518 | |
| 519 | function check-zk { |
| 520 | # assumption here is that ZK status script is the last command in status-zk. |
| 521 | status-zk &> /dev/null |
| 522 | local zk_status=$? |
| 523 | if [ "$zk_status" -ne 0 ]; then |
| 524 | return 1; |
| 525 | fi |
| 526 | return 0 |
| 527 | } |
| 528 | |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 529 | function check-and-start-zk { |
| 530 | check-zk |
| 531 | local zk_status=$? |
| 532 | if [ "$zk_status" -ne 0 ]; then |
| 533 | start-zk |
| 534 | fi |
| 535 | } |
| 536 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 537 | # wait-zk-or-die {timeout-sec} |
| 538 | function wait-zk-or-die { |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 539 | local retries=${1:-5} |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 540 | # do-while retries >= 0 |
| 541 | while true; do |
| 542 | check-zk |
| 543 | local zk_status=$? |
| 544 | if [ "$zk_status" -eq 0 ]; then |
| 545 | return 0 |
| 546 | fi |
| 547 | sleep 1; |
| 548 | ((retries -= 1)) |
| 549 | (( retries >= 0 )) || break |
| 550 | done |
| 551 | echo "ZooKeeper is not running." |
| 552 | exit 1 |
| 553 | } |
| 554 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 555 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 556 | |
| 557 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 558 | ####### Functions related to RAMCloud ###### |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 559 | |
| 560 | # Check if this host should be running RAMCloud coordinator: |
| 561 | function is-coord-role { |
| 562 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 563 | case "${ONOS_HOST_ROLE}" in |
| 564 | single-node) |
| 565 | echo "true" |
| 566 | return 0 |
| 567 | ;; |
| 568 | coord-node) |
| 569 | echo "true" |
| 570 | return 0 |
| 571 | ;; |
| 572 | server-node) |
| 573 | echo "false" |
| 574 | return 1 |
| 575 | ;; |
| 576 | coord-and-server-node) |
| 577 | echo "true" |
| 578 | return 0 |
| 579 | ;; |
| 580 | *) |
| 581 | echo "false" |
| 582 | return 1 |
| 583 | ;; |
| 584 | esac |
| 585 | else |
| 586 | echo "false" |
| 587 | return 1 |
| 588 | fi |
| 589 | } |
| 590 | |
| 591 | # Check if this host should be running RAMCloud server: |
| 592 | function is-server-role { |
| 593 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 594 | case "${ONOS_HOST_ROLE}" in |
| 595 | single-node) |
| 596 | echo "true" |
| 597 | return 0 |
| 598 | ;; |
| 599 | coord-node) |
| 600 | echo "false" |
| 601 | return 1 |
| 602 | ;; |
| 603 | server-node) |
| 604 | echo "true" |
| 605 | return 0 |
| 606 | ;; |
| 607 | coord-and-server-node) |
| 608 | echo "true" |
| 609 | return 0 |
| 610 | ;; |
| 611 | *) |
| 612 | echo "false" |
| 613 | return 1 |
| 614 | ;; |
| 615 | esac |
| 616 | else |
| 617 | echo "false" |
| 618 | return 1 |
| 619 | fi |
| 620 | } |
| 621 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 622 | function start-backend { |
| 623 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 624 | if [ $1 == "coord" ]; then |
| 625 | rc-coord startifdown |
| 626 | elif [ $1 == "server" ]; then |
| 627 | rc-server startifdown |
| 628 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 629 | fi |
| 630 | } |
| 631 | |
| 632 | function stop-backend { |
| 633 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 634 | if [ $rcsn != 0 ]; then |
| 635 | rc-server stop |
| 636 | fi |
| 637 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 638 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 639 | if [ $rccn != 0 ]; then |
| 640 | rc-coord stop |
| 641 | fi |
| 642 | } |
| 643 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 644 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 645 | ### Functions related to RAMCloud coordinator |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 646 | function rc-coord-addr { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 647 | local host=${RC_COORD_IP} |
| 648 | if [ -z "${host}" ]; then |
| 649 | # falling back to 0.0.0.0 |
| 650 | host="0.0.0.0" |
| 651 | fi |
| 652 | echo "${RC_COORD_PROTOCOL}:host=${host},port=${RC_COORD_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | function rc-server-addr { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 656 | local host=${RC_SERVER_IP} |
| 657 | if [ -z "${host}" ]; then |
| 658 | # falling back to 0.0.0.0 |
| 659 | host="0.0.0.0" |
| 660 | fi |
| 661 | echo "${RC_SERVER_PROTOCOL}:host=${host},port=${RC_SERVER_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 664 | function rc-coord { |
| 665 | case "$1" in |
| 666 | start) |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 667 | stop-coord |
| 668 | start-coord |
| 669 | ;; |
| 670 | startifdown) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 671 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 672 | if [ $n == 0 ]; then |
| 673 | start-coord |
| 674 | else |
| 675 | echo "$n instance of RAMCloud coordinator running" |
| 676 | fi |
| 677 | ;; |
| 678 | stop) |
| 679 | stop-coord |
| 680 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 681 | deldb) |
| 682 | stop-backend |
| 683 | del-coord-info |
| 684 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 685 | stat*) # <- status |
| 686 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
| 687 | echo "$n RAMCloud coordinator running" |
| 688 | ;; |
| 689 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 690 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 691 | exit 1 |
| 692 | esac |
| 693 | } |
| 694 | |
| 695 | function start-coord { |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 696 | check-and-start-zk |
| 697 | wait-zk-or-die |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 698 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 699 | if [ ! -d ${LOGDIR} ]; then |
| 700 | mkdir -p ${LOGDIR} |
| 701 | fi |
| 702 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 703 | rotate-log $RAMCLOUD_COORD_LOG |
| 704 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 705 | |
| 706 | local coord_addr=`rc-coord-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 707 | |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 708 | # TODO Make ONOS_CONF readable from ONOS process then eliminate RAMCLOUD_CONF |
| 709 | |
| 710 | # Configuration for ZK address, port |
| 711 | local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181") |
| 712 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 713 | # RAMCloud cluster name |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 714 | local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME}) |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 715 | |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 716 | # RAMCloud transport timeout |
| 717 | local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 718 | # RAMCloud option deadServerTimeout |
| 719 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 720 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 721 | |
| 722 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 723 | # but actual RAMCloud code only uses -C argument now. |
| 724 | # (FYI: -C is documented to be deprecated in the document) |
| 725 | |
| 726 | local coord_args="-C ${coord_addr}" |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 727 | coord_args="${coord_args} --externalStorage ${rc_locator}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 728 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 729 | coord_args="${coord_args} --timeout ${rc_timeout}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 730 | coord_args="${coord_args} --deadServerTimeout ${rc_coord_deadServerTimeout}" |
| 731 | |
| 732 | # Read environment variables if set |
| 733 | coord_args="${coord_args} ${RC_COORDINATOR_OPTS}" |
| 734 | |
| 735 | if [ "${ONOS_HOST_ROLE}" == "single-node" ]; then |
| 736 | # Note: Following reset is required, since RC restart is considered node failure, |
| 737 | # and tries recovery of server, which will never succeed after restart. |
| 738 | echo "Role configured to single-node mode. RAMCloud cluster will be reset on each start-up." |
| 739 | coord_args="${coord_args} --reset" |
| 740 | fi |
| 741 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 742 | # Run ramcloud |
| 743 | echo -n "Starting RAMCloud coordinator ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 744 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} > $RAMCLOUD_COORD_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 745 | echo "STARTED" |
| 746 | } |
| 747 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 748 | function del-coord-info { |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 749 | check-and-start-zk |
| 750 | wait-zk-or-die |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 751 | |
| 752 | if [ ! -d ${LOGDIR} ]; then |
| 753 | mkdir -p ${LOGDIR} |
| 754 | fi |
| 755 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 756 | rotate-log $RAMCLOUD_COORD_LOG |
| 757 | fi |
| 758 | |
| 759 | local coord_addr=`rc-coord-addr` |
| 760 | |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 761 | # Configuration for ZK address, port |
| 762 | local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181") |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 763 | # RAMCloud cluster name |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 764 | local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME}) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 765 | # RAMCloud option deadServerTimeout |
| 766 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 767 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 768 | |
| 769 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 770 | # but actual RAMCloud code only uses -C argument now. |
| 771 | # (FYI: -C is documented to be deprecated in the document) |
| 772 | |
| 773 | local coord_args="-C ${coord_addr}" |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 774 | coord_args="${coord_args} --externalStorage ${rc_locator}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 775 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
| 776 | |
| 777 | # Note: --reset will reset ZK stored info and start running as acoordinator. |
| 778 | echo -n "Deleting RAMCloud cluster coordination info ... " |
| 779 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} --reset &> $RAMCLOUD_COORD_LOG & |
| 780 | |
Yuta HIGUCHI | cd44eb3 | 2014-05-24 16:51:31 -0700 | [diff] [blame] | 781 | # TODO Assuming 5 sec is enough. To be sure monitor log? |
| 782 | sleep 5 |
| 783 | # kill coordinator |
Yuta HIGUCHI | ce9f3ee | 2014-05-14 09:48:40 -0700 | [diff] [blame] | 784 | (pkill -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator &> /dev/null) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 785 | |
| 786 | echo "DONE" |
| 787 | } |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 788 | |
| 789 | function stop-coord { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 790 | kill-processes "RAMCloud coordinator" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 793 | ### Functions related to RAMCloud server |
| 794 | function rc-server { |
| 795 | case "$1" in |
| 796 | start) |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 797 | stop-server |
| 798 | start-server |
| 799 | ;; |
| 800 | startifdown) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 801 | local n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 802 | if [ $n == 0 ]; then |
| 803 | start-server |
| 804 | else |
| 805 | echo "$n instance of RAMCloud server running" |
| 806 | fi |
| 807 | ;; |
| 808 | stop) |
| 809 | stop-server |
| 810 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 811 | deldb) |
| 812 | stop-server |
| 813 | del-server-backup |
| 814 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 815 | stat*) # <- status |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 816 | n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 817 | echo "$n RAMCloud server running" |
| 818 | ;; |
| 819 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 820 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 821 | exit 1 |
| 822 | esac |
| 823 | } |
| 824 | |
| 825 | function start-server { |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 826 | check-and-start-zk |
| 827 | wait-zk-or-die |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 828 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 829 | if [ ! -d ${LOGDIR} ]; then |
| 830 | mkdir -p ${LOGDIR} |
| 831 | fi |
| 832 | if [ -f $RAMCLOUD_SERVER_LOG ]; then |
| 833 | rotate-log $RAMCLOUD_SERVER_LOG |
| 834 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 835 | |
| 836 | local coord_addr=`rc-coord-addr` |
| 837 | local server_addr=`rc-server-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 838 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 839 | local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.server.masterServiceThreads 5) |
| 840 | local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.server.logCleanerThreads 1) |
Yuta HIGUCHI | 52efcbb | 2014-05-16 09:30:33 -0700 | [diff] [blame] | 841 | local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.server.detectFailures 0) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 842 | |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 843 | # Configuration for ZK address, port |
| 844 | local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181") |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 845 | # RAMCloud cluster name |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 846 | local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME}) |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 847 | # RAMCloud transport timeout |
| 848 | local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 849 | # replication factor (-r) config |
| 850 | local rc_replicas=$(read-conf ${ONOS_CONF} ramcloud.server.replicas 0) |
| 851 | # backup file path (-f) config |
| 852 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 853 | mkdir -p `dirname ${rc_datafile}` |
| 854 | |
| 855 | local server_args="-L ${server_addr}" |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 856 | server_args="${server_args} --externalStorage ${rc_locator}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 857 | server_args="${server_args} --clusterName ${rc_cluster_name}" |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 858 | server_args="${server_args} --timeout ${rc_timeout}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 859 | server_args="${server_args} --masterServiceThreads ${masterServiceThreads}" |
| 860 | server_args="${server_args} --logCleanerThreads ${logCleanerThreads}" |
| 861 | server_args="${server_args} --detectFailures ${detectFailures}" |
| 862 | server_args="${server_args} --replicas ${rc_replicas}" |
| 863 | server_args="${server_args} --file ${rc_datafile}" |
| 864 | |
| 865 | # Read environment variables if set |
| 866 | server_args="${server_args} ${RC_SERVER_OPTS}" |
Yuta HIGUCHI | 45bc3cf | 2014-04-19 18:12:15 -0700 | [diff] [blame] | 867 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 868 | # Run ramcloud |
| 869 | echo -n "Starting RAMCloud server ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 870 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server ${server_args} > $RAMCLOUD_SERVER_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 871 | echo "STARTED" |
| 872 | } |
| 873 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 874 | function del-server-backup { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 875 | echo -n "Delete RAMCloud backup server data [y/N]? " |
| 876 | while [ 1 ]; do |
| 877 | read key |
| 878 | if [ "${key}" == "Y" -o "${key}" == "y" ]; then |
| 879 | break |
| 880 | elif [ -z "${key}" -o "${key}" == "N" -o "${key}" == "n" ]; then |
| 881 | echo "Cancelled." |
| 882 | return |
| 883 | fi |
| 884 | echo "[y/N]? " |
| 885 | done |
| 886 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 887 | echo -n "Removing RAMCloud backup server data ... " |
| 888 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 889 | rm -f ${rc_datafile} |
| 890 | echo "DONE" |
| 891 | } |
| 892 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 893 | function stop-server { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 894 | kill-processes "RAMCloud server" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 895 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 896 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 897 | |
| 898 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 899 | ## Functions related to ONOS core process ## |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 900 | function onos { |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 901 | CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 902 | if [ ! -f ${CPFILE} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 903 | echo "ONOS core needs to be built" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 904 | ${MVN} -f ${ONOS_HOME}/pom.xml compile |
| 905 | fi |
| 906 | JAVA_CP=`cat ${CPFILE}` |
| 907 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
| 908 | |
| 909 | case "$1" in |
| 910 | start) |
| 911 | stop-onos |
| 912 | start-onos |
| 913 | ;; |
| 914 | startnokill) |
| 915 | start-onos |
| 916 | ;; |
| 917 | startifdown) |
| 918 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 919 | if [ $n == 0 ]; then |
| 920 | start-onos |
| 921 | else |
| 922 | echo "$n instance of onos running" |
| 923 | fi |
| 924 | ;; |
| 925 | stop) |
| 926 | stop-onos |
| 927 | ;; |
| 928 | stat*) # <- status |
| 929 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 930 | echo "$n instance of onos running" |
| 931 | ;; |
| 932 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 933 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 934 | exit 1 |
| 935 | esac |
| 936 | } |
| 937 | |
| 938 | function start-onos { |
| 939 | if [ ! -d ${LOGDIR} ]; then |
| 940 | mkdir -p ${LOGDIR} |
| 941 | fi |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 942 | # Rotate log files |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 943 | for log in ${LOGS}; do |
| 944 | if [ -f ${log} ]; then |
| 945 | rotate-log ${log} |
| 946 | fi |
| 947 | done |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 948 | |
| 949 | # Rotate logs rolled at runtime. |
| 950 | local rolled_log_shellpat=`echo ${ONOS_LOG_ROLLING_PATTERN} | sed -e "s/%i/\\*/"` |
| 951 | for rolled_log in ${rolled_log_shellpat}; do |
| 952 | if [ -f ${rolled_log} ]; then |
| 953 | rotate-log ${rolled_log} |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 954 | fi |
| 955 | done |
| 956 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 957 | if [ ! -f ${ONOS_LOGBACK} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 958 | echo "[WARNING] ${ONOS_LOGBACK} not found." |
| 959 | echo " Run \"\$ $0 setup\" to create." |
| 960 | exit 1 |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 961 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 962 | |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 963 | if [ ! -f ${HC_CONF} ]; then |
| 964 | echo "[WARNING] ${HC_CONF} not found." |
| 965 | echo " Run \"\$ $0 setup\" to create." |
| 966 | exit 1 |
| 967 | fi |
| 968 | |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 969 | # specify ZooKeeper(curator) namespace |
| 970 | JVM_OPTS="${JVM_OPTS} -Dzookeeper.namespace=${ONOS_CLUSTER_NAME}" |
| 971 | |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 972 | # specify ZooKeeper connectionString |
| 973 | local zk_locator=`echo "${ZK_HOSTS}" | sed -e "s/,/:${ZK_CLIENTPORT},/g"` |
| 974 | zk_locator+=":${ZK_CLIENTPORT}" |
| 975 | zk_locator="localhost:${ZK_CLIENTPORT},${zk_locator}" |
| 976 | |
| 977 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.registry.ZookeeperRegistry.connectionString=${zk_locator}" |
| 978 | |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 979 | # specify hazelcast.xml to datagrid |
| 980 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig=${HC_CONF}" |
| 981 | |
| 982 | # specify backend config |
Jonathan Hart | ef3dc1a | 2014-04-03 11:39:50 -0700 | [diff] [blame] | 983 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.backend=${ONOS_HOST_BACKEND}" |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 984 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 985 | JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}" |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 986 | elif [ "${ONOS_HOST_BACKEND}" = "hazelcast" ]; then |
| 987 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.hazelcast.baseConfig=${HC_CONF}" |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 988 | fi |
| 989 | |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 990 | # check for jvm debug flag |
| 991 | if [ "${ONOS_DEBUG}" = "true" ]; then |
| 992 | JVM_OPTS="${JVM_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${JVM_DEBUG_PORT}" |
| 993 | fi |
| 994 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 995 | # Run ONOS |
Yuta HIGUCHI | cce4f62 | 2014-04-18 16:48:53 -0700 | [diff] [blame] | 996 | |
| 997 | # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD |
| 998 | cd ${ONOS_HOME} |
| 999 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 1000 | echo -n "Starting ONOS controller ... " |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1001 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr & |
| 1002 | |
| 1003 | # We need to wait a bit to find out whether starting the ONOS process succeeded |
| 1004 | sleep 1 |
| 1005 | |
| 1006 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1007 | if [ $n -ge 1 ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1008 | echo " STARTED" |
| 1009 | else |
| 1010 | echo " FAILED" |
| 1011 | fi |
| 1012 | |
| 1013 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 1014 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 1015 | } |
| 1016 | |
| 1017 | function stop-onos { |
| 1018 | kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'` |
| 1019 | # kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 1020 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1021 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1022 | |
| 1023 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1024 | ################## Main #################### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1025 | case "$1" in |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1026 | setup) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 1027 | create-confs $2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1028 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1029 | start) |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1030 | mode_parameter=${ONOS_HOST_ROLE} |
| 1031 | if [ ! -z "$2" ]; then |
| 1032 | mode_parameter=$2 |
| 1033 | fi |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 1034 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1035 | case "${mode_parameter}" in |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1036 | single-node) |
| 1037 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1038 | start-backend coord |
| 1039 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1040 | onos startifdown |
| 1041 | ;; |
| 1042 | coord-node) |
| 1043 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1044 | start-backend coord |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1045 | onos startifdown |
| 1046 | ;; |
| 1047 | server-node) |
| 1048 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1049 | start-backend server |
| 1050 | onos startifdown |
| 1051 | ;; |
| 1052 | coord-and-server-node) |
| 1053 | zk start |
| 1054 | start-backend coord |
| 1055 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1056 | onos startifdown |
| 1057 | ;; |
| 1058 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1059 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1060 | ;; |
| 1061 | esac |
| 1062 | echo |
| 1063 | ;; |
| 1064 | stop) |
| 1065 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 1066 | if [ $on != 0 ]; then |
| 1067 | onos stop |
| 1068 | fi |
| 1069 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1070 | stop-backend |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1071 | |
| 1072 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 1073 | if [ $zkn != 0 ]; then |
| 1074 | zk stop |
| 1075 | fi |
| 1076 | echo |
| 1077 | ;; |
| 1078 | restart) |
| 1079 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 1080 | if [ $on != 0 ]; then |
| 1081 | onos stop |
| 1082 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1083 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1084 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 1085 | if [ $rcsn != 0 ]; then |
| 1086 | rc-server stop |
| 1087 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1088 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1089 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1090 | if [ $rccn != 0 ]; then |
| 1091 | rc-coord stop |
| 1092 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1093 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1094 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 1095 | if [ $zkn != 0 ]; then |
| 1096 | zk restart |
| 1097 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1098 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1099 | if [ $rccn != 0 ]; then |
| 1100 | rc-coord startifdown |
| 1101 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1102 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1103 | if [ $rcsn != 0 ]; then |
| 1104 | rc-server startifdown |
| 1105 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1106 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1107 | if [ $on != 0 ]; then |
| 1108 | onos startifdown |
| 1109 | fi |
| 1110 | echo |
| 1111 | ;; |
| 1112 | stat*) # <- status |
| 1113 | echo '[ZooKeeper]' |
| 1114 | zk status |
| 1115 | echo |
| 1116 | echo '[RAMCloud coordinator]' |
| 1117 | rc-coord status |
| 1118 | echo |
| 1119 | echo '[RAMCloud server]' |
| 1120 | rc-server status |
| 1121 | echo |
| 1122 | echo '[ONOS core]' |
| 1123 | onos status |
| 1124 | echo |
| 1125 | ;; |
| 1126 | zk) |
| 1127 | zk $2 |
| 1128 | ;; |
| 1129 | rc-c*) # <- rc-coordinator |
| 1130 | rc-coord $2 |
| 1131 | ;; |
| 1132 | rc-s*) # <- rc-server |
| 1133 | rc-server $2 |
| 1134 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 1135 | rc) |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1136 | # XXX rc command ignores if the host is not configured to have those roles, |
| 1137 | # while rc-s or rc-c executes the task regardless of role definition. |
| 1138 | # This is a workaround since TestON does not take role in account |
| 1139 | # and always issue rc deldb right now. |
| 1140 | |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 1141 | # TODO make deldb command more organized (clarify when it can work) |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1142 | if [ "`is-coord-role`" == "true" ]; then |
| 1143 | rc-coord $2 |
| 1144 | fi |
| 1145 | if [ "`is-server-role`" == "true" ]; then |
| 1146 | rc-server $2 |
| 1147 | fi |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 1148 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1149 | core) |
| 1150 | onos $2 |
| 1151 | ;; |
| 1152 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1153 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1154 | exit 1 |
| 1155 | esac |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1156 | |