blob: 06172863239f05c5513a2619c3bd77c08ba7362b [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}
Yuta HIGUCHIec920702014-08-01 17:54:30 -070027ONOS_DUMP_DIR=${ONOS_DUMP_DIR:-${ONOS_HOME}}
Naoki Shiota590c18d2014-03-31 17:52:59 -070028
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070029source ${ONOS_HOME}/scripts/common/utils.sh
30
Yuta HIGUCHIe748ecc2014-05-28 13:55:03 -070031confirm-if-root
32
Naoki Shiota590c18d2014-03-31 17:52:59 -070033if [ ! -f ${ONOS_CONF} ]; then
Naoki Shiota9a1e6d12014-04-03 14:47:12 -070034 # falling back to default config file
35 ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf
36 if [ ! -f ${ONOS_CONF} ]; then
37 echo "${ONOS_CONF} not found."
38 exit 1
39 fi
Naoki Shiota590c18d2014-03-31 17:52:59 -070040fi
Naoki Shiota4e928512014-04-03 15:49:35 -070041
Naoki Shiota4e928512014-04-03 15:49:35 -070042### Variables read from ONOS config file ###
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -070043ONOS_CLUSTER_NAME=$(read-conf ${ONOS_CONF} onos.cluster.name "onos")
Naoki Shiota4e928512014-04-03 15:49:35 -070044ONOS_HOST_NAME=$(read-conf ${ONOS_CONF} host.name `hostname`)
45ONOS_HOST_IP=$(read-conf ${ONOS_CONF} host.ip)
46ONOS_HOST_ROLE=$(read-conf ${ONOS_CONF} host.role)
47ONOS_HOST_BACKEND=$(read-conf ${ONOS_CONF} host.backend)
48ZK_HOSTS=$(read-conf ${ONOS_CONF} zookeeper.hosts ${ONOS_HOST_NAME})
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -070049ZK_CLIENTPORT=$(read-conf ${ONOS_CONF} zookeeper.clientPort 2181)
50ZK_PORTS=$(read-conf ${ONOS_CONF} zookeeper.ports 2888:3888)
Naoki Shiota4e928512014-04-03 15:49:35 -070051RC_COORD_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.coordinator.protocol "fast+udp")
52RC_COORD_IP=$(read-conf ${ONOS_CONF} ramcloud.coordinator.ip ${ONOS_HOST_IP})
53RC_COORD_PORT=$(read-conf ${ONOS_CONF} ramcloud.coordinator.port 12246)
54RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp")
55RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP})
56RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242)
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070057HC_HOST_PORT=$(read-conf ${ONOS_CONF} hazelcast.host.port 5701)
Naoki Shiota4e928512014-04-03 15:49:35 -070058HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members)
59HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3")
60HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327)
Naoki Shiota590c18d2014-03-31 17:52:59 -070061############################################
62
63
64############## Other variables #############
Naoki Shiota4e928512014-04-03 15:49:35 -070065ONOS_TEMPLATE_DIR=${ONOS_CONF_DIR}/template
66
Naoki Shiota4e463182014-03-21 15:13:24 -070067LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
68
Yuta HIGUCHIfb1905a2014-06-09 14:07:34 -070069ZK_HOME=${ZK_HOME:-~/zookeeper-3.4.6}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070070ZK_CONF=${ZK_CONF:-${ONOS_CONF_DIR}/zoo.cfg}
Naoki Shiota4e928512014-04-03 15:49:35 -070071ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -070072# Adding ONOS_HOST_NAME dir since file name (zookeeper.out) cannot be controlled.
Naoki Shiotad8ea71a2014-04-23 17:04:51 -070073ZK_LOG_DIR=${ZK_LOG_DIR:-${ONOS_HOME}/onos-logs/zk-${ONOS_HOST_NAME}}
Naoki Shiota72209722014-04-08 14:32:17 -070074ZK_LIB_DIR=${ZK_LIB_DIR:-/var/lib/zookeeper}
Naoki Shiota9df15d32014-03-27 14:26:20 -070075ZK_MY_ID=${ZK_LIB_DIR}/myid
Naoki Shiota4e463182014-03-21 15:13:24 -070076
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070077HC_CONF=${HC_CONF:-${ONOS_CONF_DIR}/hazelcast.xml}
Naoki Shiota4e928512014-04-03 15:49:35 -070078HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template
79
Naoki Shiota4e463182014-03-21 15:13:24 -070080RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
Naoki Shiota590c18d2014-03-31 17:52:59 -070081RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log
82RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log
Naoki Shiota4e463182014-03-21 15:13:24 -070083RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070084RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_CONF_DIR}/ramcloud.conf}
Naoki Shiota4e463182014-03-21 15:13:24 -070085
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -070086export LD_LIBRARY_PATH=${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}:$LD_LIBRARY_PATH
Naoki Shiota4e463182014-03-21 15:13:24 -070087
88## 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 -070089ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_CONF_DIR}/logback.${ONOS_HOST_NAME}.xml}
Naoki Shiota9df15d32014-03-27 14:26:20 -070090ONOS_LOGBACK_BACKUP=${ONOS_LOGBACK}.bak
Naoki Shiota4e928512014-04-03 15:49:35 -070091ONOS_LOGBACK_TEMPLATE=${ONOS_TEMPLATE_DIR}/logback.xml.template
Naoki Shiota4e463182014-03-21 15:13:24 -070092LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
Naoki Shiota590c18d2014-03-31 17:52:59 -070093LOGBASE=${ONOS_LOGBASE:-onos.${ONOS_HOST_NAME}}
Naoki Shiota4e463182014-03-21 15:13:24 -070094ONOS_LOG="${LOGDIR}/${LOGBASE}.log"
Yuta HIGUCHI04713972014-05-30 11:01:17 -070095ONOS_LOG_ROLLING_PATTERN="${LOGDIR}/${LOGBASE}.%i.log.gz"
96ONOS_STDOUT_LOG="${LOGDIR}/${LOGBASE}.stdout"
97ONOS_STDERR_LOG="${LOGDIR}/${LOGBASE}.stderr"
Naoki Shiota4e463182014-03-21 15:13:24 -070098PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap"
Yuta HIGUCHI04713972014-05-30 11:01:17 -070099LOGS="$ONOS_LOG $ONOS_STDOUT_LOG $ONOS_STDERR_LOG $PCAP_LOG"
Naoki Shiota4e463182014-03-21 15:13:24 -0700100
Naoki Shiota9df15d32014-03-27 14:26:20 -0700101ONOS_PROPS=${ONOS_PROPS:-${ONOS_CONF_DIR}/onos.properties}
Naoki Shiota4e463182014-03-21 15:13:24 -0700102JMX_PORT=${JMX_PORT:-7189}
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -0700103JVM_DEBUG_PORT=${JVM_DEBUG_PORT:-22007}
Naoki Shiota4e463182014-03-21 15:13:24 -0700104
105# Set JVM options
106JVM_OPTS="${JVM_OPTS:-}"
Naoki Shiota4e463182014-03-21 15:13:24 -0700107JVM_OPTS="$JVM_OPTS -server -d64"
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700108
109# TODO Revisit appropriate CodeCache size
110JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700111
112# Uncomment or specify appropriate value as JVM_OPTS environment variables.
113#JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
Naoki Shiota4e463182014-03-21 15:13:24 -0700114#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
115#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700116
117#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC"
118JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC"
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700119#JVM_OPTS="$JVM_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=200"
120# Note: shoult NOT specify -Xmn when using G1GC
121# http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html
122
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700123JVM_OPTS="$JVM_OPTS -XX:+AggressiveOpts"
124
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700125# 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 -0700126JVM_OPTS="$JVM_OPTS -XX:+UseFastAccessorMethods"
127
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700128# TODO revisit these derived from floodlight
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700129JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192"
130JVM_OPTS="$JVM_OPTS -XX:FreqInlineSize=8192"
131JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500"
132
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700133# FIXME Specify appropriate cmd to handle fatal crash
134# http://www.oracle.com/technetwork/java/javase/clopts-139448.html#gbmum
Naoki Shiota4e463182014-03-21 15:13:24 -0700135JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700136#JVM_OPTS="$JVM_OPTS -XX:+ShowMessageBoxOnError"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700137
Praseed Balakrishnan4fe80812014-07-24 11:29:19 -0700138# This option tells the VM to generate a heap dump when memory allocation cannot be satisfied.
139# http://www.oracle.com/technetwork/java/javase/clopts-139448.html#gbzrr
Yuta HIGUCHIec920702014-08-01 17:54:30 -0700140JVM_OPTS="$JVM_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${ONOS_DUMP_DIR}"
Praseed Balakrishnan4fe80812014-07-24 11:29:19 -0700141
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700142# Workaround for Thread Priority http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html
143JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42"
144
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700145JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT"
146JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false"
147JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
148
Yuta HIGUCHI6bcaf982014-07-30 15:49:58 -0700149JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j -Dhazelcast.jmx=true -Dhazelcast.jmx.detailed=true"
Naoki Shiota4e463182014-03-21 15:13:24 -0700150
Yuta HIGUCHIc248d0d2014-07-30 16:14:18 -0700151# TODO revisit HZ related magic numbers
152# HZ Default:1000000
153JVM_OPTS="$JVM_OPTS -Dhazelcast.event.queue.capacity=4000000"
154# HZ Default:32 (KB)
155JVM_OPTS="$JVM_OPTS -Dhazelcast.socket.receive.buffer.size=4096"
156# HZ Default:32 (KB)
157JVM_OPTS="$JVM_OPTS -Dhazelcast.socket.send.buffer.size=4096"
158
159
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -0700160if [ "${ONOS_DEBUG}" == "true" ]; then
161 # Compilation diagnosis
162 JVM_OPTS="$JVM_OPTS -XX:+UnlockDiagnosticVMOptions"
163 JVM_OPTS="$JVM_OPTS -XX:+LogCompilation"
164 JVM_OPTS="$JVM_OPTS -XX:LogFile=${LOGDIR}/compilation.${ONOS_HOST_NAME}.log"
165
166 # GC diagnosis
167 JVM_OPTS="$JVM_OPTS -verbose:gc"
168 JVM_OPTS="$JVM_OPTS -verbose:sizes"
169 JVM_OPTS="$JVM_OPTS -Xloggc:${LOGDIR}/gc.${ONOS_HOST_NAME}.log"
170 JVM_OPTS="$JVM_OPTS -XX:GCLogFileSize=1G"
171 JVM_OPTS="$JVM_OPTS -XX:+PrintGCDetails"
172 JVM_OPTS="$JVM_OPTS -XX:+PrintGCTimeStamps"
173 JVM_OPTS="$JVM_OPTS -XX:+PrintGCDateStamps"
174 JVM_OPTS="$JVM_OPTS -XX:+PrintTenuringDistribution"
175 JVM_OPTS="$JVM_OPTS -XX:+PrintCMSInitiationStatistics"
176fi
177
178# dump final JVM flags to stdout
179JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700180
Naoki Shiota4e463182014-03-21 15:13:24 -0700181# Set ONOS core main class
Jonathan Hart51f6f5b2014-04-03 10:32:10 -0700182MAIN_CLASS="net.onrc.onos.core.main.Main"
Naoki Shiota4e463182014-03-21 15:13:24 -0700183
184MVN=${MVN:-mvn -o}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700185############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700186
Naoki Shiota9df15d32014-03-27 14:26:20 -0700187
Naoki Shiota590c18d2014-03-31 17:52:59 -0700188############# Common functions #############
189function print_usage {
Naoki Shiota05721b32014-04-29 14:41:12 -0700190 local scriptname=`basename $0`
Naoki Shiota590c18d2014-03-31 17:52:59 -0700191 local filename=`basename ${ONOS_CONF}`
192 local usage="Usage: setup/start/stop ONOS on this server.
Naoki Shiota05721b32014-04-29 14:41:12 -0700193 \$ ${scriptname} setup [-f]
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700194 Set up ONOS node using ${ONOS_CONF} .
Naoki Shiota590c18d2014-03-31 17:52:59 -0700195 - generate and replace config file of ZooKeeper.
196 - create myid in ZooKeeper datadir.
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700197 - generate and replace config file for Hazelcast.
198 - generate and replace config file for RAMCloud.
Naoki Shiota590c18d2014-03-31 17:52:59 -0700199 - generate and replace logback.${ONOS_HOST_NAME}.xml
200 If -f option is used, all existing files will be overwritten without confirmation.
Naoki Shiota05721b32014-04-29 14:41:12 -0700201 \$ ${scriptname} start [single-node|coord-node|server-node|coord-and-server-node]
Naoki Shiota590c18d2014-03-31 17:52:59 -0700202 Start ONOS node with specific RAMCloud entities
203 - single-node: start ONOS with stand-alone RAMCloud
204 - coord-node : start ONOS with RAMCloud coordinator
205 - server-node: start ONOS with RAMCloud server
206 - coord-and-server-node: start ONOS with RAMCloud coordinator and server
207 * Default behavior can be defined by ${filename}
Naoki Shiota05721b32014-04-29 14:41:12 -0700208 \$ ${scriptname} stop
Naoki Shiota590c18d2014-03-31 17:52:59 -0700209 Stop all ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700210 \$ ${scriptname} restart
Naoki Shiota590c18d2014-03-31 17:52:59 -0700211 Stop and start currently running ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700212 \$ ${scriptname} status
Naoki Shiota590c18d2014-03-31 17:52:59 -0700213 Show status of ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700214 \$ ${scriptname} {zk|rc-coord|rc-server|core} {start|stop|restart|status}
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700215 Control specific ONOS-related process
216 \$ ${scriptname} rc deldb
217 Delete data in RAMCloud"
Naoki Shiota590c18d2014-03-31 17:52:59 -0700218
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700219 echo "${usage}"
Naoki Shiota4e463182014-03-21 15:13:24 -0700220}
221
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700222# rotate-log [log-filename] [max rotations]
223# Example:
224# foobar.log -> foobar.log.1
225# foobar.log.1 -> foobar.log.2
226# foobar.log.gz -> foobar.log.1.gz
Naoki Shiota4e463182014-03-21 15:13:24 -0700227function rotate-log {
Naoki Shiota4e928512014-04-03 15:49:35 -0700228 local logfile=$1
229 local nr_max=${2:-10}
230 if [ -f $logfile ]; then
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700231 # TODO treating only .gz now. probably want more generic solution
232 local basename=${logfile%%.gz}
233 local append=""
234 if [ "$basename" != "$logfile" ]; then
235 append=".gz"
236 fi
Naoki Shiota4e928512014-04-03 15:49:35 -0700237 for i in `seq $(expr $nr_max - 1) -1 1`; do
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700238 if [ -f ${basename}.${i}${append} ]; then
239 mv -f ${basename}.${i}${append} ${basename}.`expr $i + 1`${append}
Naoki Shiota4e928512014-04-03 15:49:35 -0700240 fi
241 done
Yuta HIGUCHIb138a8c2014-06-19 11:07:20 -0700242 mv ${basename}${append} ${basename}.1${append}
Naoki Shiota4e928512014-04-03 15:49:35 -0700243 fi
Naoki Shiota4e463182014-03-21 15:13:24 -0700244}
245
246# kill-processes {module-name} {array of pids}
247function kill-processes {
248 # Kill the existing processes
249 local pids=$2
Naoki Shiota9df15d32014-03-27 14:26:20 -0700250 if [ ! -z "$pids" ]; then
Naoki Shiota4e463182014-03-21 15:13:24 -0700251 echo -n "Stopping $1 ... "
252 fi
253 for p in ${pids}; do
254 if [ x$p != "x" ]; then
Naoki Shiota4b355762014-05-27 11:46:43 -0700255 # Check if target process is accesible from current user
256 kill -0 $p
257 if [ "$?" -ne 0 ]; then
258 # Error exit code here means "failed to send signal".
259 # Supposedly because of permission error.
260 echo "Failed to kill process (pid: $p)."
261 echo "Check if current user is the same as process owner."
262 exit 1
263 fi
264
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700265 (
266 # Ask process with SIGTERM first, if that did not kill the process
267 # wait 1s and if process still exist, force process to be killed.
268 kill -TERM $p && kill -0 $p && sleep 1 && kill -0 $p && kill -KILL $p
269 ) 2> /dev/null
Naoki Shiota4b355762014-05-27 11:46:43 -0700270
271 # Ensure process is killed.
272 kill -0 $p 2> /dev/null
273 if [ "$?" -ne 0 ]; then
274 # Error exit code here means "process not found", i.e. "kill succeeded".
275 echo "Killed existing process (pid: $p)"
276 else
277 # Process still exists. Some unexpected error occurs.
278 echo "Failed to kill process (pid: $p)."
279 echo "Unexpected error occurs during process termination."
280 exit 1
281 fi
Naoki Shiota4e463182014-03-21 15:13:24 -0700282 fi
283 done
284}
285
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700286function handle-error {
287 set -e
288
289 revert-confs
290
291 set +e
292
293 exit 1
294}
295
Naoki Shiota4e928512014-04-03 15:49:35 -0700296# revert-confs [error message]
297function revert-confs {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700298 echo -n "ERROR occurred ... "
Naoki Shiota9df15d32014-03-27 14:26:20 -0700299
Naoki Shiota4e928512014-04-03 15:49:35 -0700300 revert-file `basename ${ZK_CONF}`
301 revert-file `basename ${HC_CONF}`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700302
303 echo "EXIT"
304
305 if [ ! -z "$1" ]; then
306 echo $1
307 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700308}
309
Naoki Shiota590c18d2014-03-31 17:52:59 -0700310function create-zk-conf {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700311 echo -n "Creating ${ZK_CONF} ... "
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700312
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700313 # Create the ZooKeeper lib directory
Yuta HIGUCHIb3983b12014-06-12 14:21:09 -0700314 if [[ ! ( -w ${ZK_LIB_DIR} && -d ${ZK_LIB_DIR} ) ]]; then
Naoki Shiota7f495cf2014-05-21 17:23:25 -0700315 local SUDO=${SUDO:-sudo}
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700316 local whoami=`whoami`
317 {
Yuta HIGUCHIb3983b12014-06-12 14:21:09 -0700318 ${SUDO} mkdir -p ${ZK_LIB_DIR}
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700319 ${SUDO} chown ${whoami} ${ZK_LIB_DIR}
320 } || {
321 echo "FAILED"
322 echo "[ERROR] Failed to create directory ${ZK_LIB_DIR}."
323 echo "[ERROR] Please retry after setting \"env SUDO=sudo\""
324 exit 1
325 }
326 fi
327
328 # creation of ZooKeeper config
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700329 local temp_zk=`begin-conf-creation ${ZK_CONF}`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700330
Naoki Shiota4e928512014-04-03 15:49:35 -0700331 hostarr=`echo ${ZK_HOSTS} | tr "," " "`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700332
333 local i=1
334 local myid=
335 for host in ${hostarr}; do
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700336 if [ "${host}" = "${ONOS_HOST_NAME}" -o "${host}" = "${ONOS_HOST_IP}" ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700337 myid=$i
338 break
339 fi
340 i=`expr $i + 1`
341 done
342
343 if [ -z "${myid}" ]; then
Naoki Shiota590c18d2014-03-31 17:52:59 -0700344 local filename=`basename ${ONOS_CONF}`
Naoki Shiota35f8d5c2014-04-08 11:13:18 -0700345 revert-confs "[ERROR] In ${filename}, zookeeper.hosts must have hostname \"${ONOS_HOST_NAME}\" or IP address"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700346 fi
347
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700348 if [ -f "${ZK_MY_ID}" ]; then
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700349 # sudo will be needed if ZK_MY_ID is already created by other (old) script
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700350 local SUDO=${SUDO:-}
351 {
352 ${SUDO} mv -f ${ZK_MY_ID} ${ZK_MY_ID}.old
353 } || {
354 echo "FAILED"
355 echo "[ERROR] Failed to rename ${ZK_MY_ID}."
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700356 echo "[ERROR] Please retry after setting \"env SUDO=sudo\""
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700357 exit 1
358 }
359 fi
360
Naoki Shiota9df15d32014-03-27 14:26:20 -0700361 echo ${myid} > ${ZK_MY_ID}
362
363 echo -n "myid is assigned to ${myid} ... "
364
365 while read line; do
366 if [[ $line =~ ^__HOSTS__$ ]]; then
367 i=1
368 for host in ${hostarr}; do
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700369 # TODO: ZK ports should be configurable per host
370 local hostline="server.${i}=${host}:${ZK_PORTS}"
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700371 echo $hostline
Naoki Shiota9df15d32014-03-27 14:26:20 -0700372 i=`expr $i + 1`
373 done
374 elif [[ $line =~ __DATADIR__ ]]; then
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700375 echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700376 else
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700377 echo $line
Naoki Shiota9df15d32014-03-27 14:26:20 -0700378 fi
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700379 done < ${ZK_CONF_TEMPLATE} > ${temp_zk}
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700380 sed -e "s|__CLIENTPORT__|${ZK_CLIENTPORT}|" -i "" ${temp_zk}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700381
382 end-conf-creation ${ZK_CONF}
Naoki Shiota9df15d32014-03-27 14:26:20 -0700383
384 echo "DONE"
Naoki Shiota590c18d2014-03-31 17:52:59 -0700385}
Naoki Shiota9df15d32014-03-27 14:26:20 -0700386
Naoki Shiota4e928512014-04-03 15:49:35 -0700387function create-hazelcast-conf {
388 echo -n "Creating ${HC_CONF} ... "
389
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700390 local temp_hc=`begin-conf-creation ${HC_CONF}`
Naoki Shiota4e928512014-04-03 15:49:35 -0700391
392 # To keep indent of XML file, change IFS
393 local IFS=''
394 while read line; do
395 if [[ $line =~ __HC_NETWORK__ ]]; then
396 if [ ! -z "${HC_TCPIP_MEMBERS}" ]; then
397 # temporary change
398 IFS=' '
399 local memberarr=`echo ${HC_TCPIP_MEMBERS} | tr "," " "`
400 echo '<multicast enabled="false" />'
401 echo '<tcp-ip enabled="true">'
402 for member in ${memberarr}; do
403 echo " <member>${member}</member>"
404 done
405 echo '</tcp-ip>'
406 IFS=''
407 else
408 echo '<multicast enabled="true">'
409 echo " <multicast-group>${HC_MULTICAST_GROUP}</multicast-group>"
410 echo " <multicast-port>${HC_MULTICAST_PORT}</multicast-port>"
411 echo '</multicast>'
412 echo '<tcp-ip enabled="false" />'
413 fi
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700414 elif [[ $line =~ __HC_PORT__ ]]; then
415 echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|"
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700416 elif [[ $line =~ __HC_CLUSTER__ ]]; then
417 echo $line | sed -e "s|__HC_CLUSTER__|${ONOS_CLUSTER_NAME}|"
Naoki Shiota4e928512014-04-03 15:49:35 -0700418 else
419 echo "${line}"
420 fi
421 done < ${HC_CONF_TEMPLATE} > ${temp_hc}
422
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700423 end-conf-creation ${HC_CONF}
Naoki Shiota4e928512014-04-03 15:49:35 -0700424
425 echo "DONE"
426}
427
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700428function create-ramcloud-conf {
429 echo -n "Creating ${RAMCLOUD_CONF} ... "
430
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700431 local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}`
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700432
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700433 local rc_locator=`echo "${ZK_HOSTS}" | sed -e "s/,/:${ZK_CLIENTPORT},/g"`
434 rc_locator+=":${ZK_CLIENTPORT}"
435
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700436 local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700437
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700438 echo "ramcloud.locator=zk:localhost:2181,${rc_locator}" > ${temp_rc}
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700439 echo "ramcloud.clusterName=${rc_cluster_name}" >> ${temp_rc}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700440
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700441 end-conf-creation ${RAMCLOUD_CONF}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700442
443 echo "DONE"
444}
445
Naoki Shiota590c18d2014-03-31 17:52:59 -0700446function create-logback-conf {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700447 echo -n "Creating ${ONOS_LOGBACK} ... "
Naoki Shiota590c18d2014-03-31 17:52:59 -0700448
Naoki Shiota9df15d32014-03-27 14:26:20 -0700449 # creation of logback config
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700450 local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}`
Yuta HIGUCHI04713972014-05-30 11:01:17 -0700451
452 sed -e "s|__FILENAME__|${ONOS_LOG}|" \
453 -e "s|__ROLLING_PATTERN__|${ONOS_LOG_ROLLING_PATTERN}|" ${ONOS_LOGBACK_TEMPLATE} > ${temp_lb}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700454
455 end-conf-creation ${ONOS_LOGBACK}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700456
Naoki Shiota9df15d32014-03-27 14:26:20 -0700457 echo "DONE"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700458}
459
Naoki Shiota4e928512014-04-03 15:49:35 -0700460function create-confs {
461 local key
462 local filename
463
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700464 trap handle-error ERR
Naoki Shiota4e928512014-04-03 15:49:35 -0700465
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700466 echo "Config file : ${ONOS_CONF}"
467
Naoki Shiota4e928512014-04-03 15:49:35 -0700468 if [ "$1" == "-f" ]; then
469 create-zk-conf
470 create-hazelcast-conf
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700471 create-ramcloud-conf
Naoki Shiota4e928512014-04-03 15:49:35 -0700472 create-logback-conf
473 else
474 create-conf-interactive ${ZK_CONF} create-zk-conf
475 create-conf-interactive ${HC_CONF} create-hazelcast-conf
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700476 create-conf-interactive ${RAMCLOUD_CONF} create-ramcloud-conf
Naoki Shiota4e928512014-04-03 15:49:35 -0700477 create-conf-interactive ${ONOS_LOGBACK} create-logback-conf
478 fi
Naoki Shiota590c18d2014-03-31 17:52:59 -0700479
480 trap - ERR
481}
482############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700483
Naoki Shiota590c18d2014-03-31 17:52:59 -0700484
485###### Functions related to ZooKeeper ######
Naoki Shiota4e463182014-03-21 15:13:24 -0700486function zk {
487 case "$1" in
488 start)
489 start-zk
490 ;;
491 stop)
492 stop-zk
493 ;;
494 stat*) # <- status
495 status-zk
496 ;;
497 re*) # <- restart
498 stop-zk
499 start-zk
500 ;;
501 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700502 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700503 exit 1
504 esac
505}
506
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700507function load-zk-cfg {
508 if [ -f "${ZK_CONF}" ]; then
509 local filename=`basename ${ZK_CONF}`
510 local dirname=`dirname ${ZK_CONF}`
511
512 # Run ZooKeeper with our configuration
513 export ZOOCFG=${filename}
514 export ZOOCFGDIR=${dirname}
515 fi
516}
517
Naoki Shiota4e463182014-03-21 15:13:24 -0700518function start-zk {
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700519 echo -n "Starting ZooKeeper ... "
Naoki Shiota9df15d32014-03-27 14:26:20 -0700520
Naoki Shiota4e928512014-04-03 15:49:35 -0700521 export ZOO_LOG_DIR=${ZK_LOG_DIR}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700522 mkdir -p ${ZK_LOG_DIR}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700523
524 load-zk-cfg
Yuta HIGUCHIf66cf212014-05-29 23:16:44 -0700525
526 # log4j.properties is read from classpath if not found in CWD.
527 # Using the ZooKeeper supplied default in ZooKeeper conf dir.
528 # TODO: To explicitly specify our customized log4j config file:
529 # export SERVER_JVMFLAGS="-Dlog4j.configuration=${ZK_LOG4J}"
530 env CLASSPATH="${ZK_HOME}/conf:${CLASSPATH}" ${ZK_HOME}/bin/zkServer.sh start
Naoki Shiota4e463182014-03-21 15:13:24 -0700531}
532
533function stop-zk {
Yuta HIGUCHI7c708362014-06-02 23:15:13 -0700534 echo -n "Stopping ZooKeeper ... "
535 load-zk-cfg
536
537 ${ZK_HOME}/bin/zkServer.sh stop
Naoki Shiota4e463182014-03-21 15:13:24 -0700538}
539
540function status-zk {
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700541 load-zk-cfg
Naoki Shiota9df15d32014-03-27 14:26:20 -0700542
Naoki Shiota72209722014-04-08 14:32:17 -0700543 ${ZK_HOME}/bin/zkServer.sh status
Naoki Shiota4e463182014-03-21 15:13:24 -0700544}
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700545
546function check-zk {
547 # assumption here is that ZK status script is the last command in status-zk.
548 status-zk &> /dev/null
549 local zk_status=$?
550 if [ "$zk_status" -ne 0 ]; then
551 return 1;
552 fi
553 return 0
554}
555
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700556function check-and-start-zk {
557 check-zk
558 local zk_status=$?
559 if [ "$zk_status" -ne 0 ]; then
560 start-zk
561 fi
562}
563
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700564# wait-zk-or-die {timeout-sec}
565function wait-zk-or-die {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700566 local retries=${1:-5}
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700567 # do-while retries >= 0
568 while true; do
569 check-zk
570 local zk_status=$?
571 if [ "$zk_status" -eq 0 ]; then
572 return 0
573 fi
574 sleep 1;
575 ((retries -= 1))
576 (( retries >= 0 )) || break
577 done
578 echo "ZooKeeper is not running."
579 exit 1
580}
581
Naoki Shiota590c18d2014-03-31 17:52:59 -0700582############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700583
584
Naoki Shiota590c18d2014-03-31 17:52:59 -0700585####### Functions related to RAMCloud ######
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -0700586
587# Check if this host should be running RAMCloud coordinator:
588function is-coord-role {
589 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
590 case "${ONOS_HOST_ROLE}" in
591 single-node)
592 echo "true"
593 return 0
594 ;;
595 coord-node)
596 echo "true"
597 return 0
598 ;;
599 server-node)
600 echo "false"
601 return 1
602 ;;
603 coord-and-server-node)
604 echo "true"
605 return 0
606 ;;
607 *)
608 echo "false"
609 return 1
610 ;;
611 esac
612 else
613 echo "false"
614 return 1
615 fi
616}
617
618# Check if this host should be running RAMCloud server:
619function is-server-role {
620 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
621 case "${ONOS_HOST_ROLE}" in
622 single-node)
623 echo "true"
624 return 0
625 ;;
626 coord-node)
627 echo "false"
628 return 1
629 ;;
630 server-node)
631 echo "true"
632 return 0
633 ;;
634 coord-and-server-node)
635 echo "true"
636 return 0
637 ;;
638 *)
639 echo "false"
640 return 1
641 ;;
642 esac
643 else
644 echo "false"
645 return 1
646 fi
647}
648
Naoki Shiota9df15d32014-03-27 14:26:20 -0700649function start-backend {
650 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
Naoki Shiota590c18d2014-03-31 17:52:59 -0700651 if [ $1 == "coord" ]; then
652 rc-coord startifdown
653 elif [ $1 == "server" ]; then
654 rc-server startifdown
655 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700656 fi
657}
658
659function stop-backend {
660 rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l`
661 if [ $rcsn != 0 ]; then
662 rc-server stop
663 fi
664
Naoki Shiota590c18d2014-03-31 17:52:59 -0700665 rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700666 if [ $rccn != 0 ]; then
667 rc-coord stop
668 fi
669}
670
Naoki Shiota590c18d2014-03-31 17:52:59 -0700671
Naoki Shiota4e463182014-03-21 15:13:24 -0700672### Functions related to RAMCloud coordinator
Naoki Shiota9df15d32014-03-27 14:26:20 -0700673function rc-coord-addr {
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700674 local host=${RC_COORD_IP}
675 if [ -z "${host}" ]; then
676 # falling back to 0.0.0.0
677 host="0.0.0.0"
678 fi
679 echo "${RC_COORD_PROTOCOL}:host=${host},port=${RC_COORD_PORT}"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700680}
681
682function rc-server-addr {
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700683 local host=${RC_SERVER_IP}
684 if [ -z "${host}" ]; then
685 # falling back to 0.0.0.0
686 host="0.0.0.0"
687 fi
688 echo "${RC_SERVER_PROTOCOL}:host=${host},port=${RC_SERVER_PORT}"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700689}
690
Naoki Shiota4e463182014-03-21 15:13:24 -0700691function rc-coord {
692 case "$1" in
693 start)
Naoki Shiota4e463182014-03-21 15:13:24 -0700694 stop-coord
695 start-coord
696 ;;
697 startifdown)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700698 local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700699 if [ $n == 0 ]; then
700 start-coord
701 else
702 echo "$n instance of RAMCloud coordinator running"
703 fi
704 ;;
705 stop)
706 stop-coord
707 ;;
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700708 deldb)
709 stop-backend
710 del-coord-info
711 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700712 stat*) # <- status
713 local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
714 echo "$n RAMCloud coordinator running"
715 ;;
716 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700717 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700718 exit 1
719 esac
720}
721
722function start-coord {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700723 check-and-start-zk
724 wait-zk-or-die
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700725
Naoki Shiota4e463182014-03-21 15:13:24 -0700726 if [ ! -d ${LOGDIR} ]; then
727 mkdir -p ${LOGDIR}
728 fi
729 if [ -f $RAMCLOUD_COORD_LOG ]; then
730 rotate-log $RAMCLOUD_COORD_LOG
731 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700732
733 local coord_addr=`rc-coord-addr`
Naoki Shiota4e463182014-03-21 15:13:24 -0700734
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700735 # TODO Make ONOS_CONF readable from ONOS process then eliminate RAMCLOUD_CONF
736
737 # Configuration for ZK address, port
738 local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181")
739
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700740 # RAMCloud cluster name
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700741 local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700742
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700743 # RAMCloud transport timeout
744 local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700745 # RAMCloud option deadServerTimeout
746 # (note RC default is 250ms, setting relaxed ONOS default to 1000ms)
747 local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000)
748
749 # NOTE RAMCloud document suggests to use -L to specify listen address:port,
750 # but actual RAMCloud code only uses -C argument now.
751 # (FYI: -C is documented to be deprecated in the document)
752
753 local coord_args="-C ${coord_addr}"
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700754 coord_args="${coord_args} --externalStorage ${rc_locator}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700755 coord_args="${coord_args} --clusterName ${rc_cluster_name}"
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700756 coord_args="${coord_args} --timeout ${rc_timeout}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700757 coord_args="${coord_args} --deadServerTimeout ${rc_coord_deadServerTimeout}"
758
759 # Read environment variables if set
760 coord_args="${coord_args} ${RC_COORDINATOR_OPTS}"
761
762 if [ "${ONOS_HOST_ROLE}" == "single-node" ]; then
763 # Note: Following reset is required, since RC restart is considered node failure,
764 # and tries recovery of server, which will never succeed after restart.
765 echo "Role configured to single-node mode. RAMCloud cluster will be reset on each start-up."
766 coord_args="${coord_args} --reset"
767 fi
768
Naoki Shiota4e463182014-03-21 15:13:24 -0700769 # Run ramcloud
770 echo -n "Starting RAMCloud coordinator ... "
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700771 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} > $RAMCLOUD_COORD_LOG 2>&1 &
Naoki Shiota4e463182014-03-21 15:13:24 -0700772 echo "STARTED"
773}
774
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700775function del-coord-info {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700776 check-and-start-zk
777 wait-zk-or-die
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700778
779 if [ ! -d ${LOGDIR} ]; then
780 mkdir -p ${LOGDIR}
781 fi
782 if [ -f $RAMCLOUD_COORD_LOG ]; then
783 rotate-log $RAMCLOUD_COORD_LOG
784 fi
785
786 local coord_addr=`rc-coord-addr`
787
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700788 # Configuration for ZK address, port
789 local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181")
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700790 # RAMCloud cluster name
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700791 local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700792 # RAMCloud option deadServerTimeout
793 # (note RC default is 250ms, setting relaxed ONOS default to 1000ms)
794 local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000)
795
796 # NOTE RAMCloud document suggests to use -L to specify listen address:port,
797 # but actual RAMCloud code only uses -C argument now.
798 # (FYI: -C is documented to be deprecated in the document)
799
800 local coord_args="-C ${coord_addr}"
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700801 coord_args="${coord_args} --externalStorage ${rc_locator}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700802 coord_args="${coord_args} --clusterName ${rc_cluster_name}"
803
804 # Note: --reset will reset ZK stored info and start running as acoordinator.
805 echo -n "Deleting RAMCloud cluster coordination info ... "
806 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} --reset &> $RAMCLOUD_COORD_LOG &
807
Yuta HIGUCHIcd44eb32014-05-24 16:51:31 -0700808 # TODO Assuming 5 sec is enough. To be sure monitor log?
809 sleep 5
810 # kill coordinator
Yuta HIGUCHIce9f3ee2014-05-14 09:48:40 -0700811 (pkill -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator &> /dev/null)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700812
813 echo "DONE"
814}
Naoki Shiota4e463182014-03-21 15:13:24 -0700815
816function stop-coord {
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700817 kill-processes "RAMCloud coordinator" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator`
Naoki Shiota4e463182014-03-21 15:13:24 -0700818}
819
Naoki Shiota4e463182014-03-21 15:13:24 -0700820### Functions related to RAMCloud server
821function rc-server {
822 case "$1" in
823 start)
Naoki Shiota4e463182014-03-21 15:13:24 -0700824 stop-server
825 start-server
826 ;;
827 startifdown)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700828 local n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700829 if [ $n == 0 ]; then
830 start-server
831 else
832 echo "$n instance of RAMCloud server running"
833 fi
834 ;;
835 stop)
836 stop-server
837 ;;
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700838 deldb)
839 stop-server
840 del-server-backup
841 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700842 stat*) # <- status
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700843 n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700844 echo "$n RAMCloud server running"
845 ;;
846 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700847 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700848 exit 1
849 esac
850}
851
852function start-server {
Yuta HIGUCHI7873c932014-06-02 23:16:18 -0700853 check-and-start-zk
854 wait-zk-or-die
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700855
Naoki Shiota4e463182014-03-21 15:13:24 -0700856 if [ ! -d ${LOGDIR} ]; then
857 mkdir -p ${LOGDIR}
858 fi
859 if [ -f $RAMCLOUD_SERVER_LOG ]; then
860 rotate-log $RAMCLOUD_SERVER_LOG
861 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700862
863 local coord_addr=`rc-coord-addr`
864 local server_addr=`rc-server-addr`
Naoki Shiota4e463182014-03-21 15:13:24 -0700865
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700866 local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.server.masterServiceThreads 5)
867 local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.server.logCleanerThreads 1)
Yuta HIGUCHI52efcbb2014-05-16 09:30:33 -0700868 local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.server.detectFailures 0)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700869
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700870 # Configuration for ZK address, port
871 local rc_locator=$(read-conf ${RAMCLOUD_CONF} ramcloud.locator "zk:localhost:2181")
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700872 # RAMCloud cluster name
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700873 local rc_cluster_name=$(read-conf ${RAMCLOUD_CONF} ramcloud.clusterName ${ONOS_CLUSTER_NAME})
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700874 # RAMCloud transport timeout
875 local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700876 # replication factor (-r) config
877 local rc_replicas=$(read-conf ${ONOS_CONF} ramcloud.server.replicas 0)
878 # backup file path (-f) config
879 local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log")
880 mkdir -p `dirname ${rc_datafile}`
881
882 local server_args="-L ${server_addr}"
Yuta HIGUCHId082b962014-06-02 11:42:22 -0700883 server_args="${server_args} --externalStorage ${rc_locator}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700884 server_args="${server_args} --clusterName ${rc_cluster_name}"
Yuta HIGUCHIea7eba02014-05-14 11:13:52 -0700885 server_args="${server_args} --timeout ${rc_timeout}"
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700886 server_args="${server_args} --masterServiceThreads ${masterServiceThreads}"
887 server_args="${server_args} --logCleanerThreads ${logCleanerThreads}"
888 server_args="${server_args} --detectFailures ${detectFailures}"
889 server_args="${server_args} --replicas ${rc_replicas}"
890 server_args="${server_args} --file ${rc_datafile}"
891
892 # Read environment variables if set
893 server_args="${server_args} ${RC_SERVER_OPTS}"
Yuta HIGUCHI45bc3cf2014-04-19 18:12:15 -0700894
Naoki Shiota4e463182014-03-21 15:13:24 -0700895 # Run ramcloud
896 echo -n "Starting RAMCloud server ... "
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700897 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server ${server_args} > $RAMCLOUD_SERVER_LOG 2>&1 &
Naoki Shiota4e463182014-03-21 15:13:24 -0700898 echo "STARTED"
899}
900
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700901function del-server-backup {
Naoki Shiota9109a1e2014-05-13 11:11:01 -0700902 echo -n "Delete RAMCloud backup server data [y/N]? "
903 while [ 1 ]; do
904 read key
905 if [ "${key}" == "Y" -o "${key}" == "y" ]; then
906 break
907 elif [ -z "${key}" -o "${key}" == "N" -o "${key}" == "n" ]; then
908 echo "Cancelled."
909 return
910 fi
911 echo "[y/N]? "
912 done
913
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700914 echo -n "Removing RAMCloud backup server data ... "
915 local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log")
916 rm -f ${rc_datafile}
917 echo "DONE"
918}
919
Naoki Shiota4e463182014-03-21 15:13:24 -0700920function stop-server {
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700921 kill-processes "RAMCloud server" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server`
Naoki Shiota4e463182014-03-21 15:13:24 -0700922}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700923############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700924
925
Naoki Shiota590c18d2014-03-31 17:52:59 -0700926## Functions related to ONOS core process ##
Naoki Shiota4e463182014-03-21 15:13:24 -0700927function onos {
Naoki Shiota590c18d2014-03-31 17:52:59 -0700928 CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME}
Naoki Shiota4e463182014-03-21 15:13:24 -0700929 if [ ! -f ${CPFILE} ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700930 echo "ONOS core needs to be built"
Naoki Shiota4e463182014-03-21 15:13:24 -0700931 ${MVN} -f ${ONOS_HOME}/pom.xml compile
932 fi
933 JAVA_CP=`cat ${CPFILE}`
934 JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
935
936 case "$1" in
937 start)
938 stop-onos
939 start-onos
940 ;;
941 startnokill)
942 start-onos
943 ;;
944 startifdown)
945 n=`jps -l | grep "${MAIN_CLASS}" | wc -l`
946 if [ $n == 0 ]; then
947 start-onos
948 else
949 echo "$n instance of onos running"
950 fi
951 ;;
952 stop)
953 stop-onos
954 ;;
955 stat*) # <- status
956 n=`jps -l | grep "${MAIN_CLASS}" | wc -l`
957 echo "$n instance of onos running"
958 ;;
959 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700960 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700961 exit 1
962 esac
963}
964
965function start-onos {
966 if [ ! -d ${LOGDIR} ]; then
967 mkdir -p ${LOGDIR}
968 fi
Yuta HIGUCHI04713972014-05-30 11:01:17 -0700969 # Rotate log files
Naoki Shiota4e463182014-03-21 15:13:24 -0700970 for log in ${LOGS}; do
971 if [ -f ${log} ]; then
972 rotate-log ${log}
973 fi
974 done
Yuta HIGUCHI04713972014-05-30 11:01:17 -0700975
976 # Rotate logs rolled at runtime.
977 local rolled_log_shellpat=`echo ${ONOS_LOG_ROLLING_PATTERN} | sed -e "s/%i/\\*/"`
978 for rolled_log in ${rolled_log_shellpat}; do
979 if [ -f ${rolled_log} ]; then
980 rotate-log ${rolled_log}
Yuta HIGUCHI04713972014-05-30 11:01:17 -0700981 fi
982 done
983
Naoki Shiota4e463182014-03-21 15:13:24 -0700984 if [ ! -f ${ONOS_LOGBACK} ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700985 echo "[WARNING] ${ONOS_LOGBACK} not found."
986 echo " Run \"\$ $0 setup\" to create."
987 exit 1
Naoki Shiota4e463182014-03-21 15:13:24 -0700988 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700989
Yuta HIGUCHI3ebc9482014-05-08 16:28:28 -0700990 if [ ! -f ${HC_CONF} ]; then
991 echo "[WARNING] ${HC_CONF} not found."
992 echo " Run \"\$ $0 setup\" to create."
993 exit 1
994 fi
995
Yuta HIGUCHI85de40d2014-06-12 14:06:41 -0700996 # specify ZooKeeper(curator) namespace
997 JVM_OPTS="${JVM_OPTS} -Dzookeeper.namespace=${ONOS_CLUSTER_NAME}"
998
Yuta HIGUCHI5f1ce1c2014-07-20 22:43:54 -0700999 # specify ZooKeeper connectionString
1000 local zk_locator=`echo "${ZK_HOSTS}" | sed -e "s/,/:${ZK_CLIENTPORT},/g"`
1001 zk_locator+=":${ZK_CLIENTPORT}"
1002 zk_locator="localhost:${ZK_CLIENTPORT},${zk_locator}"
1003
1004 JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.registry.ZookeeperRegistry.connectionString=${zk_locator}"
1005
Yuta HIGUCHI3ebc9482014-05-08 16:28:28 -07001006 # specify hazelcast.xml to datagrid
1007 JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig=${HC_CONF}"
1008
1009 # specify backend config
Jonathan Hartef3dc1a2014-04-03 11:39:50 -07001010 JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.backend=${ONOS_HOST_BACKEND}"
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -07001011 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
1012 JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}"
Yuta HIGUCHI3ebc9482014-05-08 16:28:28 -07001013 elif [ "${ONOS_HOST_BACKEND}" = "hazelcast" ]; then
1014 JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.hazelcast.baseConfig=${HC_CONF}"
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -07001015 fi
1016
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -07001017 # check for jvm debug flag
Yuta HIGUCHI32532ea2014-08-01 15:52:55 -07001018 if [ "${ONOS_DEBUG}" == "true" ]; then
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -07001019 JVM_OPTS="${JVM_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${JVM_DEBUG_PORT}"
1020 fi
1021
Naoki Shiota9df15d32014-03-27 14:26:20 -07001022 # Run ONOS
Yuta HIGUCHIcce4f622014-04-18 16:48:53 -07001023
1024 # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD
1025 cd ${ONOS_HOME}
1026
Yuta HIGUCHId150ece2014-04-29 16:25:36 -07001027 echo -n "Starting ONOS controller ... "
Naoki Shiota4e463182014-03-21 15:13:24 -07001028 java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr &
1029
1030 # We need to wait a bit to find out whether starting the ONOS process succeeded
1031 sleep 1
1032
1033 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Naoki Shiota9df15d32014-03-27 14:26:20 -07001034 if [ $n -ge 1 ]; then
Naoki Shiota4e463182014-03-21 15:13:24 -07001035 echo " STARTED"
1036 else
1037 echo " FAILED"
1038 fi
1039
1040# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
1041# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
1042}
1043
1044function stop-onos {
1045 kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'`
1046# kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
1047}
Naoki Shiota590c18d2014-03-31 17:52:59 -07001048############################################
Naoki Shiota4e463182014-03-21 15:13:24 -07001049
1050
Naoki Shiota590c18d2014-03-31 17:52:59 -07001051################## Main ####################
Naoki Shiota4e463182014-03-21 15:13:24 -07001052case "$1" in
Naoki Shiota9df15d32014-03-27 14:26:20 -07001053 setup)
Naoki Shiota4e928512014-04-03 15:49:35 -07001054 create-confs $2
Naoki Shiota9df15d32014-03-27 14:26:20 -07001055 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -07001056 start)
Naoki Shiota9df15d32014-03-27 14:26:20 -07001057 mode_parameter=${ONOS_HOST_ROLE}
1058 if [ ! -z "$2" ]; then
1059 mode_parameter=$2
1060 fi
Praseed Balakrishnan418c7b22014-06-16 13:33:53 -07001061
Naoki Shiota9df15d32014-03-27 14:26:20 -07001062 case "${mode_parameter}" in
Naoki Shiota4e463182014-03-21 15:13:24 -07001063 single-node)
1064 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -07001065 start-backend coord
1066 start-backend server
Naoki Shiota4e463182014-03-21 15:13:24 -07001067 onos startifdown
1068 ;;
1069 coord-node)
1070 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -07001071 start-backend coord
Naoki Shiota4e463182014-03-21 15:13:24 -07001072 onos startifdown
1073 ;;
1074 server-node)
1075 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -07001076 start-backend server
1077 onos startifdown
1078 ;;
1079 coord-and-server-node)
1080 zk start
1081 start-backend coord
1082 start-backend server
Naoki Shiota4e463182014-03-21 15:13:24 -07001083 onos startifdown
1084 ;;
1085 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -07001086 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -07001087 ;;
1088 esac
1089 echo
1090 ;;
1091 stop)
1092 on=`jps -l | grep "${MAIN_CLASS}" | wc -l`
1093 if [ $on != 0 ]; then
1094 onos stop
1095 fi
1096
Naoki Shiota9df15d32014-03-27 14:26:20 -07001097 stop-backend
Naoki Shiota4e463182014-03-21 15:13:24 -07001098
1099 zkn=`jps -l | grep org.apache.zookeeper.server | wc -l`
1100 if [ $zkn != 0 ]; then
1101 zk stop
1102 fi
1103 echo
1104 ;;
1105 restart)
1106 on=`jps -l | grep "${MAIN_CLASS}" | wc -l`
1107 if [ $on != 0 ]; then
1108 onos stop
1109 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001110
Naoki Shiota4e463182014-03-21 15:13:24 -07001111 rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l`
1112 if [ $rcsn != 0 ]; then
1113 rc-server stop
1114 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001115
Naoki Shiota590c18d2014-03-31 17:52:59 -07001116 rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -07001117 if [ $rccn != 0 ]; then
1118 rc-coord stop
1119 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001120
Naoki Shiota4e463182014-03-21 15:13:24 -07001121 zkn=`jps -l | grep org.apache.zookeeper.server | wc -l`
1122 if [ $zkn != 0 ]; then
1123 zk restart
1124 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001125
Naoki Shiota4e463182014-03-21 15:13:24 -07001126 if [ $rccn != 0 ]; then
1127 rc-coord startifdown
1128 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001129
Naoki Shiota4e463182014-03-21 15:13:24 -07001130 if [ $rcsn != 0 ]; then
1131 rc-server startifdown
1132 fi
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001133
Naoki Shiota4e463182014-03-21 15:13:24 -07001134 if [ $on != 0 ]; then
1135 onos startifdown
1136 fi
1137 echo
1138 ;;
1139 stat*) # <- status
1140 echo '[ZooKeeper]'
1141 zk status
1142 echo
1143 echo '[RAMCloud coordinator]'
1144 rc-coord status
1145 echo
1146 echo '[RAMCloud server]'
1147 rc-server status
1148 echo
1149 echo '[ONOS core]'
1150 onos status
1151 echo
1152 ;;
1153 zk)
1154 zk $2
1155 ;;
1156 rc-c*) # <- rc-coordinator
1157 rc-coord $2
1158 ;;
1159 rc-s*) # <- rc-server
1160 rc-server $2
1161 ;;
Yuta HIGUCHId150ece2014-04-29 16:25:36 -07001162 rc)
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001163 # XXX rc command ignores if the host is not configured to have those roles,
1164 # while rc-s or rc-c executes the task regardless of role definition.
1165 # This is a workaround since TestON does not take role in account
1166 # and always issue rc deldb right now.
1167
Naoki Shiota9109a1e2014-05-13 11:11:01 -07001168 # TODO make deldb command more organized (clarify when it can work)
Yuta HIGUCHI259b79a2014-06-04 12:21:22 -07001169 if [ "`is-coord-role`" == "true" ]; then
1170 rc-coord $2
1171 fi
1172 if [ "`is-server-role`" == "true" ]; then
1173 rc-server $2
1174 fi
Yuta HIGUCHId150ece2014-04-29 16:25:36 -07001175 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -07001176 core)
1177 onos $2
1178 ;;
1179 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -07001180 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -07001181 exit 1
1182esac
Naoki Shiota590c18d2014-03-31 17:52:59 -07001183