blob: 1db93d582719487fa944659bdd145b152f773de3 [file] [log] [blame]
Naoki Shiota4e463182014-03-21 15:13:24 -07001#!/bin/bash
Naoki Shiota4e463182014-03-21 15:13:24 -07002
Naoki Shiota590c18d2014-03-31 17:52:59 -07003### 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 Shiota9a1e6d12014-04-03 14:47:12 -07006# $ONOS_CONF : path of ONOS node config file (~/ONOS/conf/onos_node.`hostname`.conf or onos_node.conf)
Naoki Shiota590c18d2014-03-31 17:52:59 -07007# $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 Shiotad8ea71a2014-04-23 17:04:51 -07009# $ONOS_LOGDIR : path of log output directory (~/ONOS/onos-logs)
10# $ONOS_LOGBASE : base name of log output file (onos.`hostname`)
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -070011# $ONOS_DEBUG : option to enable debugger for ONOS (false)
Naoki Shiota590c18d2014-03-31 17:52:59 -070012# $RAMCLOUD_HOME : path of root directory of RAMCloud repository (~/ramcloud)
13# $RAMCLOUD_BRANCH : branch name of RAMCloud to use (master)
Yuta HIGUCHIfb1905a2014-06-09 14:07:34 -070014# $ZK_HOME : path of root directory of ZooKeeper (~/zookeeper-3.4.6)
Naoki Shiota72209722014-04-08 14:32:17 -070015# $ZK_LIB_DIR : path of ZooKeeper library (/var/lib/zookeeper)
Naoki Shiotad8ea71a2014-04-23 17:04:51 -070016# $ZK_LOG_DIR : path of ZooKeeper log output directory (~/ONOS/onos-logs/zk-`hostname`)
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -070017# $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 Shiotab7eb55d2014-04-21 18:21:36 -070019# $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 Shiota590c18d2014-03-31 17:52:59 -070022#####################################################
23
Naoki Shiota590c18d2014-03-31 17:52:59 -070024ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)}
Naoki Shiota9df15d32014-03-27 14:26:20 -070025ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf}
Naoki Shiota9a1e6d12014-04-03 14:47:12 -070026ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.`hostname`.conf}
Naoki Shiota590c18d2014-03-31 17:52:59 -070027
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070028source ${ONOS_HOME}/scripts/common/utils.sh
29
Yuta HIGUCHIe748ecc2014-05-28 13:55:03 -070030confirm-if-root
31
Naoki Shiota590c18d2014-03-31 17:52:59 -070032if [ ! -f ${ONOS_CONF} ]; then
Naoki Shiota9a1e6d12014-04-03 14:47:12 -070033 # 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 Shiota590c18d2014-03-31 17:52:59 -070039fi
Naoki Shiota4e928512014-04-03 15:49:35 -070040
Naoki Shiota4e928512014-04-03 15:49:35 -070041### Variables read from ONOS config file ###
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -070042ONOS_CLUSTER_NAME=$(read-conf ${ONOS_CONF} onos.cluster.name "onos")
Naoki Shiota4e928512014-04-03 15:49:35 -070043ONOS_HOST_NAME=$(read-conf ${ONOS_CONF} host.name `hostname`)
44ONOS_HOST_IP=$(read-conf ${ONOS_CONF} host.ip)
45ONOS_HOST_ROLE=$(read-conf ${ONOS_CONF} host.role)
46ONOS_HOST_BACKEND=$(read-conf ${ONOS_CONF} host.backend)
47ZK_HOSTS=$(read-conf ${ONOS_CONF} zookeeper.hosts ${ONOS_HOST_NAME})
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -070048ZK_CLIENTPORT=$(read-conf ${ONOS_CONF} zookeeper.clientPort 2181)
49ZK_PORTS=$(read-conf ${ONOS_CONF} zookeeper.ports 2888:3888)
Naoki Shiota4e928512014-04-03 15:49:35 -070050RC_COORD_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.coordinator.protocol "fast+udp")
51RC_COORD_IP=$(read-conf ${ONOS_CONF} ramcloud.coordinator.ip ${ONOS_HOST_IP})
52RC_COORD_PORT=$(read-conf ${ONOS_CONF} ramcloud.coordinator.port 12246)
53RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp")
54RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP})
55RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242)
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070056HC_HOST_PORT=$(read-conf ${ONOS_CONF} hazelcast.host.port 5701)
Naoki Shiota4e928512014-04-03 15:49:35 -070057HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members)
58HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3")
59HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327)
Naoki Shiota590c18d2014-03-31 17:52:59 -070060############################################
61
62
63############## Other variables #############
Naoki Shiota4e928512014-04-03 15:49:35 -070064ONOS_TEMPLATE_DIR=${ONOS_CONF_DIR}/template
65
Naoki Shiota4e463182014-03-21 15:13:24 -070066LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
67
Yuta HIGUCHIfb1905a2014-06-09 14:07:34 -070068ZK_HOME=${ZK_HOME:-~/zookeeper-3.4.6}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070069ZK_CONF=${ZK_CONF:-${ONOS_CONF_DIR}/zoo.cfg}
Naoki Shiota4e928512014-04-03 15:49:35 -070070ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -070071# Adding ONOS_HOST_NAME dir since file name (zookeeper.out) cannot be controlled.
Naoki Shiotad8ea71a2014-04-23 17:04:51 -070072ZK_LOG_DIR=${ZK_LOG_DIR:-${ONOS_HOME}/onos-logs/zk-${ONOS_HOST_NAME}}
Naoki Shiota72209722014-04-08 14:32:17 -070073ZK_LIB_DIR=${ZK_LIB_DIR:-/var/lib/zookeeper}
Naoki Shiota9df15d32014-03-27 14:26:20 -070074ZK_MY_ID=${ZK_LIB_DIR}/myid
Naoki Shiota4e463182014-03-21 15:13:24 -070075
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070076HC_CONF=${HC_CONF:-${ONOS_CONF_DIR}/hazelcast.xml}
Naoki Shiota4e928512014-04-03 15:49:35 -070077HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template
78
Naoki Shiota4e463182014-03-21 15:13:24 -070079RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
Naoki Shiota590c18d2014-03-31 17:52:59 -070080RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log
81RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log
Naoki Shiota4e463182014-03-21 15:13:24 -070082RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070083RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_CONF_DIR}/ramcloud.conf}
Naoki Shiota4e463182014-03-21 15:13:24 -070084
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -070085export LD_LIBRARY_PATH=${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}:$LD_LIBRARY_PATH
Naoki Shiota4e463182014-03-21 15:13:24 -070086
87## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME
Naoki Shiota590c18d2014-03-31 17:52:59 -070088ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_CONF_DIR}/logback.${ONOS_HOST_NAME}.xml}
Naoki Shiota9df15d32014-03-27 14:26:20 -070089ONOS_LOGBACK_BACKUP=${ONOS_LOGBACK}.bak
Naoki Shiota4e928512014-04-03 15:49:35 -070090ONOS_LOGBACK_TEMPLATE=${ONOS_TEMPLATE_DIR}/logback.xml.template
Naoki Shiota4e463182014-03-21 15:13:24 -070091LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
Naoki Shiota590c18d2014-03-31 17:52:59 -070092LOGBASE=${ONOS_LOGBASE:-onos.${ONOS_HOST_NAME}}
Naoki Shiota4e463182014-03-21 15:13:24 -070093ONOS_LOG="${LOGDIR}/${LOGBASE}.log"
Yuta HIGUCHI04713972014-05-30 11:01:17 -070094ONOS_LOG_ROLLING_PATTERN="${LOGDIR}/${LOGBASE}.%i.log.gz"
95ONOS_STDOUT_LOG="${LOGDIR}/${LOGBASE}.stdout"
96ONOS_STDERR_LOG="${LOGDIR}/${LOGBASE}.stderr"
Naoki Shiota4e463182014-03-21 15:13:24 -070097PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap"
Yuta HIGUCHI04713972014-05-30 11:01:17 -070098LOGS="$ONOS_LOG $ONOS_STDOUT_LOG $ONOS_STDERR_LOG $PCAP_LOG"
Naoki Shiota4e463182014-03-21 15:13:24 -070099
Naoki Shiota9df15d32014-03-27 14:26:20 -0700100ONOS_PROPS=${ONOS_PROPS:-${ONOS_CONF_DIR}/onos.properties}
Naoki Shiota4e463182014-03-21 15:13:24 -0700101JMX_PORT=${JMX_PORT:-7189}
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -0700102JVM_DEBUG_PORT=${JVM_DEBUG_PORT:-22007}
Naoki Shiota4e463182014-03-21 15:13:24 -0700103
104# Set JVM options
105JVM_OPTS="${JVM_OPTS:-}"
Naoki Shiota4e463182014-03-21 15:13:24 -0700106JVM_OPTS="$JVM_OPTS -server -d64"
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700107
108# TODO Revisit appropriate CodeCache size
109JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700110
111# Uncomment or specify appropriate value as JVM_OPTS environment variables.
112#JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
Naoki Shiota4e463182014-03-21 15:13:24 -0700113#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
114#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700115
116#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC"
117JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC"
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700118#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 HIGUCHI18354592014-04-01 13:53:42 -0700122JVM_OPTS="$JVM_OPTS -XX:+AggressiveOpts"
123
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700124# TODO We may want to remove UseFastAccessorMethods option: http://bugs.java.com/view_bug.do?bug_id=6385687
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700125JVM_OPTS="$JVM_OPTS -XX:+UseFastAccessorMethods"
126
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700127# TODO revisit these derived from floodlight
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700128JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192"
129JVM_OPTS="$JVM_OPTS -XX:FreqInlineSize=8192"
130JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500"
131
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700132# FIXME Specify appropriate cmd to handle fatal crash
133# http://www.oracle.com/technetwork/java/javase/clopts-139448.html#gbmum
Naoki Shiota4e463182014-03-21 15:13:24 -0700134JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700135#JVM_OPTS="$JVM_OPTS -XX:+ShowMessageBoxOnError"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700136
Praseed Balakrishnan4fe80812014-07-24 11:29:19 -0700137# 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
139JVM_OPTS="$JVM_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${ONOS_HOME}"
140
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700141# Workaround for Thread Priority http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html
142JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42"
143
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700144JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT"
145JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false"
146JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
147
Yuta HIGUCHI6bcaf982014-07-30 15:49:58 -0700148JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j -Dhazelcast.jmx=true -Dhazelcast.jmx.detailed=true"
Naoki Shiota4e463182014-03-21 15:13:24 -0700149
Yuta HIGUCHIc248d0d2014-07-30 16:14:18 -0700150# TODO revisit HZ related magic numbers
151# HZ Default:1000000
152JVM_OPTS="$JVM_OPTS -Dhazelcast.event.queue.capacity=4000000"
153# HZ Default:32 (KB)
154JVM_OPTS="$JVM_OPTS -Dhazelcast.socket.receive.buffer.size=4096"
155# HZ Default:32 (KB)
156JVM_OPTS="$JVM_OPTS -Dhazelcast.socket.send.buffer.size=4096"
157
158
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700159if [ "${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"
175fi
176
177# dump final JVM flags to stdout
178JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700179
Naoki Shiota4e463182014-03-21 15:13:24 -0700180# Set ONOS core main class
Jonathan Hart51f6f5b2014-04-03 10:32:10 -0700181MAIN_CLASS="net.onrc.onos.core.main.Main"
Naoki Shiota4e463182014-03-21 15:13:24 -0700182
183MVN=${MVN:-mvn -o}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700184############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700185
Naoki Shiota9df15d32014-03-27 14:26:20 -0700186
Naoki Shiota590c18d2014-03-31 17:52:59 -0700187############# Common functions #############
188function print_usage {
Naoki Shiota05721b32014-04-29 14:41:12 -0700189 local scriptname=`basename $0`
Naoki Shiota590c18d2014-03-31 17:52:59 -0700190 local filename=`basename ${ONOS_CONF}`
191 local usage="Usage: setup/start/stop ONOS on this server.
Naoki Shiota05721b32014-04-29 14:41:12 -0700192 \$ ${scriptname} setup [-f]
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700193 Set up ONOS node using ${ONOS_CONF} .
Naoki Shiota590c18d2014-03-31 17:52:59 -0700194 - generate and replace config file of ZooKeeper.
195 - create myid in ZooKeeper datadir.
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700196 - generate and replace config file for Hazelcast.
197 - generate and replace config file for RAMCloud.
Naoki Shiota590c18d2014-03-31 17:52:59 -0700198 - generate and replace logback.${ONOS_HOST_NAME}.xml
199 If -f option is used, all existing files will be overwritten without confirmation.
Naoki Shiota05721b32014-04-29 14:41:12 -0700200 \$ ${scriptname} start [single-node|coord-node|server-node|coord-and-server-node]
Naoki Shiota590c18d2014-03-31 17:52:59 -0700201 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 Shiota05721b32014-04-29 14:41:12 -0700207 \$ ${scriptname} stop
Naoki Shiota590c18d2014-03-31 17:52:59 -0700208 Stop all ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700209 \$ ${scriptname} restart
Naoki Shiota590c18d2014-03-31 17:52:59 -0700210 Stop and start currently running ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700211 \$ ${scriptname} status
Naoki Shiota590c18d2014-03-31 17:52:59 -0700212 Show status of ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700213 \$ ${scriptname} {zk|rc-coord|rc-server|core} {start|stop|restart|status}
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700214 Control specific ONOS-related process
215 \$ ${scriptname} rc deldb
216 Delete data in RAMCloud"
Naoki Shiota590c18d2014-03-31 17:52:59 -0700217
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700218 echo "${usage}"
Naoki Shiota4e463182014-03-21 15:13:24 -0700219}
220
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700221# 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 Shiota4e463182014-03-21 15:13:24 -0700226function rotate-log {
Naoki Shiota4e928512014-04-03 15:49:35 -0700227 local logfile=$1
228 local nr_max=${2:-10}
229 if [ -f $logfile ]; then
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700230 # 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 Shiota4e928512014-04-03 15:49:35 -0700236 for i in `seq $(expr $nr_max - 1) -1 1`; do
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700237 if [ -f ${basename}.${i}${append} ]; then
238 mv -f ${basename}.${i}${append} ${basename}.`expr $i + 1`${append}
Naoki Shiota4e928512014-04-03 15:49:35 -0700239 fi
240 done
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700241 mv ${basename}${append} ${basename}.1${append}
Naoki Shiota4e928512014-04-03 15:49:35 -0700242 fi
Naoki Shiota4e463182014-03-21 15:13:24 -0700243}
244
245# kill-processes {module-name} {array of pids}
246function kill-processes {
247 # Kill the existing processes
248 local pids=$2
Naoki Shiota9df15d32014-03-27 14:26:20 -0700249 if [ ! -z "$pids" ]; then
Naoki Shiota4e463182014-03-21 15:13:24 -0700250 echo -n "Stopping $1 ... "
251 fi
252 for p in ${pids}; do
253 if [ x$p != "x" ]; then
Naoki Shiota4b355762014-05-27 11:46:43 -0700254 # 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 HIGUCHId150ece2014-04-29 16:25:36 -0700264 (
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 Shiota4b355762014-05-27 11:46:43 -0700269
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 Shiota4e463182014-03-21 15:13:24 -0700281 fi
282 done
283}
284
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700285function handle-error {
286 set -e
287
288 revert-confs
289
290 set +e
291
292 exit 1
293}
294
Naoki Shiota4e928512014-04-03 15:49:35 -0700295# revert-confs [error message]
296function revert-confs {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700297 echo -n "ERROR occurred ... "
Naoki Shiota9df15d32014-03-27 14:26:20 -0700298
Naoki Shiota4e928512014-04-03 15:49:35 -0700299 revert-file `basename ${ZK_CONF}`
300 revert-file `basename ${HC_CONF}`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700301
302 echo "EXIT"
303
304 if [ ! -z "$1" ]; then
305 echo $1
306 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700307}
308
Naoki Shiota590c18d2014-03-31 17:52:59 -0700309function create-zk-conf {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700310 echo -n "Creating ${ZK_CONF} ... "
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700311
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700312 # Create the ZooKeeper lib directory
Yuta HIGUCHIb3983b12014-06-12 14:21:09 -0700313 if [[ ! ( -w ${ZK_LIB_DIR} && -d ${ZK_LIB_DIR} ) ]]; then
Naoki Shiota7f495cf2014-05-21 17:23:25 -0700314 local SUDO=${SUDO:-sudo}
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700315 local whoami=`whoami`
316 {
Yuta HIGUCHIb3983b12014-06-12 14:21:09 -0700317 ${SUDO} mkdir -p ${ZK_LIB_DIR}
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700318 ${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 Shiotab7eb55d2014-04-21 18:21:36 -0700328 local temp_zk=`begin-conf-creation ${ZK_CONF}`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700329
Naoki Shiota4e928512014-04-03 15:49:35 -0700330 hostarr=`echo ${ZK_HOSTS} | tr "," " "`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700331
332 local i=1
333 local myid=
334 for host in ${hostarr}; do
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700335 if [ "${host}" = "${ONOS_HOST_NAME}" -o "${host}" = "${ONOS_HOST_IP}" ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700336 myid=$i
337 break
338 fi
339 i=`expr $i + 1`
340 done
341
342 if [ -z "${myid}" ]; then
Naoki Shiota590c18d2014-03-31 17:52:59 -0700343 local filename=`basename ${ONOS_CONF}`
Naoki Shiota35f8d5c2014-04-08 11:13:18 -0700344 revert-confs "[ERROR] In ${filename}, zookeeper.hosts must have hostname \"${ONOS_HOST_NAME}\" or IP address"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700345 fi
346
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700347 if [ -f "${ZK_MY_ID}" ]; then
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700348 # sudo will be needed if ZK_MY_ID is already created by other (old) script
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700349 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 Radoslavovd8f30d92014-04-18 13:03:09 -0700355 echo "[ERROR] Please retry after setting \"env SUDO=sudo\""
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700356 exit 1
357 }
358 fi
359
Naoki Shiota9df15d32014-03-27 14:26:20 -0700360 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 HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700368 # TODO: ZK ports should be configurable per host
369 local hostline="server.${i}=${host}:${ZK_PORTS}"
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700370 echo $hostline
Naoki Shiota9df15d32014-03-27 14:26:20 -0700371 i=`expr $i + 1`
372 done
373 elif [[ $line =~ __DATADIR__ ]]; then
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700374 echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700375 else
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700376 echo $line
Naoki Shiota9df15d32014-03-27 14:26:20 -0700377 fi
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700378 done < ${ZK_CONF_TEMPLATE} > ${temp_zk}
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700379 sed -e "s|__CLIENTPORT__|${ZK_CLIENTPORT}|" -i "" ${temp_zk}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700380
381 end-conf-creation ${ZK_CONF}
Naoki Shiota9df15d32014-03-27 14:26:20 -0700382
383 echo "DONE"
Naoki Shiota590c18d2014-03-31 17:52:59 -0700384}
Naoki Shiota9df15d32014-03-27 14:26:20 -0700385
Naoki Shiota4e928512014-04-03 15:49:35 -0700386function create-hazelcast-conf {
387 echo -n "Creating ${HC_CONF} ... "
388
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700389 local temp_hc=`begin-conf-creation ${HC_CONF}`
Naoki Shiota4e928512014-04-03 15:49:35 -0700390
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 Shiotab7eb55d2014-04-21 18:21:36 -0700413 elif [[ $line =~ __HC_PORT__ ]]; then
414 echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|"
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700415 elif [[ $line =~ __HC_CLUSTER__ ]]; then
416 echo $line | sed -e "s|__HC_CLUSTER__|${ONOS_CLUSTER_NAME}|"
Naoki Shiota4e928512014-04-03 15:49:35 -0700417 else
418 echo "${line}"
419 fi
420 done < ${HC_CONF_TEMPLATE} > ${temp_hc}
421
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700422 end-conf-creation ${HC_CONF}
Naoki Shiota4e928512014-04-03 15:49:35 -0700423
424 echo "DONE"
425}
426
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700427function create-ramcloud-conf {
428 echo -n "Creating ${RAMCLOUD_CONF} ... "
429
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700430 local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}`
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700431
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700432 local rc_locator=`echo "${ZK_HOSTS}" | sed -e "s/,/:${ZK_CLIENTPORT},/g"`
433 rc_locator+=":${ZK_CLIENTPORT}"
434
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700435 local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700436
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700437 echo "ramcloud.locator=zk:localhost:2181,${rc_locator}" > ${temp_rc}
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700438 echo "ramcloud.clusterName=${rc_cluster_name}" >> ${temp_rc}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700439
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700440 end-conf-creation ${RAMCLOUD_CONF}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700441
442 echo "DONE"
443}
444
Naoki Shiota590c18d2014-03-31 17:52:59 -0700445function create-logback-conf {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700446 echo -n "Creating ${ONOS_LOGBACK} ... "
Naoki Shiota590c18d2014-03-31 17:52:59 -0700447
Naoki Shiota9df15d32014-03-27 14:26:20 -0700448 # creation of logback config
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700449 local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}`
Yuta HIGUCHI04713972014-05-30 11:01:17 -0700450
451 sed -e "s|__FILENAME__|${ONOS_LOG}|" \
452 -e "s|__ROLLING_PATTERN__|${ONOS_LOG_ROLLING_PATTERN}|" ${ONOS_LOGBACK_TEMPLATE} > ${temp_lb}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700453
454 end-conf-creation ${ONOS_LOGBACK}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700455
Naoki Shiota9df15d32014-03-27 14:26:20 -0700456 echo "DONE"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700457}
458
Naoki Shiota4e928512014-04-03 15:49:35 -0700459function create-confs {
460 local key
461 local filename
462
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700463 trap handle-error ERR
Naoki Shiota4e928512014-04-03 15:49:35 -0700464
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700465 echo "Config file : ${ONOS_CONF}"
466
Naoki Shiota4e928512014-04-03 15:49:35 -0700467 if [ "$1" == "-f" ]; then
468 create-zk-conf
469 create-hazelcast-conf
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700470 create-ramcloud-conf
Naoki Shiota4e928512014-04-03 15:49:35 -0700471 create-logback-conf
472 else
473 create-conf-interactive ${ZK_CONF} create-zk-conf
474 create-conf-interactive ${HC_CONF} create-hazelcast-conf
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700475 create-conf-interactive ${RAMCLOUD_CONF} create-ramcloud-conf
Naoki Shiota4e928512014-04-03 15:49:35 -0700476 create-conf-interactive ${ONOS_LOGBACK} create-logback-conf
477 fi
Naoki Shiota590c18d2014-03-31 17:52:59 -0700478
479 trap - ERR
480}
481############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700482
Naoki Shiota590c18d2014-03-31 17:52:59 -0700483
484###### Functions related to ZooKeeper ######
Naoki Shiota4e463182014-03-21 15:13:24 -0700485function 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 Shiota590c18d2014-03-31 17:52:59 -0700501 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700502 exit 1
503 esac
504}
505
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700506function 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 Shiota4e463182014-03-21 15:13:24 -0700517function start-zk {
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700518 echo -n "Starting ZooKeeper ... "
Naoki Shiota9df15d32014-03-27 14:26:20 -0700519
Naoki Shiota4e928512014-04-03 15:49:35 -0700520 export ZOO_LOG_DIR=${ZK_LOG_DIR}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700521 mkdir -p ${ZK_LOG_DIR}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700522
523 load-zk-cfg
Yuta HIGUCHIf66cf212014-05-29 23:16:44 -0700524
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 Shiota4e463182014-03-21 15:13:24 -0700530}
531
532function stop-zk {
Yuta HIGUCHI7c708362014-06-02 23:15:13 -0700533 echo -n "Stopping ZooKeeper ... "
534 load-zk-cfg
535
536 ${ZK_HOME}/bin/zkServer.sh stop
Naoki Shiota4e463182014-03-21 15:13:24 -0700537}
538
539function status-zk {
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700540 load-zk-cfg
Naoki Shiota9df15d32014-03-27 14:26:20 -0700541
Naoki Shiota72209722014-04-08 14:32:17 -0700542 ${ZK_HOME}/bin/zkServer.sh status
Naoki Shiota4e463182014-03-21 15:13:24 -0700543}
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700544
545function 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 HIGUCHI7873c932014-06-02 23:16:18 -0700555function 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 HIGUCHId150ece2014-04-29 16:25:36 -0700563# wait-zk-or-die {timeout-sec}
564function wait-zk-or-die {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700565 local retries=${1:-5}
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700566 # 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 Shiota590c18d2014-03-31 17:52:59 -0700581############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700582
583
Naoki Shiota590c18d2014-03-31 17:52:59 -0700584####### Functions related to RAMCloud ######
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -0700585
586# Check if this host should be running RAMCloud coordinator:
587function 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:
618function 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 Shiota9df15d32014-03-27 14:26:20 -0700648function start-backend {
649 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
Naoki Shiota590c18d2014-03-31 17:52:59 -0700650 if [ $1 == "coord" ]; then
651 rc-coord startifdown
652 elif [ $1 == "server" ]; then
653 rc-server startifdown
654 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700655 fi
656}
657
658function 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 Shiota590c18d2014-03-31 17:52:59 -0700664 rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700665 if [ $rccn != 0 ]; then
666 rc-coord stop
667 fi
668}
669
Naoki Shiota590c18d2014-03-31 17:52:59 -0700670
Naoki Shiota4e463182014-03-21 15:13:24 -0700671### Functions related to RAMCloud coordinator
Naoki Shiota9df15d32014-03-27 14:26:20 -0700672function rc-coord-addr {
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700673 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 Shiota9df15d32014-03-27 14:26:20 -0700679}
680
681function rc-server-addr {
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700682 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 Shiota9df15d32014-03-27 14:26:20 -0700688}
689
Naoki Shiota4e463182014-03-21 15:13:24 -0700690function rc-coord {
691 case "$1" in
692 start)
Naoki Shiota4e463182014-03-21 15:13:24 -0700693 stop-coord
694 start-coord
695 ;;
696 startifdown)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700697 local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700698 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 HIGUCHId150ece2014-04-29 16:25:36 -0700707 deldb)
708 stop-backend
709 del-coord-info
710 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700711 stat*) # <- status
712 local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
713 echo "$n RAMCloud coordinator running"
714 ;;
715 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700716 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700717 exit 1
718 esac
719}
720
721function start-coord {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700722 check-and-start-zk
723 wait-zk-or-die
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700724
Naoki Shiota4e463182014-03-21 15:13:24 -0700725 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 Shiota9df15d32014-03-27 14:26:20 -0700731
732 local coord_addr=`rc-coord-addr`
Naoki Shiota4e463182014-03-21 15:13:24 -0700733
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700734 # 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 HIGUCHId150ece2014-04-29 16:25:36 -0700739 # RAMCloud cluster name
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700740 local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700741
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700742 # RAMCloud transport timeout
743 local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700744 # 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 HIGUCHId082b962014-06-02 11:42:22 -0700753 coord_args="${coord_args} --externalStorage ${rc_locator}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700754 coord_args="${coord_args} --clusterName ${rc_cluster_name}"
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700755 coord_args="${coord_args} --timeout ${rc_timeout}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700756 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 Shiota4e463182014-03-21 15:13:24 -0700768 # Run ramcloud
769 echo -n "Starting RAMCloud coordinator ... "
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700770 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} > $RAMCLOUD_COORD_LOG 2>&1 &
Naoki Shiota4e463182014-03-21 15:13:24 -0700771 echo "STARTED"
772}
773
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700774function del-coord-info {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700775 check-and-start-zk
776 wait-zk-or-die
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700777
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 HIGUCHId082b962014-06-02 11:42:22 -0700787 # Configuration for ZK address, port
788 local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181")
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700789 # RAMCloud cluster name
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700790 local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700791 # 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 HIGUCHId082b962014-06-02 11:42:22 -0700800 coord_args="${coord_args} --externalStorage ${rc_locator}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700801 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 HIGUCHIcd44eb32014-05-24 16:51:31 -0700807 # TODO Assuming 5 sec is enough. To be sure monitor log?
808 sleep 5
809 # kill coordinator
Yuta HIGUCHIce9f3ee2014-05-14 09:48:40 -0700810 (pkill -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator &> /dev/null)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700811
812 echo "DONE"
813}
Naoki Shiota4e463182014-03-21 15:13:24 -0700814
815function stop-coord {
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700816 kill-processes "RAMCloud coordinator" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator`
Naoki Shiota4e463182014-03-21 15:13:24 -0700817}
818
Naoki Shiota4e463182014-03-21 15:13:24 -0700819### Functions related to RAMCloud server
820function rc-server {
821 case "$1" in
822 start)
Naoki Shiota4e463182014-03-21 15:13:24 -0700823 stop-server
824 start-server
825 ;;
826 startifdown)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700827 local n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700828 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 HIGUCHId150ece2014-04-29 16:25:36 -0700837 deldb)
838 stop-server
839 del-server-backup
840 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700841 stat*) # <- status
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700842 n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700843 echo "$n RAMCloud server running"
844 ;;
845 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700846 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700847 exit 1
848 esac
849}
850
851function start-server {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700852 check-and-start-zk
853 wait-zk-or-die
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700854
Naoki Shiota4e463182014-03-21 15:13:24 -0700855 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 Shiota9df15d32014-03-27 14:26:20 -0700861
862 local coord_addr=`rc-coord-addr`
863 local server_addr=`rc-server-addr`
Naoki Shiota4e463182014-03-21 15:13:24 -0700864
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700865 local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.server.masterServiceThreads 5)
866 local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.server.logCleanerThreads 1)
Yuta HIGUCHI52efcbb2014-05-16 09:30:33 -0700867 local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.server.detectFailures 0)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700868
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700869 # Configuration for ZK address, port
870 local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181")
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700871 # RAMCloud cluster name
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700872 local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700873 # RAMCloud transport timeout
874 local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700875 # 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 HIGUCHId082b962014-06-02 11:42:22 -0700882 server_args="${server_args} --externalStorage ${rc_locator}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700883 server_args="${server_args} --clusterName ${rc_cluster_name}"
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700884 server_args="${server_args} --timeout ${rc_timeout}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700885 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 HIGUCHI45bc3cf2014-04-19 18:12:15 -0700893
Naoki Shiota4e463182014-03-21 15:13:24 -0700894 # Run ramcloud
895 echo -n "Starting RAMCloud server ... "
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700896 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server ${server_args} > $RAMCLOUD_SERVER_LOG 2>&1 &
Naoki Shiota4e463182014-03-21 15:13:24 -0700897 echo "STARTED"
898}
899
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700900function del-server-backup {
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700901 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 HIGUCHId150ece2014-04-29 16:25:36 -0700913 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 Shiota4e463182014-03-21 15:13:24 -0700919function stop-server {
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700920 kill-processes "RAMCloud server" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server`
Naoki Shiota4e463182014-03-21 15:13:24 -0700921}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700922############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700923
924
Naoki Shiota590c18d2014-03-31 17:52:59 -0700925## Functions related to ONOS core process ##
Naoki Shiota4e463182014-03-21 15:13:24 -0700926function onos {
Naoki Shiota590c18d2014-03-31 17:52:59 -0700927 CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME}
Naoki Shiota4e463182014-03-21 15:13:24 -0700928 if [ ! -f ${CPFILE} ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700929 echo "ONOS core needs to be built"
Naoki Shiota4e463182014-03-21 15:13:24 -0700930 ${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 Shiota590c18d2014-03-31 17:52:59 -0700959 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700960 exit 1
961 esac
962}
963
964function start-onos {
965 if [ ! -d ${LOGDIR} ]; then
966 mkdir -p ${LOGDIR}
967 fi
Yuta HIGUCHI04713972014-05-30 11:01:17 -0700968 # Rotate log files
Naoki Shiota4e463182014-03-21 15:13:24 -0700969 for log in ${LOGS}; do
970 if [ -f ${log} ]; then
971 rotate-log ${log}
972 fi
973 done
Yuta HIGUCHI04713972014-05-30 11:01:17 -0700974
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 HIGUCHI04713972014-05-30 11:01:17 -0700980 fi
981 done
982
Naoki Shiota4e463182014-03-21 15:13:24 -0700983 if [ ! -f ${ONOS_LOGBACK} ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700984 echo "[WARNING] ${ONOS_LOGBACK} not found."
985 echo " Run \"\$ $0 setup\" to create."
986 exit 1
Naoki Shiota4e463182014-03-21 15:13:24 -0700987 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700988
Yuta HIGUCHI3ebc9482014-05-08 16:28:28 -0700989 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 HIGUCHI85de40d2014-06-12 14:06:41 -0700995 # specify ZooKeeper(curator) namespace
996 JVM_OPTS="${JVM_OPTS} -Dzookeeper.namespace=${ONOS_CLUSTER_NAME}"
997
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700998 # 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 HIGUCHI3ebc9482014-05-08 16:28:28 -07001005 # 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 Hartef3dc1a2014-04-03 11:39:50 -07001009 JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.backend=${ONOS_HOST_BACKEND}"
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -07001010 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
1011 JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}"
Yuta HIGUCHI3ebc9482014-05-08 16:28:28 -07001012 elif [ "${ONOS_HOST_BACKEND}" = "hazelcast" ]; then
1013 JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.hazelcast.baseConfig=${HC_CONF}"
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -07001014 fi
1015
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -07001016 # check for jvm debug flag
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -07001017 if [ "${ONOS_DEBUG}" == "true" ]; then
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -07001018 JVM_OPTS="${JVM_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${JVM_DEBUG_PORT}"
1019 fi
1020
Naoki Shiota9df15d32014-03-27 14:26:20 -07001021 # Run ONOS
Yuta HIGUCHIcce4f622014-04-18 16:48:53 -07001022
1023 # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD
1024 cd ${ONOS_HOME}
1025
Yuta HIGUCHId150ece2014-04-29 16:25:36 -07001026 echo -n "Starting ONOS controller ... "
Naoki Shiota4e463182014-03-21 15:13:24 -07001027 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 Shiota9df15d32014-03-27 14:26:20 -07001033 if [ $n -ge 1 ]; then
Naoki Shiota4e463182014-03-21 15:13:24 -07001034 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
1043function 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 Shiota590c18d2014-03-31 17:52:59 -07001047############################################
Naoki Shiota4e463182014-03-21 15:13:24 -07001048
1049
Naoki Shiota590c18d2014-03-31 17:52:59 -07001050################## Main ####################
Naoki Shiota4e463182014-03-21 15:13:24 -07001051case "$1" in
Naoki Shiota9df15d32014-03-27 14:26:20 -07001052 setup)
Naoki Shiota4e928512014-04-03 15:49:35 -07001053 create-confs $2
Naoki Shiota9df15d32014-03-27 14:26:20 -07001054 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -07001055 start)
Naoki Shiota9df15d32014-03-27 14:26:20 -07001056 mode_parameter=${ONOS_HOST_ROLE}
1057 if [ ! -z "$2" ]; then
1058 mode_parameter=$2
1059 fi
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -07001060
Naoki Shiota9df15d32014-03-27 14:26:20 -07001061 case "${mode_parameter}" in
Naoki Shiota4e463182014-03-21 15:13:24 -07001062 single-node)
1063 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -07001064 start-backend coord
1065 start-backend server
Naoki Shiota4e463182014-03-21 15:13:24 -07001066 onos startifdown
1067 ;;
1068 coord-node)
1069 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -07001070 start-backend coord
Naoki Shiota4e463182014-03-21 15:13:24 -07001071 onos startifdown
1072 ;;
1073 server-node)
1074 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -07001075 start-backend server
1076 onos startifdown
1077 ;;
1078 coord-and-server-node)
1079 zk start
1080 start-backend coord
1081 start-backend server
Naoki Shiota4e463182014-03-21 15:13:24 -07001082 onos startifdown
1083 ;;
1084 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -07001085 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -07001086 ;;
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 Shiota9df15d32014-03-27 14:26:20 -07001096 stop-backend
Naoki Shiota4e463182014-03-21 15:13:24 -07001097
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 HIGUCHI259b79a2014-06-04 12:21:22 -07001109
Naoki Shiota4e463182014-03-21 15:13:24 -07001110 rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l`
1111 if [ $rcsn != 0 ]; then
1112 rc-server stop
1113 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001114
Naoki Shiota590c18d2014-03-31 17:52:59 -07001115 rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -07001116 if [ $rccn != 0 ]; then
1117 rc-coord stop
1118 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001119
Naoki Shiota4e463182014-03-21 15:13:24 -07001120 zkn=`jps -l | grep org.apache.zookeeper.server | wc -l`
1121 if [ $zkn != 0 ]; then
1122 zk restart
1123 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001124
Naoki Shiota4e463182014-03-21 15:13:24 -07001125 if [ $rccn != 0 ]; then
1126 rc-coord startifdown
1127 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001128
Naoki Shiota4e463182014-03-21 15:13:24 -07001129 if [ $rcsn != 0 ]; then
1130 rc-server startifdown
1131 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001132
Naoki Shiota4e463182014-03-21 15:13:24 -07001133 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 HIGUCHId150ece2014-04-29 16:25:36 -07001161 rc)
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001162 # 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 Shiota9109a1e2014-05-13 11:11:01 -07001167 # TODO make deldb command more organized (clarify when it can work)
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001168 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 HIGUCHId150ece2014-04-29 16:25:36 -07001174 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -07001175 core)
1176 onos $2
1177 ;;
1178 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -07001179 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -07001180 exit 1
1181esac
Naoki Shiota590c18d2014-03-31 17:52:59 -07001182