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