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)} |
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 |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 419 | done < ${ZK_CONF_TEMPLATE} > ${temp_zk} |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 420 | sed -e "s|__CLIENTPORT__|${ZK_CLIENTPORT}|" -i "" ${temp_zk} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 421 | |
| 422 | end-conf-creation ${ZK_CONF} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 423 | |
| 424 | echo "DONE" |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 425 | } |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 426 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 427 | function create-hazelcast-conf { |
| 428 | echo -n "Creating ${HC_CONF} ... " |
| 429 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 430 | local temp_hc=`begin-conf-creation ${HC_CONF}` |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 431 | |
| 432 | # To keep indent of XML file, change IFS |
| 433 | local IFS='' |
| 434 | while read line; do |
| 435 | if [[ $line =~ __HC_NETWORK__ ]]; then |
| 436 | if [ ! -z "${HC_TCPIP_MEMBERS}" ]; then |
| 437 | # temporary change |
| 438 | IFS=' ' |
| 439 | local memberarr=`echo ${HC_TCPIP_MEMBERS} | tr "," " "` |
| 440 | echo '<multicast enabled="false" />' |
| 441 | echo '<tcp-ip enabled="true">' |
| 442 | for member in ${memberarr}; do |
| 443 | echo " <member>${member}</member>" |
| 444 | done |
| 445 | echo '</tcp-ip>' |
| 446 | IFS='' |
| 447 | else |
| 448 | echo '<multicast enabled="true">' |
| 449 | echo " <multicast-group>${HC_MULTICAST_GROUP}</multicast-group>" |
| 450 | echo " <multicast-port>${HC_MULTICAST_PORT}</multicast-port>" |
| 451 | echo '</multicast>' |
| 452 | echo '<tcp-ip enabled="false" />' |
| 453 | fi |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 454 | elif [[ $line =~ __HC_PORT__ ]]; then |
| 455 | echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|" |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 456 | elif [[ $line =~ __HC_CLUSTER__ ]]; then |
| 457 | echo $line | sed -e "s|__HC_CLUSTER__|${ONOS_CLUSTER_NAME}|" |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 458 | else |
| 459 | echo "${line}" |
| 460 | fi |
| 461 | done < ${HC_CONF_TEMPLATE} > ${temp_hc} |
| 462 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 463 | end-conf-creation ${HC_CONF} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 464 | |
| 465 | echo "DONE" |
| 466 | } |
| 467 | |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 468 | function create-ramcloud-conf { |
| 469 | echo -n "Creating ${RAMCLOUD_CONF} ... " |
| 470 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 471 | local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}` |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 472 | |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 473 | local rc_locator=`echo "${ZK_HOSTS}" | sed -e "s/,/:${ZK_CLIENTPORT},/g"` |
| 474 | rc_locator+=":${ZK_CLIENTPORT}" |
| 475 | |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 476 | 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] | 477 | |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 478 | echo "ramcloud.locator=zk:localhost:2181,${rc_locator}" > ${temp_rc} |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 479 | echo "ramcloud.clusterName=${rc_cluster_name}" >> ${temp_rc} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 480 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 481 | end-conf-creation ${RAMCLOUD_CONF} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 482 | |
| 483 | echo "DONE" |
| 484 | } |
| 485 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 486 | function create-logback-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 487 | echo -n "Creating ${ONOS_LOGBACK} ... " |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 488 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 489 | # creation of logback config |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 490 | local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}` |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 491 | |
| 492 | sed -e "s|__FILENAME__|${ONOS_LOG}|" \ |
| 493 | -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] | 494 | |
| 495 | end-conf-creation ${ONOS_LOGBACK} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 496 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 497 | echo "DONE" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 500 | function create-confs { |
| 501 | local key |
| 502 | local filename |
| 503 | |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 504 | trap handle-error ERR |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 505 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 506 | echo "Config file : ${ONOS_CONF}" |
| 507 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 508 | if [ "$1" == "-f" ]; then |
| 509 | create-zk-conf |
| 510 | create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 511 | create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 512 | create-logback-conf |
| 513 | else |
| 514 | create-conf-interactive ${ZK_CONF} create-zk-conf |
| 515 | create-conf-interactive ${HC_CONF} create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 516 | create-conf-interactive ${RAMCLOUD_CONF} create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 517 | create-conf-interactive ${ONOS_LOGBACK} create-logback-conf |
| 518 | fi |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 519 | |
| 520 | trap - ERR |
| 521 | } |
| 522 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 523 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 524 | |
| 525 | ###### Functions related to ZooKeeper ###### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 526 | function zk { |
| 527 | case "$1" in |
| 528 | start) |
Yuta HIGUCHI | d1941ee | 2014-08-06 23:48:03 -0700 | [diff] [blame] | 529 | check-and-start-zk |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 530 | ;; |
| 531 | stop) |
| 532 | stop-zk |
| 533 | ;; |
| 534 | stat*) # <- status |
| 535 | status-zk |
| 536 | ;; |
| 537 | re*) # <- restart |
| 538 | stop-zk |
| 539 | start-zk |
| 540 | ;; |
| 541 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 542 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 543 | exit 1 |
| 544 | esac |
| 545 | } |
| 546 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 547 | function load-zk-cfg { |
| 548 | if [ -f "${ZK_CONF}" ]; then |
| 549 | local filename=`basename ${ZK_CONF}` |
| 550 | local dirname=`dirname ${ZK_CONF}` |
| 551 | |
| 552 | # Run ZooKeeper with our configuration |
| 553 | export ZOOCFG=${filename} |
| 554 | export ZOOCFGDIR=${dirname} |
| 555 | fi |
| 556 | } |
| 557 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 558 | function start-zk { |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 559 | echo -n "Starting ZooKeeper ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 560 | |
Yuta HIGUCHI | d1941ee | 2014-08-06 23:48:03 -0700 | [diff] [blame] | 561 | # CONSOLE output dir |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 562 | export ZOO_LOG_DIR=${ZK_LOG_DIR} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 563 | mkdir -p ${ZK_LOG_DIR} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 564 | |
| 565 | load-zk-cfg |
Yuta HIGUCHI | f66cf21 | 2014-05-29 23:16:44 -0700 | [diff] [blame] | 566 | |
Yuta HIGUCHI | d1941ee | 2014-08-06 23:48:03 -0700 | [diff] [blame] | 567 | # level,appender |
| 568 | export ZOO_LOG4J_PROP="INFO,ROLLINGFILE" |
| 569 | # ROLLINGFILE : ${zookeeper.log.dir}/${zookeeper.log.file} |
| 570 | local server_jvm="-Dzookeeper.log.dir=${LOGDIR} -Dzookeeper.log.file=zk.${ONOS_HOST_NAME}.log" |
| 571 | |
| 572 | pack-rotate-log "${LOGDIR}/zk.${ONOS_HOST_NAME}" "${LOGDIR}/zk.${ONOS_HOST_NAME}.log*" |
| 573 | |
Yuta HIGUCHI | f66cf21 | 2014-05-29 23:16:44 -0700 | [diff] [blame] | 574 | # log4j.properties is read from classpath if not found in CWD. |
| 575 | # Using the ZooKeeper supplied default in ZooKeeper conf dir. |
| 576 | # TODO: To explicitly specify our customized log4j config file: |
| 577 | # export SERVER_JVMFLAGS="-Dlog4j.configuration=${ZK_LOG4J}" |
Yuta HIGUCHI | d1941ee | 2014-08-06 23:48:03 -0700 | [diff] [blame] | 578 | 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] | 579 | } |
| 580 | |
| 581 | function stop-zk { |
Yuta HIGUCHI | 7c70836 | 2014-06-02 23:15:13 -0700 | [diff] [blame] | 582 | echo -n "Stopping ZooKeeper ... " |
| 583 | load-zk-cfg |
| 584 | |
| 585 | ${ZK_HOME}/bin/zkServer.sh stop |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | function status-zk { |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 589 | load-zk-cfg |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 590 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 591 | ${ZK_HOME}/bin/zkServer.sh status |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 592 | } |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 593 | |
| 594 | function check-zk { |
| 595 | # assumption here is that ZK status script is the last command in status-zk. |
| 596 | status-zk &> /dev/null |
| 597 | local zk_status=$? |
| 598 | if [ "$zk_status" -ne 0 ]; then |
| 599 | return 1; |
| 600 | fi |
| 601 | return 0 |
| 602 | } |
| 603 | |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 604 | function check-and-start-zk { |
| 605 | check-zk |
| 606 | local zk_status=$? |
| 607 | if [ "$zk_status" -ne 0 ]; then |
| 608 | start-zk |
Yuta HIGUCHI | d1941ee | 2014-08-06 23:48:03 -0700 | [diff] [blame] | 609 | else |
| 610 | echo "ZooKeeper already running" |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 611 | fi |
| 612 | } |
| 613 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 614 | # wait-zk-or-die {timeout-sec} |
| 615 | function wait-zk-or-die { |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 616 | local retries=${1:-5} |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 617 | # do-while retries >= 0 |
| 618 | while true; do |
| 619 | check-zk |
| 620 | local zk_status=$? |
| 621 | if [ "$zk_status" -eq 0 ]; then |
| 622 | return 0 |
| 623 | fi |
| 624 | sleep 1; |
| 625 | ((retries -= 1)) |
| 626 | (( retries >= 0 )) || break |
| 627 | done |
| 628 | echo "ZooKeeper is not running." |
| 629 | exit 1 |
| 630 | } |
| 631 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 632 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 633 | |
| 634 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 635 | ####### Functions related to RAMCloud ###### |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 636 | |
| 637 | # Check if this host should be running RAMCloud coordinator: |
| 638 | function is-coord-role { |
| 639 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 640 | case "${ONOS_HOST_ROLE}" in |
| 641 | single-node) |
| 642 | echo "true" |
| 643 | return 0 |
| 644 | ;; |
| 645 | coord-node) |
| 646 | echo "true" |
| 647 | return 0 |
| 648 | ;; |
| 649 | server-node) |
| 650 | echo "false" |
| 651 | return 1 |
| 652 | ;; |
| 653 | coord-and-server-node) |
| 654 | echo "true" |
| 655 | return 0 |
| 656 | ;; |
| 657 | *) |
| 658 | echo "false" |
| 659 | return 1 |
| 660 | ;; |
| 661 | esac |
| 662 | else |
| 663 | echo "false" |
| 664 | return 1 |
| 665 | fi |
| 666 | } |
| 667 | |
| 668 | # Check if this host should be running RAMCloud server: |
| 669 | function is-server-role { |
| 670 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 671 | case "${ONOS_HOST_ROLE}" in |
| 672 | single-node) |
| 673 | echo "true" |
| 674 | return 0 |
| 675 | ;; |
| 676 | coord-node) |
| 677 | echo "false" |
| 678 | return 1 |
| 679 | ;; |
| 680 | server-node) |
| 681 | echo "true" |
| 682 | return 0 |
| 683 | ;; |
| 684 | coord-and-server-node) |
| 685 | echo "true" |
| 686 | return 0 |
| 687 | ;; |
| 688 | *) |
| 689 | echo "false" |
| 690 | return 1 |
| 691 | ;; |
| 692 | esac |
| 693 | else |
| 694 | echo "false" |
| 695 | return 1 |
| 696 | fi |
| 697 | } |
| 698 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 699 | function start-backend { |
| 700 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 701 | if [ $1 == "coord" ]; then |
| 702 | rc-coord startifdown |
| 703 | elif [ $1 == "server" ]; then |
| 704 | rc-server startifdown |
| 705 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 706 | fi |
| 707 | } |
| 708 | |
| 709 | function stop-backend { |
| 710 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 711 | if [ $rcsn != 0 ]; then |
| 712 | rc-server stop |
| 713 | fi |
| 714 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 715 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 716 | if [ $rccn != 0 ]; then |
| 717 | rc-coord stop |
| 718 | fi |
| 719 | } |
| 720 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 721 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 722 | ### Functions related to RAMCloud coordinator |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 723 | function rc-coord-addr { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 724 | local host=${RC_COORD_IP} |
| 725 | if [ -z "${host}" ]; then |
| 726 | # falling back to 0.0.0.0 |
| 727 | host="0.0.0.0" |
| 728 | fi |
| 729 | echo "${RC_COORD_PROTOCOL}:host=${host},port=${RC_COORD_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | function rc-server-addr { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 733 | local host=${RC_SERVER_IP} |
| 734 | if [ -z "${host}" ]; then |
| 735 | # falling back to 0.0.0.0 |
| 736 | host="0.0.0.0" |
| 737 | fi |
| 738 | echo "${RC_SERVER_PROTOCOL}:host=${host},port=${RC_SERVER_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 741 | function rc-coord { |
| 742 | case "$1" in |
Yuta HIGUCHI | d91c669 | 2014-08-07 09:43:46 -0700 | [diff] [blame] | 743 | start*) # <- start, startifdown |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 744 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 745 | if [ $n == 0 ]; then |
| 746 | start-coord |
| 747 | else |
| 748 | echo "$n instance of RAMCloud coordinator running" |
| 749 | fi |
| 750 | ;; |
| 751 | stop) |
| 752 | stop-coord |
| 753 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 754 | deldb) |
| 755 | stop-backend |
| 756 | del-coord-info |
| 757 | ;; |
Yuta HIGUCHI | d91c669 | 2014-08-07 09:43:46 -0700 | [diff] [blame] | 758 | re*) # <- restart |
| 759 | stop-coord |
| 760 | start-coord |
| 761 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 762 | stat*) # <- status |
| 763 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
| 764 | echo "$n RAMCloud coordinator running" |
| 765 | ;; |
| 766 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 767 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 768 | exit 1 |
| 769 | esac |
| 770 | } |
| 771 | |
| 772 | function start-coord { |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 773 | check-and-start-zk |
| 774 | wait-zk-or-die |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 775 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 776 | if [ ! -d ${LOGDIR} ]; then |
| 777 | mkdir -p ${LOGDIR} |
| 778 | fi |
| 779 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 780 | rotate-log $RAMCLOUD_COORD_LOG |
| 781 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 782 | |
| 783 | local coord_addr=`rc-coord-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 784 | |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 785 | # TODO Make ONOS_CONF readable from ONOS process then eliminate RAMCLOUD_CONF |
| 786 | |
| 787 | # Configuration for ZK address, port |
| 788 | local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181") |
| 789 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 790 | # RAMCloud cluster name |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 791 | 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] | 792 | |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 793 | # RAMCloud transport timeout |
| 794 | local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 795 | # RAMCloud option deadServerTimeout |
| 796 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 797 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 798 | |
| 799 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 800 | # but actual RAMCloud code only uses -C argument now. |
| 801 | # (FYI: -C is documented to be deprecated in the document) |
| 802 | |
| 803 | local coord_args="-C ${coord_addr}" |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 804 | coord_args="${coord_args} --externalStorage ${rc_locator}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 805 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 806 | coord_args="${coord_args} --timeout ${rc_timeout}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 807 | coord_args="${coord_args} --deadServerTimeout ${rc_coord_deadServerTimeout}" |
| 808 | |
| 809 | # Read environment variables if set |
| 810 | coord_args="${coord_args} ${RC_COORDINATOR_OPTS}" |
| 811 | |
| 812 | if [ "${ONOS_HOST_ROLE}" == "single-node" ]; then |
| 813 | # Note: Following reset is required, since RC restart is considered node failure, |
| 814 | # and tries recovery of server, which will never succeed after restart. |
| 815 | echo "Role configured to single-node mode. RAMCloud cluster will be reset on each start-up." |
| 816 | coord_args="${coord_args} --reset" |
| 817 | fi |
| 818 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 819 | # Run ramcloud |
| 820 | echo -n "Starting RAMCloud coordinator ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 821 | ${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] | 822 | echo "STARTED" |
| 823 | } |
| 824 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 825 | function del-coord-info { |
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 | |
| 829 | if [ ! -d ${LOGDIR} ]; then |
| 830 | mkdir -p ${LOGDIR} |
| 831 | fi |
| 832 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 833 | rotate-log $RAMCLOUD_COORD_LOG |
| 834 | fi |
| 835 | |
| 836 | local coord_addr=`rc-coord-addr` |
| 837 | |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 838 | # Configuration for ZK address, port |
| 839 | local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181") |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 840 | # RAMCloud cluster name |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 841 | 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] | 842 | # RAMCloud option deadServerTimeout |
| 843 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 844 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 845 | |
| 846 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 847 | # but actual RAMCloud code only uses -C argument now. |
| 848 | # (FYI: -C is documented to be deprecated in the document) |
| 849 | |
| 850 | local coord_args="-C ${coord_addr}" |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 851 | coord_args="${coord_args} --externalStorage ${rc_locator}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 852 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
| 853 | |
| 854 | # Note: --reset will reset ZK stored info and start running as acoordinator. |
| 855 | echo -n "Deleting RAMCloud cluster coordination info ... " |
| 856 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} --reset &> $RAMCLOUD_COORD_LOG & |
| 857 | |
Yuta HIGUCHI | cd44eb3 | 2014-05-24 16:51:31 -0700 | [diff] [blame] | 858 | # TODO Assuming 5 sec is enough. To be sure monitor log? |
| 859 | sleep 5 |
| 860 | # kill coordinator |
Yuta HIGUCHI | ce9f3ee | 2014-05-14 09:48:40 -0700 | [diff] [blame] | 861 | (pkill -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator &> /dev/null) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 862 | |
| 863 | echo "DONE" |
| 864 | } |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 865 | |
| 866 | function stop-coord { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 867 | kill-processes "RAMCloud coordinator" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 870 | ### Functions related to RAMCloud server |
| 871 | function rc-server { |
| 872 | case "$1" in |
Yuta HIGUCHI | d91c669 | 2014-08-07 09:43:46 -0700 | [diff] [blame] | 873 | start*) # <- start, startifdown |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 874 | local n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 875 | if [ $n == 0 ]; then |
| 876 | start-server |
| 877 | else |
| 878 | echo "$n instance of RAMCloud server running" |
| 879 | fi |
| 880 | ;; |
| 881 | stop) |
| 882 | stop-server |
| 883 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 884 | deldb) |
| 885 | stop-server |
| 886 | del-server-backup |
| 887 | ;; |
Yuta HIGUCHI | d91c669 | 2014-08-07 09:43:46 -0700 | [diff] [blame] | 888 | re*) # <- restart |
| 889 | stop-server |
| 890 | start-server |
| 891 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 892 | stat*) # <- status |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 893 | n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 894 | echo "$n RAMCloud server running" |
| 895 | ;; |
| 896 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 897 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 898 | exit 1 |
| 899 | esac |
| 900 | } |
| 901 | |
| 902 | function start-server { |
Yuta HIGUCHI | 7873c93 | 2014-06-02 23:16:18 -0700 | [diff] [blame] | 903 | check-and-start-zk |
| 904 | wait-zk-or-die |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 905 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 906 | if [ ! -d ${LOGDIR} ]; then |
| 907 | mkdir -p ${LOGDIR} |
| 908 | fi |
| 909 | if [ -f $RAMCLOUD_SERVER_LOG ]; then |
| 910 | rotate-log $RAMCLOUD_SERVER_LOG |
| 911 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 912 | |
| 913 | local coord_addr=`rc-coord-addr` |
| 914 | local server_addr=`rc-server-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 915 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 916 | local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.server.masterServiceThreads 5) |
| 917 | local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.server.logCleanerThreads 1) |
Yuta HIGUCHI | 52efcbb | 2014-05-16 09:30:33 -0700 | [diff] [blame] | 918 | local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.server.detectFailures 0) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 919 | |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 920 | # Configuration for ZK address, port |
| 921 | local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181") |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 922 | # RAMCloud cluster name |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 923 | 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] | 924 | # RAMCloud transport timeout |
| 925 | local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 926 | # replication factor (-r) config |
| 927 | local rc_replicas=$(read-conf ${ONOS_CONF} ramcloud.server.replicas 0) |
| 928 | # backup file path (-f) config |
| 929 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 930 | mkdir -p `dirname ${rc_datafile}` |
| 931 | |
| 932 | local server_args="-L ${server_addr}" |
Yuta HIGUCHI | d082b96 | 2014-06-02 11:42:22 -0700 | [diff] [blame] | 933 | server_args="${server_args} --externalStorage ${rc_locator}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 934 | server_args="${server_args} --clusterName ${rc_cluster_name}" |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 935 | server_args="${server_args} --timeout ${rc_timeout}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 936 | server_args="${server_args} --masterServiceThreads ${masterServiceThreads}" |
| 937 | server_args="${server_args} --logCleanerThreads ${logCleanerThreads}" |
| 938 | server_args="${server_args} --detectFailures ${detectFailures}" |
| 939 | server_args="${server_args} --replicas ${rc_replicas}" |
| 940 | server_args="${server_args} --file ${rc_datafile}" |
| 941 | |
| 942 | # Read environment variables if set |
| 943 | server_args="${server_args} ${RC_SERVER_OPTS}" |
Yuta HIGUCHI | 45bc3cf | 2014-04-19 18:12:15 -0700 | [diff] [blame] | 944 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 945 | # Run ramcloud |
| 946 | echo -n "Starting RAMCloud server ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 947 | ${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] | 948 | echo "STARTED" |
| 949 | } |
| 950 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 951 | function del-server-backup { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 952 | echo -n "Delete RAMCloud backup server data [y/N]? " |
| 953 | while [ 1 ]; do |
| 954 | read key |
| 955 | if [ "${key}" == "Y" -o "${key}" == "y" ]; then |
| 956 | break |
| 957 | elif [ -z "${key}" -o "${key}" == "N" -o "${key}" == "n" ]; then |
| 958 | echo "Cancelled." |
| 959 | return |
| 960 | fi |
| 961 | echo "[y/N]? " |
| 962 | done |
| 963 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 964 | echo -n "Removing RAMCloud backup server data ... " |
| 965 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 966 | rm -f ${rc_datafile} |
| 967 | echo "DONE" |
| 968 | } |
| 969 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 970 | function stop-server { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 971 | kill-processes "RAMCloud server" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 972 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 973 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 974 | |
| 975 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 976 | ## Functions related to ONOS core process ## |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 977 | function onos { |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 978 | |
| 979 | case "$1" in |
Yuta HIGUCHI | d91c669 | 2014-08-07 09:43:46 -0700 | [diff] [blame] | 980 | start*) # <- start, startnokill, startifdown |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 981 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 982 | if [ $n == 0 ]; then |
| 983 | start-onos |
| 984 | else |
| 985 | echo "$n instance of onos running" |
| 986 | fi |
| 987 | ;; |
Yuta HIGUCHI | d91c669 | 2014-08-07 09:43:46 -0700 | [diff] [blame] | 988 | unchecked-start) |
| 989 | start-onos |
| 990 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 991 | stop) |
| 992 | stop-onos |
| 993 | ;; |
Yuta HIGUCHI | d91c669 | 2014-08-07 09:43:46 -0700 | [diff] [blame] | 994 | re*) # <- restart |
| 995 | stop-onos |
| 996 | start-onos |
| 997 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 998 | stat*) # <- status |
| 999 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 1000 | echo "$n instance of onos running" |
| 1001 | ;; |
| 1002 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1003 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1004 | exit 1 |
| 1005 | esac |
| 1006 | } |
| 1007 | |
| 1008 | function start-onos { |
Yuta HIGUCHI | 5f14b01 | 2014-07-18 19:14:04 -0700 | [diff] [blame] | 1009 | |
| 1010 | JAVA_CP="" |
| 1011 | CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME} |
| 1012 | if [ ! -f ${MAIN_CLASS_FILE} ]; then |
| 1013 | # No .class |
| 1014 | if [ -f ${ONOS_JAR} ]; then |
| 1015 | echo "Starting ONOS using packaged jar file" |
| 1016 | JAVA_CP="${JAVA_CP}:${ONOS_JAR}" |
| 1017 | else |
| 1018 | echo "Building ONOS from source" |
| 1019 | ${MVN} -f ${ONOS_HOME}/pom.xml compile -T 1C |
| 1020 | fi |
| 1021 | else |
| 1022 | # .class exists |
| 1023 | if [ ! -f ${CPFILE} ]; then |
| 1024 | echo "Building ONOS dependency classpath" |
| 1025 | ${MVN} -f ${ONOS_HOME}/pom.xml -T 1C dependency:go-offline -Dsilent dependency:build-classpath -Dmdep.outputFile=${CPFILE} |
| 1026 | fi |
| 1027 | fi |
| 1028 | if [ -f ${CPFILE} ]; then |
| 1029 | JAVA_CP="${JAVA_CP}:`cat ${CPFILE}`" |
| 1030 | fi |
| 1031 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
| 1032 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1033 | if [ ! -d ${LOGDIR} ]; then |
| 1034 | mkdir -p ${LOGDIR} |
| 1035 | fi |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 1036 | # Rotate log files |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1037 | for log in ${LOGS}; do |
| 1038 | if [ -f ${log} ]; then |
| 1039 | rotate-log ${log} |
| 1040 | fi |
| 1041 | done |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 1042 | |
| 1043 | # Rotate logs rolled at runtime. |
| 1044 | local rolled_log_shellpat=`echo ${ONOS_LOG_ROLLING_PATTERN} | sed -e "s/%i/\\*/"` |
| 1045 | for rolled_log in ${rolled_log_shellpat}; do |
| 1046 | if [ -f ${rolled_log} ]; then |
| 1047 | rotate-log ${rolled_log} |
Yuta HIGUCHI | 0471397 | 2014-05-30 11:01:17 -0700 | [diff] [blame] | 1048 | fi |
| 1049 | done |
| 1050 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1051 | if [ ! -f ${ONOS_LOGBACK} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1052 | echo "[WARNING] ${ONOS_LOGBACK} not found." |
| 1053 | echo " Run \"\$ $0 setup\" to create." |
| 1054 | exit 1 |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1055 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1056 | |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 1057 | if [ ! -f ${HC_CONF} ]; then |
| 1058 | echo "[WARNING] ${HC_CONF} not found." |
| 1059 | echo " Run \"\$ $0 setup\" to create." |
| 1060 | exit 1 |
| 1061 | fi |
| 1062 | |
Yuta HIGUCHI | 85de40d | 2014-06-12 14:06:41 -0700 | [diff] [blame] | 1063 | # specify ZooKeeper(curator) namespace |
| 1064 | JVM_OPTS="${JVM_OPTS} -Dzookeeper.namespace=${ONOS_CLUSTER_NAME}" |
| 1065 | |
Yuta HIGUCHI | 5f1ce1c | 2014-07-20 22:43:54 -0700 | [diff] [blame] | 1066 | # specify ZooKeeper connectionString |
| 1067 | local zk_locator=`echo "${ZK_HOSTS}" | sed -e "s/,/:${ZK_CLIENTPORT},/g"` |
| 1068 | zk_locator+=":${ZK_CLIENTPORT}" |
| 1069 | zk_locator="localhost:${ZK_CLIENTPORT},${zk_locator}" |
| 1070 | |
| 1071 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.registry.ZookeeperRegistry.connectionString=${zk_locator}" |
| 1072 | |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 1073 | # specify hazelcast.xml to datagrid |
| 1074 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig=${HC_CONF}" |
| 1075 | |
| 1076 | # specify backend config |
Jonathan Hart | ef3dc1a | 2014-04-03 11:39:50 -0700 | [diff] [blame] | 1077 | 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] | 1078 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 1079 | JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}" |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 1080 | elif [ "${ONOS_HOST_BACKEND}" = "hazelcast" ]; then |
| 1081 | 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] | 1082 | fi |
| 1083 | |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 1084 | # check for jvm debug flag |
Yuta HIGUCHI | 32532ea | 2014-08-01 15:52:55 -0700 | [diff] [blame] | 1085 | if [ "${ONOS_DEBUG}" == "true" ]; then |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 1086 | JVM_OPTS="${JVM_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${JVM_DEBUG_PORT}" |
| 1087 | fi |
| 1088 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1089 | # Run ONOS |
Yuta HIGUCHI | cce4f62 | 2014-04-18 16:48:53 -0700 | [diff] [blame] | 1090 | |
| 1091 | # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD |
| 1092 | cd ${ONOS_HOME} |
| 1093 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 1094 | echo -n "Starting ONOS controller ... " |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1095 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr & |
| 1096 | |
| 1097 | # We need to wait a bit to find out whether starting the ONOS process succeeded |
| 1098 | sleep 1 |
| 1099 | |
| 1100 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1101 | if [ $n -ge 1 ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1102 | echo " STARTED" |
| 1103 | else |
| 1104 | echo " FAILED" |
| 1105 | fi |
| 1106 | |
| 1107 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 1108 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 1109 | } |
| 1110 | |
| 1111 | function stop-onos { |
| 1112 | kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'` |
| 1113 | # kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 1114 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1115 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1116 | |
| 1117 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1118 | ################## Main #################### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1119 | case "$1" in |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1120 | setup) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 1121 | create-confs $2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1122 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1123 | start) |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1124 | mode_parameter=${ONOS_HOST_ROLE} |
| 1125 | if [ ! -z "$2" ]; then |
| 1126 | mode_parameter=$2 |
| 1127 | fi |
Praseed Balakrishnan | 418c7b2 | 2014-06-16 13:33:53 -0700 | [diff] [blame] | 1128 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1129 | case "${mode_parameter}" in |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1130 | single-node) |
| 1131 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1132 | start-backend coord |
| 1133 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1134 | onos startifdown |
| 1135 | ;; |
| 1136 | coord-node) |
| 1137 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1138 | start-backend coord |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1139 | onos startifdown |
| 1140 | ;; |
| 1141 | server-node) |
| 1142 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1143 | start-backend server |
| 1144 | onos startifdown |
| 1145 | ;; |
| 1146 | coord-and-server-node) |
| 1147 | zk start |
| 1148 | start-backend coord |
| 1149 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1150 | onos startifdown |
| 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 | ;; |
| 1155 | esac |
| 1156 | echo |
| 1157 | ;; |
| 1158 | stop) |
| 1159 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 1160 | if [ $on != 0 ]; then |
| 1161 | onos stop |
| 1162 | fi |
| 1163 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 1164 | stop-backend |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1165 | |
| 1166 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 1167 | if [ $zkn != 0 ]; then |
| 1168 | zk stop |
| 1169 | fi |
| 1170 | echo |
| 1171 | ;; |
| 1172 | restart) |
| 1173 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 1174 | if [ $on != 0 ]; then |
| 1175 | onos stop |
| 1176 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1177 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1178 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 1179 | if [ $rcsn != 0 ]; then |
| 1180 | rc-server stop |
| 1181 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1182 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1183 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1184 | if [ $rccn != 0 ]; then |
| 1185 | rc-coord stop |
| 1186 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1187 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1188 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 1189 | if [ $zkn != 0 ]; then |
| 1190 | zk restart |
| 1191 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1192 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1193 | if [ $rccn != 0 ]; then |
| 1194 | rc-coord startifdown |
| 1195 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1196 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1197 | if [ $rcsn != 0 ]; then |
| 1198 | rc-server startifdown |
| 1199 | fi |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1200 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1201 | if [ $on != 0 ]; then |
| 1202 | onos startifdown |
| 1203 | fi |
| 1204 | echo |
| 1205 | ;; |
| 1206 | stat*) # <- status |
| 1207 | echo '[ZooKeeper]' |
| 1208 | zk status |
| 1209 | echo |
| 1210 | echo '[RAMCloud coordinator]' |
| 1211 | rc-coord status |
| 1212 | echo |
| 1213 | echo '[RAMCloud server]' |
| 1214 | rc-server status |
| 1215 | echo |
| 1216 | echo '[ONOS core]' |
| 1217 | onos status |
| 1218 | echo |
| 1219 | ;; |
| 1220 | zk) |
| 1221 | zk $2 |
| 1222 | ;; |
| 1223 | rc-c*) # <- rc-coordinator |
| 1224 | rc-coord $2 |
| 1225 | ;; |
| 1226 | rc-s*) # <- rc-server |
| 1227 | rc-server $2 |
| 1228 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 1229 | rc) |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1230 | # XXX rc command ignores if the host is not configured to have those roles, |
| 1231 | # while rc-s or rc-c executes the task regardless of role definition. |
| 1232 | # This is a workaround since TestON does not take role in account |
| 1233 | # and always issue rc deldb right now. |
| 1234 | |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 1235 | # TODO make deldb command more organized (clarify when it can work) |
Yuta HIGUCHI | 259b79a | 2014-06-04 12:21:22 -0700 | [diff] [blame] | 1236 | if [ "`is-coord-role`" == "true" ]; then |
| 1237 | rc-coord $2 |
| 1238 | fi |
| 1239 | if [ "`is-server-role`" == "true" ]; then |
| 1240 | rc-server $2 |
| 1241 | fi |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 1242 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1243 | core) |
| 1244 | onos $2 |
| 1245 | ;; |
| 1246 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1247 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1248 | exit 1 |
| 1249 | esac |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 1250 | |