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