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