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