blob: e6d7d6885f553374db248013fc973405544a6470 [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`)
Naoki Shiota590c18d2014-03-31 17:52:59 -070011# $RAMCLOUD_HOME : path of root directory of RAMCloud repository (~/ramcloud)
12# $RAMCLOUD_BRANCH : branch name of RAMCloud to use (master)
Naoki Shiota72209722014-04-08 14:32:17 -070013# $ZK_HOME : path of root directory of ZooKeeper (~/zookeeper-3.4.5)
14# $ZK_LIB_DIR : path of ZooKeeper library (/var/lib/zookeeper)
Naoki Shiotad8ea71a2014-04-23 17:04:51 -070015# $ZK_LOG_DIR : path of ZooKeeper log output directory (~/ONOS/onos-logs/zk-`hostname`)
Naoki Shiota590c18d2014-03-31 17:52:59 -070016# $JVM_OPTS : JVM options ONOS starts with
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070017# $ZK_CONF : path of ZooKeeper config file (~/ONOS/conf/zoo.cfg)
18# $HC_CONF : path of Hazelcast config file (~/ONOS/conf/hazelcast.xml)
19# $RAMCLOUD_CONF : path of RAMCloud config file (~/ONOS/conf/ramcloud.conf)
Naoki Shiota590c18d2014-03-31 17:52:59 -070020#####################################################
21
Naoki Shiota590c18d2014-03-31 17:52:59 -070022ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)}
Naoki Shiota9df15d32014-03-27 14:26:20 -070023ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf}
Naoki Shiota9a1e6d12014-04-03 14:47:12 -070024ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.`hostname`.conf}
Naoki Shiota590c18d2014-03-31 17:52:59 -070025
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070026source ${ONOS_HOME}/scripts/common/utils.sh
27
Naoki Shiota590c18d2014-03-31 17:52:59 -070028if [ ! -f ${ONOS_CONF} ]; then
Naoki Shiota9a1e6d12014-04-03 14:47:12 -070029 # falling back to default config file
30 ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf
31 if [ ! -f ${ONOS_CONF} ]; then
32 echo "${ONOS_CONF} not found."
33 exit 1
34 fi
Naoki Shiota590c18d2014-03-31 17:52:59 -070035fi
Naoki Shiota4e928512014-04-03 15:49:35 -070036
37
38### Variables read from ONOS config file ###
39ONOS_HOST_NAME=$(read-conf ${ONOS_CONF} host.name `hostname`)
40ONOS_HOST_IP=$(read-conf ${ONOS_CONF} host.ip)
41ONOS_HOST_ROLE=$(read-conf ${ONOS_CONF} host.role)
42ONOS_HOST_BACKEND=$(read-conf ${ONOS_CONF} host.backend)
43ZK_HOSTS=$(read-conf ${ONOS_CONF} zookeeper.hosts ${ONOS_HOST_NAME})
44RC_COORD_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.coordinator.protocol "fast+udp")
45RC_COORD_IP=$(read-conf ${ONOS_CONF} ramcloud.coordinator.ip ${ONOS_HOST_IP})
46RC_COORD_PORT=$(read-conf ${ONOS_CONF} ramcloud.coordinator.port 12246)
47RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp")
48RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP})
49RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242)
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070050HC_HOST_PORT=$(read-conf ${ONOS_CONF} hazelcast.host.port 5701)
Naoki Shiota4e928512014-04-03 15:49:35 -070051HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members)
52HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3")
53HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327)
Naoki Shiota590c18d2014-03-31 17:52:59 -070054############################################
55
56
57############## Other variables #############
Naoki Shiota4e928512014-04-03 15:49:35 -070058ONOS_TEMPLATE_DIR=${ONOS_CONF_DIR}/template
59
Naoki Shiota4e463182014-03-21 15:13:24 -070060LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
61
Naoki Shiota72209722014-04-08 14:32:17 -070062ZK_HOME=${ZK_HOME:-~/zookeeper-3.4.5}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070063ZK_CONF=${ZK_CONF:-${ONOS_CONF_DIR}/zoo.cfg}
Naoki Shiota4e928512014-04-03 15:49:35 -070064ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -070065# Adding ONOS_HOST_NAME dir since file name (zookeeper.out) cannot be controlled.
Naoki Shiotad8ea71a2014-04-23 17:04:51 -070066ZK_LOG_DIR=${ZK_LOG_DIR:-${ONOS_HOME}/onos-logs/zk-${ONOS_HOST_NAME}}
Naoki Shiota72209722014-04-08 14:32:17 -070067ZK_LIB_DIR=${ZK_LIB_DIR:-/var/lib/zookeeper}
Naoki Shiota9df15d32014-03-27 14:26:20 -070068ZK_MY_ID=${ZK_LIB_DIR}/myid
Naoki Shiota4e463182014-03-21 15:13:24 -070069
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070070HC_CONF=${HC_CONF:-${ONOS_CONF_DIR}/hazelcast.xml}
Naoki Shiota4e928512014-04-03 15:49:35 -070071HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template
72
Naoki Shiota4e463182014-03-21 15:13:24 -070073RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
Naoki Shiota590c18d2014-03-31 17:52:59 -070074RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log
75RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log
Naoki Shiota4e463182014-03-21 15:13:24 -070076RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -070077RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_CONF_DIR}/ramcloud.conf}
Naoki Shiota4e463182014-03-21 15:13:24 -070078
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -070079export LD_LIBRARY_PATH=${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}:$LD_LIBRARY_PATH
Naoki Shiota4e463182014-03-21 15:13:24 -070080
81## 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 -070082ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_CONF_DIR}/logback.${ONOS_HOST_NAME}.xml}
Naoki Shiota9df15d32014-03-27 14:26:20 -070083ONOS_LOGBACK_BACKUP=${ONOS_LOGBACK}.bak
Naoki Shiota4e928512014-04-03 15:49:35 -070084ONOS_LOGBACK_TEMPLATE=${ONOS_TEMPLATE_DIR}/logback.xml.template
Naoki Shiota4e463182014-03-21 15:13:24 -070085LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
Naoki Shiota590c18d2014-03-31 17:52:59 -070086LOGBASE=${ONOS_LOGBASE:-onos.${ONOS_HOST_NAME}}
Naoki Shiota4e463182014-03-21 15:13:24 -070087ONOS_LOG="${LOGDIR}/${LOGBASE}.log"
88PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap"
89LOGS="$ONOS_LOG $PCAP_LOG"
90
Naoki Shiota9df15d32014-03-27 14:26:20 -070091ONOS_PROPS=${ONOS_PROPS:-${ONOS_CONF_DIR}/onos.properties}
Naoki Shiota4e463182014-03-21 15:13:24 -070092JMX_PORT=${JMX_PORT:-7189}
93
94# Set JVM options
95JVM_OPTS="${JVM_OPTS:-}"
Naoki Shiota4e463182014-03-21 15:13:24 -070096JVM_OPTS="$JVM_OPTS -server -d64"
97#JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
Yuta HIGUCHI18354592014-04-01 13:53:42 -070098
99# Uncomment or specify appropriate value as JVM_OPTS environment variables.
100#JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
Naoki Shiota4e463182014-03-21 15:13:24 -0700101#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
102#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700103
104#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC"
105JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC"
106JVM_OPTS="$JVM_OPTS -XX:+AggressiveOpts"
107
108# We may want to remove UseFastAccessorMethods option: http://bugs.java.com/view_bug.do?bug_id=6385687
109JVM_OPTS="$JVM_OPTS -XX:+UseFastAccessorMethods"
110
111JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192"
112JVM_OPTS="$JVM_OPTS -XX:FreqInlineSize=8192"
113JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500"
114
Naoki Shiota4e463182014-03-21 15:13:24 -0700115JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700116
117# Workaround for Thread Priority http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html
118JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42"
119
120JVM_OPTS="$JVM_OPTS -XX:+UseCompressedOops"
121
122JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT"
123JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false"
124JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
125
Naoki Shiota4e463182014-03-21 15:13:24 -0700126JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
127
Naoki Shiotad8ea71a2014-04-23 17:04:51 -0700128JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig=${HC_CONF}"
129
Yuta HIGUCHI18354592014-04-01 13:53:42 -0700130# Uncomment to dump final JVM flags to stdout
131#JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal"
132
Naoki Shiota4e463182014-03-21 15:13:24 -0700133# Set ONOS core main class
Jonathan Hart51f6f5b2014-04-03 10:32:10 -0700134MAIN_CLASS="net.onrc.onos.core.main.Main"
Naoki Shiota4e463182014-03-21 15:13:24 -0700135
136MVN=${MVN:-mvn -o}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700137############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700138
Naoki Shiota9df15d32014-03-27 14:26:20 -0700139
Naoki Shiota590c18d2014-03-31 17:52:59 -0700140############# Common functions #############
141function print_usage {
Naoki Shiota05721b32014-04-29 14:41:12 -0700142 local scriptname=`basename $0`
Naoki Shiota590c18d2014-03-31 17:52:59 -0700143 local filename=`basename ${ONOS_CONF}`
144 local usage="Usage: setup/start/stop ONOS on this server.
Naoki Shiota05721b32014-04-29 14:41:12 -0700145 \$ ${scriptname} setup [-f]
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700146 Set up ONOS node using ${ONOS_CONF} .
Naoki Shiota590c18d2014-03-31 17:52:59 -0700147 - generate and replace config file of ZooKeeper.
148 - create myid in ZooKeeper datadir.
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700149 - generate and replace config file for Hazelcast.
150 - generate and replace config file for RAMCloud.
Naoki Shiota590c18d2014-03-31 17:52:59 -0700151 - generate and replace logback.${ONOS_HOST_NAME}.xml
152 If -f option is used, all existing files will be overwritten without confirmation.
Naoki Shiota05721b32014-04-29 14:41:12 -0700153 \$ ${scriptname} start [single-node|coord-node|server-node|coord-and-server-node]
Naoki Shiota590c18d2014-03-31 17:52:59 -0700154 Start ONOS node with specific RAMCloud entities
155 - single-node: start ONOS with stand-alone RAMCloud
156 - coord-node : start ONOS with RAMCloud coordinator
157 - server-node: start ONOS with RAMCloud server
158 - coord-and-server-node: start ONOS with RAMCloud coordinator and server
159 * Default behavior can be defined by ${filename}
Naoki Shiota05721b32014-04-29 14:41:12 -0700160 \$ ${scriptname} stop
Naoki Shiota590c18d2014-03-31 17:52:59 -0700161 Stop all ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700162 \$ ${scriptname} restart
Naoki Shiota590c18d2014-03-31 17:52:59 -0700163 Stop and start currently running ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700164 \$ ${scriptname} status
Naoki Shiota590c18d2014-03-31 17:52:59 -0700165 Show status of ONOS-related processes
Naoki Shiota05721b32014-04-29 14:41:12 -0700166 \$ ${scriptname} {zk|rc-coord|rc-server|core} {start|stop|restart|status}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700167 Control specific ONOS-related process"
168
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700169 echo "${usage}"
Naoki Shiota4e463182014-03-21 15:13:24 -0700170}
171
172function rotate-log {
Naoki Shiota4e928512014-04-03 15:49:35 -0700173 local logfile=$1
174 local nr_max=${2:-10}
175 if [ -f $logfile ]; then
176 for i in `seq $(expr $nr_max - 1) -1 1`; do
177 if [ -f ${logfile}.${i} ]; then
178 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
179 fi
180 done
181 mv $logfile $logfile.1
182 fi
Naoki Shiota4e463182014-03-21 15:13:24 -0700183}
184
185# kill-processes {module-name} {array of pids}
186function kill-processes {
187 # Kill the existing processes
188 local pids=$2
Naoki Shiota9df15d32014-03-27 14:26:20 -0700189 if [ ! -z "$pids" ]; then
Naoki Shiota4e463182014-03-21 15:13:24 -0700190 echo -n "Stopping $1 ... "
191 fi
192 for p in ${pids}; do
193 if [ x$p != "x" ]; then
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700194 (
195 # Ask process with SIGTERM first, if that did not kill the process
196 # wait 1s and if process still exist, force process to be killed.
197 kill -TERM $p && kill -0 $p && sleep 1 && kill -0 $p && kill -KILL $p
198 ) 2> /dev/null
Naoki Shiota4e463182014-03-21 15:13:24 -0700199 echo "Killed existing process (pid: $p)"
200 fi
201 done
202}
203
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700204function handle-error {
205 set -e
206
207 revert-confs
208
209 set +e
210
211 exit 1
212}
213
Naoki Shiota4e928512014-04-03 15:49:35 -0700214# revert-confs [error message]
215function revert-confs {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700216 echo -n "ERROR occurred ... "
Naoki Shiota9df15d32014-03-27 14:26:20 -0700217
Naoki Shiota4e928512014-04-03 15:49:35 -0700218 revert-file `basename ${ZK_CONF}`
219 revert-file `basename ${HC_CONF}`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700220
221 echo "EXIT"
222
223 if [ ! -z "$1" ]; then
224 echo $1
225 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700226}
227
Naoki Shiota590c18d2014-03-31 17:52:59 -0700228function create-zk-conf {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700229 echo -n "Creating ${ZK_CONF} ... "
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700230
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700231 # Create the ZooKeeper lib directory
232 if [ ! -d ${ZK_LIB_DIR} ]; then
233 local SUDO=${SUDO:-}
234 local whoami=`whoami`
235 {
236 ${SUDO} mkdir ${ZK_LIB_DIR}
237 ${SUDO} chown ${whoami} ${ZK_LIB_DIR}
238 } || {
239 echo "FAILED"
240 echo "[ERROR] Failed to create directory ${ZK_LIB_DIR}."
241 echo "[ERROR] Please retry after setting \"env SUDO=sudo\""
242 exit 1
243 }
244 fi
245
246 # creation of ZooKeeper config
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700247 local temp_zk=`begin-conf-creation ${ZK_CONF}`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700248
Naoki Shiota4e928512014-04-03 15:49:35 -0700249 hostarr=`echo ${ZK_HOSTS} | tr "," " "`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700250
251 local i=1
252 local myid=
253 for host in ${hostarr}; do
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700254 if [ "${host}" = "${ONOS_HOST_NAME}" -o "${host}" = "${ONOS_HOST_IP}" ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700255 myid=$i
256 break
257 fi
258 i=`expr $i + 1`
259 done
260
261 if [ -z "${myid}" ]; then
Naoki Shiota590c18d2014-03-31 17:52:59 -0700262 local filename=`basename ${ONOS_CONF}`
Naoki Shiota35f8d5c2014-04-08 11:13:18 -0700263 revert-confs "[ERROR] In ${filename}, zookeeper.hosts must have hostname \"${ONOS_HOST_NAME}\" or IP address"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700264 fi
265
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700266 if [ -f "${ZK_MY_ID}" ]; then
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700267 # sudo will be needed if ZK_MY_ID is already created by other (old) script
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700268 local SUDO=${SUDO:-}
269 {
270 ${SUDO} mv -f ${ZK_MY_ID} ${ZK_MY_ID}.old
271 } || {
272 echo "FAILED"
273 echo "[ERROR] Failed to rename ${ZK_MY_ID}."
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700274 echo "[ERROR] Please retry after setting \"env SUDO=sudo\""
Yuta HIGUCHI69450892014-04-16 09:10:55 -0700275 exit 1
276 }
277 fi
278
Naoki Shiota9df15d32014-03-27 14:26:20 -0700279 echo ${myid} > ${ZK_MY_ID}
280
281 echo -n "myid is assigned to ${myid} ... "
282
283 while read line; do
284 if [[ $line =~ ^__HOSTS__$ ]]; then
285 i=1
286 for host in ${hostarr}; do
287 # TODO: ports might be configurable
288 local hostline="server.${i}=${host}:2888:3888"
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700289 echo $hostline
Naoki Shiota9df15d32014-03-27 14:26:20 -0700290 i=`expr $i + 1`
291 done
292 elif [[ $line =~ __DATADIR__ ]]; then
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700293 echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700294 else
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700295 echo $line
Naoki Shiota9df15d32014-03-27 14:26:20 -0700296 fi
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700297 done < ${ZK_CONF_TEMPLATE} > ${temp_zk}
298
299 end-conf-creation ${ZK_CONF}
Naoki Shiota9df15d32014-03-27 14:26:20 -0700300
301 echo "DONE"
Naoki Shiota590c18d2014-03-31 17:52:59 -0700302}
Naoki Shiota9df15d32014-03-27 14:26:20 -0700303
Naoki Shiota4e928512014-04-03 15:49:35 -0700304function create-hazelcast-conf {
305 echo -n "Creating ${HC_CONF} ... "
306
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700307 local temp_hc=`begin-conf-creation ${HC_CONF}`
Naoki Shiota4e928512014-04-03 15:49:35 -0700308
309 # To keep indent of XML file, change IFS
310 local IFS=''
311 while read line; do
312 if [[ $line =~ __HC_NETWORK__ ]]; then
313 if [ ! -z "${HC_TCPIP_MEMBERS}" ]; then
314 # temporary change
315 IFS=' '
316 local memberarr=`echo ${HC_TCPIP_MEMBERS} | tr "," " "`
317 echo '<multicast enabled="false" />'
318 echo '<tcp-ip enabled="true">'
319 for member in ${memberarr}; do
320 echo " <member>${member}</member>"
321 done
322 echo '</tcp-ip>'
323 IFS=''
324 else
325 echo '<multicast enabled="true">'
326 echo " <multicast-group>${HC_MULTICAST_GROUP}</multicast-group>"
327 echo " <multicast-port>${HC_MULTICAST_PORT}</multicast-port>"
328 echo '</multicast>'
329 echo '<tcp-ip enabled="false" />'
330 fi
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700331 elif [[ $line =~ __HC_PORT__ ]]; then
332 echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|"
Naoki Shiota4e928512014-04-03 15:49:35 -0700333 else
334 echo "${line}"
335 fi
336 done < ${HC_CONF_TEMPLATE} > ${temp_hc}
337
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700338 end-conf-creation ${HC_CONF}
Naoki Shiota4e928512014-04-03 15:49:35 -0700339
340 echo "DONE"
341}
342
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700343function create-ramcloud-conf {
344 echo -n "Creating ${RAMCLOUD_CONF} ... "
345
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700346 local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}`
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700347
348 local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC")
349
350 # TODO make ZooKeeper address configurable.
351 echo "ramcloud.locator=zk:localhost:2181" > ${temp_rc}
352 echo "ramcloud.clusterName=${rc_cluster_name}" >> ${temp_rc}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700353
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700354 end-conf-creation ${RAMCLOUD_CONF}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700355
356 echo "DONE"
357}
358
Naoki Shiota590c18d2014-03-31 17:52:59 -0700359function create-logback-conf {
Naoki Shiota9df15d32014-03-27 14:26:20 -0700360 echo -n "Creating ${ONOS_LOGBACK} ... "
Naoki Shiota590c18d2014-03-31 17:52:59 -0700361
Naoki Shiota9df15d32014-03-27 14:26:20 -0700362 # creation of logback config
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700363 local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}`
364
365 sed -e "s|__FILENAME__|${ONOS_LOG}|" ${ONOS_LOGBACK_TEMPLATE} > ${temp_lb}
366
367 end-conf-creation ${ONOS_LOGBACK}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700368
Naoki Shiota9df15d32014-03-27 14:26:20 -0700369 echo "DONE"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700370}
371
Naoki Shiota4e928512014-04-03 15:49:35 -0700372function create-confs {
373 local key
374 local filename
375
Naoki Shiota9a1e6d12014-04-03 14:47:12 -0700376 trap handle-error ERR
Naoki Shiota4e928512014-04-03 15:49:35 -0700377
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700378 echo "Config file : ${ONOS_CONF}"
379
Naoki Shiota4e928512014-04-03 15:49:35 -0700380 if [ "$1" == "-f" ]; then
381 create-zk-conf
382 create-hazelcast-conf
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700383 create-ramcloud-conf
Naoki Shiota4e928512014-04-03 15:49:35 -0700384 create-logback-conf
385 else
386 create-conf-interactive ${ZK_CONF} create-zk-conf
387 create-conf-interactive ${HC_CONF} create-hazelcast-conf
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700388 create-conf-interactive ${RAMCLOUD_CONF} create-ramcloud-conf
Naoki Shiota4e928512014-04-03 15:49:35 -0700389 create-conf-interactive ${ONOS_LOGBACK} create-logback-conf
390 fi
Naoki Shiota590c18d2014-03-31 17:52:59 -0700391
392 trap - ERR
393}
394############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700395
Naoki Shiota590c18d2014-03-31 17:52:59 -0700396
397###### Functions related to ZooKeeper ######
Naoki Shiota4e463182014-03-21 15:13:24 -0700398function zk {
399 case "$1" in
400 start)
401 start-zk
402 ;;
403 stop)
404 stop-zk
405 ;;
406 stat*) # <- status
407 status-zk
408 ;;
409 re*) # <- restart
410 stop-zk
411 start-zk
412 ;;
413 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700414 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700415 exit 1
416 esac
417}
418
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700419function load-zk-cfg {
420 if [ -f "${ZK_CONF}" ]; then
421 local filename=`basename ${ZK_CONF}`
422 local dirname=`dirname ${ZK_CONF}`
423
424 # Run ZooKeeper with our configuration
425 export ZOOCFG=${filename}
426 export ZOOCFGDIR=${dirname}
427 fi
428}
429
Naoki Shiota4e463182014-03-21 15:13:24 -0700430function start-zk {
Pavlin Radoslavovd8f30d92014-04-18 13:03:09 -0700431 echo -n "Starting ZooKeeper ... "
Naoki Shiota9df15d32014-03-27 14:26:20 -0700432
Naoki Shiota4e928512014-04-03 15:49:35 -0700433 export ZOO_LOG_DIR=${ZK_LOG_DIR}
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700434 mkdir -p ${ZK_LOG_DIR}
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700435
436 load-zk-cfg
Naoki Shiota9df15d32014-03-27 14:26:20 -0700437
Naoki Shiota72209722014-04-08 14:32:17 -0700438 ${ZK_HOME}/bin/zkServer.sh start
Naoki Shiota4e463182014-03-21 15:13:24 -0700439}
440
441function stop-zk {
442 kill-processes "ZooKeeper" `jps -l | grep org.apache.zookeeper.server | awk '{print $1}'`
443}
444
445function status-zk {
Naoki Shiotab7eb55d2014-04-21 18:21:36 -0700446 load-zk-cfg
Naoki Shiota9df15d32014-03-27 14:26:20 -0700447
Naoki Shiota72209722014-04-08 14:32:17 -0700448 ${ZK_HOME}/bin/zkServer.sh status
Naoki Shiota4e463182014-03-21 15:13:24 -0700449}
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700450
451function check-zk {
452 # assumption here is that ZK status script is the last command in status-zk.
453 status-zk &> /dev/null
454 local zk_status=$?
455 if [ "$zk_status" -ne 0 ]; then
456 return 1;
457 fi
458 return 0
459}
460
461# wait-zk-or-die {timeout-sec}
462function wait-zk-or-die {
463 local retries=${1:-1}
464 # do-while retries >= 0
465 while true; do
466 check-zk
467 local zk_status=$?
468 if [ "$zk_status" -eq 0 ]; then
469 return 0
470 fi
471 sleep 1;
472 ((retries -= 1))
473 (( retries >= 0 )) || break
474 done
475 echo "ZooKeeper is not running."
476 exit 1
477}
478
Naoki Shiota590c18d2014-03-31 17:52:59 -0700479############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700480
481
Naoki Shiota590c18d2014-03-31 17:52:59 -0700482####### Functions related to RAMCloud ######
Naoki Shiota9df15d32014-03-27 14:26:20 -0700483function start-backend {
484 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
Naoki Shiota590c18d2014-03-31 17:52:59 -0700485 if [ $1 == "coord" ]; then
486 rc-coord startifdown
487 elif [ $1 == "server" ]; then
488 rc-server startifdown
489 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700490 fi
491}
492
493function stop-backend {
494 rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l`
495 if [ $rcsn != 0 ]; then
496 rc-server stop
497 fi
498
Naoki Shiota590c18d2014-03-31 17:52:59 -0700499 rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700500 if [ $rccn != 0 ]; then
501 rc-coord stop
502 fi
503}
504
Naoki Shiota590c18d2014-03-31 17:52:59 -0700505
Naoki Shiota4e463182014-03-21 15:13:24 -0700506### Functions related to RAMCloud coordinator
Naoki Shiota9df15d32014-03-27 14:26:20 -0700507function rc-coord-addr {
Naoki Shiota4e928512014-04-03 15:49:35 -0700508 echo "${RC_COORD_PROTOCOL}:host=${RC_COORD_IP},port=${RC_COORD_PORT}"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700509}
510
511function rc-server-addr {
Naoki Shiota4e928512014-04-03 15:49:35 -0700512 echo "${RC_SERVER_PROTOCOL}:host=${RC_SERVER_IP},port=${RC_SERVER_PORT}"
Naoki Shiota9df15d32014-03-27 14:26:20 -0700513}
514
Naoki Shiota4e463182014-03-21 15:13:24 -0700515function rc-coord {
516 case "$1" in
517 start)
Naoki Shiota4e463182014-03-21 15:13:24 -0700518 stop-coord
519 start-coord
520 ;;
521 startifdown)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700522 local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700523 if [ $n == 0 ]; then
524 start-coord
525 else
526 echo "$n instance of RAMCloud coordinator running"
527 fi
528 ;;
529 stop)
530 stop-coord
531 ;;
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700532 deldb)
533 stop-backend
534 del-coord-info
535 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700536 stat*) # <- status
537 local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
538 echo "$n RAMCloud coordinator running"
539 ;;
540 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700541 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700542 exit 1
543 esac
544}
545
546function start-coord {
Yuta HIGUCHI71703322014-05-06 09:17:29 -0700547 wait-zk-or-die 2
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700548
Naoki Shiota4e463182014-03-21 15:13:24 -0700549 if [ ! -d ${LOGDIR} ]; then
550 mkdir -p ${LOGDIR}
551 fi
552 if [ -f $RAMCLOUD_COORD_LOG ]; then
553 rotate-log $RAMCLOUD_COORD_LOG
554 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700555
556 local coord_addr=`rc-coord-addr`
Naoki Shiota4e463182014-03-21 15:13:24 -0700557
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700558 # TODO Configuration for ZK address, port
559 local zk_addr="localhost:2181"
560 # RAMCloud cluster name
561 local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC")
562 # RAMCloud option deadServerTimeout
563 # (note RC default is 250ms, setting relaxed ONOS default to 1000ms)
564 local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000)
565
566 # NOTE RAMCloud document suggests to use -L to specify listen address:port,
567 # but actual RAMCloud code only uses -C argument now.
568 # (FYI: -C is documented to be deprecated in the document)
569
570 local coord_args="-C ${coord_addr}"
571 coord_args="${coord_args} --externalStorage zk:${zk_addr}"
572 coord_args="${coord_args} --clusterName ${rc_cluster_name}"
573 coord_args="${coord_args} --deadServerTimeout ${rc_coord_deadServerTimeout}"
574
575 # Read environment variables if set
576 coord_args="${coord_args} ${RC_COORDINATOR_OPTS}"
577
578 if [ "${ONOS_HOST_ROLE}" == "single-node" ]; then
579 # Note: Following reset is required, since RC restart is considered node failure,
580 # and tries recovery of server, which will never succeed after restart.
581 echo "Role configured to single-node mode. RAMCloud cluster will be reset on each start-up."
582 coord_args="${coord_args} --reset"
583 fi
584
Naoki Shiota4e463182014-03-21 15:13:24 -0700585 # Run ramcloud
586 echo -n "Starting RAMCloud coordinator ... "
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700587 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} > $RAMCLOUD_COORD_LOG 2>&1 &
Naoki Shiota4e463182014-03-21 15:13:24 -0700588 echo "STARTED"
589}
590
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700591function del-coord-info {
592 wait-zk-or-die 1
593
594 if [ ! -d ${LOGDIR} ]; then
595 mkdir -p ${LOGDIR}
596 fi
597 if [ -f $RAMCLOUD_COORD_LOG ]; then
598 rotate-log $RAMCLOUD_COORD_LOG
599 fi
600
601 local coord_addr=`rc-coord-addr`
602
603 # TODO Configuration for ZK address, port
604 local zk_addr="localhost:2181"
605 # RAMCloud cluster name
606 local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC")
607 # RAMCloud option deadServerTimeout
608 # (note RC default is 250ms, setting relaxed ONOS default to 1000ms)
609 local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000)
610
611 # NOTE RAMCloud document suggests to use -L to specify listen address:port,
612 # but actual RAMCloud code only uses -C argument now.
613 # (FYI: -C is documented to be deprecated in the document)
614
615 local coord_args="-C ${coord_addr}"
616 coord_args="${coord_args} --externalStorage zk:${zk_addr}"
617 coord_args="${coord_args} --clusterName ${rc_cluster_name}"
618
619 # Note: --reset will reset ZK stored info and start running as acoordinator.
620 echo -n "Deleting RAMCloud cluster coordination info ... "
621 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} --reset &> $RAMCLOUD_COORD_LOG &
622
623 # TODO Assuming 1sec is enough. To be sure monitor log?
624 sleep 1
625 # Silently kill coordinator
626 (pkill -q -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator &> /dev/null)
627
628 echo "DONE"
629}
Naoki Shiota4e463182014-03-21 15:13:24 -0700630
631function stop-coord {
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700632 kill-processes "RAMCloud coordinator" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator`
Naoki Shiota4e463182014-03-21 15:13:24 -0700633}
634
Naoki Shiota4e463182014-03-21 15:13:24 -0700635### Functions related to RAMCloud server
636function rc-server {
637 case "$1" in
638 start)
Naoki Shiota4e463182014-03-21 15:13:24 -0700639 stop-server
640 start-server
641 ;;
642 startifdown)
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700643 local n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700644 if [ $n == 0 ]; then
645 start-server
646 else
647 echo "$n instance of RAMCloud server running"
648 fi
649 ;;
650 stop)
651 stop-server
652 ;;
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700653 deldb)
654 stop-server
655 del-server-backup
656 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700657 stat*) # <- status
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700658 n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700659 echo "$n RAMCloud server running"
660 ;;
661 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700662 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700663 exit 1
664 esac
665}
666
667function start-server {
Yuta HIGUCHI71703322014-05-06 09:17:29 -0700668 wait-zk-or-die 2
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700669
Naoki Shiota4e463182014-03-21 15:13:24 -0700670 if [ ! -d ${LOGDIR} ]; then
671 mkdir -p ${LOGDIR}
672 fi
673 if [ -f $RAMCLOUD_SERVER_LOG ]; then
674 rotate-log $RAMCLOUD_SERVER_LOG
675 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700676
677 local coord_addr=`rc-coord-addr`
678 local server_addr=`rc-server-addr`
Naoki Shiota4e463182014-03-21 15:13:24 -0700679
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700680 local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.server.masterServiceThreads 5)
681 local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.server.logCleanerThreads 1)
682 local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.server.detectFailures 1)
683
684 # TODO Configuration for ZK address, port
685 local zk_addr="localhost:2181"
686 # RAMCloud cluster name
687 local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC")
688 # replication factor (-r) config
689 local rc_replicas=$(read-conf ${ONOS_CONF} ramcloud.server.replicas 0)
690 # backup file path (-f) config
691 local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log")
692 mkdir -p `dirname ${rc_datafile}`
693
694 local server_args="-L ${server_addr}"
695 server_args="${server_args} --externalStorage zk:${zk_addr}"
696 server_args="${server_args} --clusterName ${rc_cluster_name}"
697 server_args="${server_args} --masterServiceThreads ${masterServiceThreads}"
698 server_args="${server_args} --logCleanerThreads ${logCleanerThreads}"
699 server_args="${server_args} --detectFailures ${detectFailures}"
700 server_args="${server_args} --replicas ${rc_replicas}"
701 server_args="${server_args} --file ${rc_datafile}"
702
703 # Read environment variables if set
704 server_args="${server_args} ${RC_SERVER_OPTS}"
Yuta HIGUCHI45bc3cf2014-04-19 18:12:15 -0700705
Naoki Shiota4e463182014-03-21 15:13:24 -0700706 # Run ramcloud
707 echo -n "Starting RAMCloud server ... "
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700708 ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server ${server_args} > $RAMCLOUD_SERVER_LOG 2>&1 &
Naoki Shiota4e463182014-03-21 15:13:24 -0700709 echo "STARTED"
710}
711
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700712function del-server-backup {
713 # TODO might want confirmation, since data can be lost
714 echo -n "Removing RAMCloud backup server data ... "
715 local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log")
716 rm -f ${rc_datafile}
717 echo "DONE"
718}
719
Naoki Shiota4e463182014-03-21 15:13:24 -0700720function stop-server {
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700721 kill-processes "RAMCloud server" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server`
Naoki Shiota4e463182014-03-21 15:13:24 -0700722}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700723############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700724
725
Naoki Shiota590c18d2014-03-31 17:52:59 -0700726## Functions related to ONOS core process ##
Naoki Shiota4e463182014-03-21 15:13:24 -0700727function onos {
Naoki Shiota590c18d2014-03-31 17:52:59 -0700728 CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME}
Naoki Shiota4e463182014-03-21 15:13:24 -0700729 if [ ! -f ${CPFILE} ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700730 echo "ONOS core needs to be built"
Naoki Shiota4e463182014-03-21 15:13:24 -0700731 ${MVN} -f ${ONOS_HOME}/pom.xml compile
732 fi
733 JAVA_CP=`cat ${CPFILE}`
734 JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
735
736 case "$1" in
737 start)
738 stop-onos
739 start-onos
740 ;;
741 startnokill)
742 start-onos
743 ;;
744 startifdown)
745 n=`jps -l | grep "${MAIN_CLASS}" | wc -l`
746 if [ $n == 0 ]; then
747 start-onos
748 else
749 echo "$n instance of onos running"
750 fi
751 ;;
752 stop)
753 stop-onos
754 ;;
755 stat*) # <- status
756 n=`jps -l | grep "${MAIN_CLASS}" | wc -l`
757 echo "$n instance of onos running"
758 ;;
759 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700760 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700761 exit 1
762 esac
763}
764
765function start-onos {
766 if [ ! -d ${LOGDIR} ]; then
767 mkdir -p ${LOGDIR}
768 fi
769 # Backup log files
770 for log in ${LOGS}; do
771 if [ -f ${log} ]; then
772 rotate-log ${log}
773 fi
774 done
Naoki Shiota9df15d32014-03-27 14:26:20 -0700775
Naoki Shiota4e463182014-03-21 15:13:24 -0700776 if [ ! -f ${ONOS_LOGBACK} ]; then
Naoki Shiota9df15d32014-03-27 14:26:20 -0700777 echo "[WARNING] ${ONOS_LOGBACK} not found."
778 echo " Run \"\$ $0 setup\" to create."
779 exit 1
Naoki Shiota4e463182014-03-21 15:13:24 -0700780 fi
Naoki Shiota9df15d32014-03-27 14:26:20 -0700781
Jonathan Hartef3dc1a2014-04-03 11:39:50 -0700782 JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.backend=${ONOS_HOST_BACKEND}"
Yuta HIGUCHI13d1dbf2014-04-17 20:51:38 -0700783 if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then
784 JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}"
785 fi
786
Naoki Shiota9df15d32014-03-27 14:26:20 -0700787 # Run ONOS
Yuta HIGUCHIcce4f622014-04-18 16:48:53 -0700788
789 # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD
790 cd ${ONOS_HOME}
791
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700792 echo -n "Starting ONOS controller ... "
Naoki Shiota4e463182014-03-21 15:13:24 -0700793 java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr &
794
795 # We need to wait a bit to find out whether starting the ONOS process succeeded
796 sleep 1
797
798 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Naoki Shiota9df15d32014-03-27 14:26:20 -0700799 if [ $n -ge 1 ]; then
Naoki Shiota4e463182014-03-21 15:13:24 -0700800 echo " STARTED"
801 else
802 echo " FAILED"
803 fi
804
805# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
806# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
807}
808
809function stop-onos {
810 kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'`
811# kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
812}
Naoki Shiota590c18d2014-03-31 17:52:59 -0700813############################################
Naoki Shiota4e463182014-03-21 15:13:24 -0700814
815
Naoki Shiota590c18d2014-03-31 17:52:59 -0700816################## Main ####################
Naoki Shiota4e463182014-03-21 15:13:24 -0700817case "$1" in
Naoki Shiota9df15d32014-03-27 14:26:20 -0700818 setup)
Naoki Shiota4e928512014-04-03 15:49:35 -0700819 create-confs $2
Naoki Shiota9df15d32014-03-27 14:26:20 -0700820 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700821 start)
Naoki Shiota9df15d32014-03-27 14:26:20 -0700822 mode_parameter=${ONOS_HOST_ROLE}
823 if [ ! -z "$2" ]; then
824 mode_parameter=$2
825 fi
826
827 case "${mode_parameter}" in
Naoki Shiota4e463182014-03-21 15:13:24 -0700828 single-node)
829 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -0700830 start-backend coord
831 start-backend server
Naoki Shiota4e463182014-03-21 15:13:24 -0700832 onos startifdown
833 ;;
834 coord-node)
835 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -0700836 start-backend coord
Naoki Shiota4e463182014-03-21 15:13:24 -0700837 onos startifdown
838 ;;
839 server-node)
840 zk start
Naoki Shiota590c18d2014-03-31 17:52:59 -0700841 start-backend server
842 onos startifdown
843 ;;
844 coord-and-server-node)
845 zk start
846 start-backend coord
847 start-backend server
Naoki Shiota4e463182014-03-21 15:13:24 -0700848 onos startifdown
849 ;;
850 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700851 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700852 ;;
853 esac
854 echo
855 ;;
856 stop)
857 on=`jps -l | grep "${MAIN_CLASS}" | wc -l`
858 if [ $on != 0 ]; then
859 onos stop
860 fi
861
Naoki Shiota9df15d32014-03-27 14:26:20 -0700862 stop-backend
Naoki Shiota4e463182014-03-21 15:13:24 -0700863
864 zkn=`jps -l | grep org.apache.zookeeper.server | wc -l`
865 if [ $zkn != 0 ]; then
866 zk stop
867 fi
868 echo
869 ;;
870 restart)
871 on=`jps -l | grep "${MAIN_CLASS}" | wc -l`
872 if [ $on != 0 ]; then
873 onos stop
874 fi
875
876 rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l`
877 if [ $rcsn != 0 ]; then
878 rc-server stop
879 fi
880
Naoki Shiota590c18d2014-03-31 17:52:59 -0700881 rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
Naoki Shiota4e463182014-03-21 15:13:24 -0700882 if [ $rccn != 0 ]; then
883 rc-coord stop
884 fi
885
886 zkn=`jps -l | grep org.apache.zookeeper.server | wc -l`
887 if [ $zkn != 0 ]; then
888 zk restart
889 fi
890
891 if [ $rccn != 0 ]; then
892 rc-coord startifdown
893 fi
894
895 if [ $rcsn != 0 ]; then
896 rc-server startifdown
897 fi
898
899 if [ $on != 0 ]; then
900 onos startifdown
901 fi
902 echo
903 ;;
904 stat*) # <- status
905 echo '[ZooKeeper]'
906 zk status
907 echo
908 echo '[RAMCloud coordinator]'
909 rc-coord status
910 echo
911 echo '[RAMCloud server]'
912 rc-server status
913 echo
914 echo '[ONOS core]'
915 onos status
916 echo
917 ;;
918 zk)
919 zk $2
920 ;;
921 rc-c*) # <- rc-coordinator
922 rc-coord $2
923 ;;
924 rc-s*) # <- rc-server
925 rc-server $2
926 ;;
Yuta HIGUCHId150ece2014-04-29 16:25:36 -0700927 rc)
928 rc-coord $2
929 rc-server $2
930 ;;
Naoki Shiota4e463182014-03-21 15:13:24 -0700931 core)
932 onos $2
933 ;;
934 *)
Naoki Shiota590c18d2014-03-31 17:52:59 -0700935 print_usage
Naoki Shiota4e463182014-03-21 15:13:24 -0700936 exit 1
937esac
Naoki Shiota590c18d2014-03-31 17:52:59 -0700938