Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 2 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 3 | ### Env vars used by this script. (default value) ### |
| 4 | # $ONOS_HOME : path of root directory of ONOS repository (this script's dir) |
| 5 | # $ONOS_CONF_DIR : path of ONOS config directory (~/ONOS/conf) |
| 6 | # $ONOS_CONF : path of ONOS node config file (~/ONOS/conf/onos_node.conf) |
| 7 | # $ONOS_PROPS : path of ONOS properties file (~/ONOS/conf/onos.properties) |
| 8 | # $ONOS_LOGBACK : path of logback config file (~/ONOS/conf/logback.`hostname`.xml) |
| 9 | # $LOGDIR : path of log output directory (~/ONOS/onos-logs) |
| 10 | # $LOGBASE : base name of log output file (onos.`hostname`) |
| 11 | # $RAMCLOUD_HOME : path of root directory of RAMCloud repository (~/ramcloud) |
| 12 | # $RAMCLOUD_BRANCH : branch name of RAMCloud to use (master) |
| 13 | # $JVM_OPTS : JVM options ONOS starts with |
| 14 | ##################################################### |
| 15 | |
| 16 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 17 | # read-conf {filename} {parameter name} [default value] |
| 18 | function read-conf { |
| 19 | local value=`grep ^${2} ${1} | cut -d "=" -f 2 | sed -e 's/^[ \t]*//'` |
| 20 | if [ -z "${value}" ]; then |
| 21 | echo $3 |
| 22 | else |
| 23 | echo ${value} |
| 24 | fi |
| 25 | } |
| 26 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 27 | ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 28 | ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 29 | ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.conf} |
| 30 | |
| 31 | if [ ! -f ${ONOS_CONF} ]; then |
| 32 | echo "${ONOS_CONF} not found." |
| 33 | exit 1 |
| 34 | fi |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 35 | |
| 36 | |
| 37 | ### Variables read from ONOS config file ### |
| 38 | ONOS_HOST_NAME=$(read-conf ${ONOS_CONF} host.name `hostname`) |
| 39 | ONOS_HOST_IP=$(read-conf ${ONOS_CONF} host.ip) |
| 40 | ONOS_HOST_ROLE=$(read-conf ${ONOS_CONF} host.role) |
| 41 | ONOS_HOST_BACKEND=$(read-conf ${ONOS_CONF} host.backend) |
| 42 | ZK_HOSTS=$(read-conf ${ONOS_CONF} zookeeper.hosts ${ONOS_HOST_NAME}) |
| 43 | RC_COORD_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.coordinator.protocol "fast+udp") |
| 44 | RC_COORD_IP=$(read-conf ${ONOS_CONF} ramcloud.coordinator.ip ${ONOS_HOST_IP}) |
| 45 | RC_COORD_PORT=$(read-conf ${ONOS_CONF} ramcloud.coordinator.port 12246) |
| 46 | RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp") |
| 47 | RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP}) |
| 48 | RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242) |
| 49 | HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members) |
| 50 | HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3") |
| 51 | HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 52 | ############################################ |
| 53 | |
| 54 | |
| 55 | ############## Other variables ############# |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 56 | ONOS_TEMPLATE_DIR=${ONOS_CONF_DIR}/template |
| 57 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 58 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
| 59 | |
| 60 | ZK_DIR=${HOME}/zookeeper-3.4.5 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 61 | ZK_CONF_FILE=zoo.cfg |
| 62 | ZK_CONF=${ONOS_CONF_DIR}/${ZK_CONF_FILE} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 63 | ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template |
| 64 | ZK_LOG_DIR=${ONOS_HOME}/onos-logs |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 65 | ZK_LIB_DIR=/var/lib/zookeeper |
| 66 | ZK_MY_ID=${ZK_LIB_DIR}/myid |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 67 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 68 | HC_CONF=${ONOS_CONF_DIR}/hazelcast.xml |
| 69 | HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template |
| 70 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 71 | RAMCLOUD_DIR=${HOME}/ramcloud |
| 72 | RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 73 | RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log |
| 74 | RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 75 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
| 76 | |
| 77 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH} |
| 78 | |
| 79 | ## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 80 | ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_CONF_DIR}/logback.${ONOS_HOST_NAME}.xml} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 81 | ONOS_LOGBACK_BACKUP=${ONOS_LOGBACK}.bak |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 82 | ONOS_LOGBACK_TEMPLATE=${ONOS_TEMPLATE_DIR}/logback.xml.template |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 83 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 84 | LOGBASE=${ONOS_LOGBASE:-onos.${ONOS_HOST_NAME}} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 85 | ONOS_LOG="${LOGDIR}/${LOGBASE}.log" |
| 86 | PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap" |
| 87 | LOGS="$ONOS_LOG $PCAP_LOG" |
| 88 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 89 | ONOS_PROPS=${ONOS_PROPS:-${ONOS_CONF_DIR}/onos.properties} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 90 | JMX_PORT=${JMX_PORT:-7189} |
| 91 | |
| 92 | # Set JVM options |
| 93 | JVM_OPTS="${JVM_OPTS:-}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 94 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 95 | #JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 96 | |
| 97 | # Uncomment or specify appropriate value as JVM_OPTS environment variables. |
| 98 | #JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 99 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 100 | #JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 101 | |
| 102 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC" |
| 103 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC" |
| 104 | JVM_OPTS="$JVM_OPTS -XX:+AggressiveOpts" |
| 105 | |
| 106 | # We may want to remove UseFastAccessorMethods option: http://bugs.java.com/view_bug.do?bug_id=6385687 |
| 107 | JVM_OPTS="$JVM_OPTS -XX:+UseFastAccessorMethods" |
| 108 | |
| 109 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192" |
| 110 | JVM_OPTS="$JVM_OPTS -XX:FreqInlineSize=8192" |
| 111 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500" |
| 112 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 113 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 114 | |
| 115 | # Workaround for Thread Priority http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html |
| 116 | JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42" |
| 117 | |
| 118 | JVM_OPTS="$JVM_OPTS -XX:+UseCompressedOops" |
| 119 | |
| 120 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT" |
| 121 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false" |
| 122 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" |
| 123 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 124 | JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j" |
| 125 | |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 126 | # Uncomment to dump final JVM flags to stdout |
| 127 | #JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal" |
| 128 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 129 | # Set ONOS core main class |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 130 | MAIN_CLASS="net.onrc.onos.core.main.Main" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 131 | |
| 132 | MVN=${MVN:-mvn -o} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 133 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 134 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 135 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 136 | ############# Common functions ############# |
| 137 | function print_usage { |
| 138 | local filename=`basename ${ONOS_CONF}` |
| 139 | local usage="Usage: setup/start/stop ONOS on this server. |
| 140 | \$ $0 setup [-f] |
| 141 | Set up ONOS node using ${filename}. |
| 142 | - generate and replace config file of ZooKeeper. |
| 143 | - create myid in ZooKeeper datadir. |
| 144 | - generate and replace logback.${ONOS_HOST_NAME}.xml |
| 145 | If -f option is used, all existing files will be overwritten without confirmation. |
| 146 | \$ $0 start [single-node|coord-node|server-node|coord-and-server-node] |
| 147 | Start ONOS node with specific RAMCloud entities |
| 148 | - single-node: start ONOS with stand-alone RAMCloud |
| 149 | - coord-node : start ONOS with RAMCloud coordinator |
| 150 | - server-node: start ONOS with RAMCloud server |
| 151 | - coord-and-server-node: start ONOS with RAMCloud coordinator and server |
| 152 | * Default behavior can be defined by ${filename} |
| 153 | \$ $0 stop |
| 154 | Stop all ONOS-related processes |
| 155 | \$ $0 restart |
| 156 | Stop and start currently running ONOS-related processes |
| 157 | \$$0 status |
| 158 | Show status of ONOS-related processes |
| 159 | \$ $0 {zk|rc-coord|rc-server|core} {start|stop|restart|status} |
| 160 | Control specific ONOS-related process" |
| 161 | |
| 162 | echo "${usage}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | function rotate-log { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 166 | local logfile=$1 |
| 167 | local nr_max=${2:-10} |
| 168 | if [ -f $logfile ]; then |
| 169 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 170 | if [ -f ${logfile}.${i} ]; then |
| 171 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 172 | fi |
| 173 | done |
| 174 | mv $logfile $logfile.1 |
| 175 | fi |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | # kill-processes {module-name} {array of pids} |
| 179 | function kill-processes { |
| 180 | # Kill the existing processes |
| 181 | local pids=$2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 182 | if [ ! -z "$pids" ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 183 | echo -n "Stopping $1 ... " |
| 184 | fi |
| 185 | for p in ${pids}; do |
| 186 | if [ x$p != "x" ]; then |
| 187 | kill -KILL $p |
| 188 | echo "Killed existing process (pid: $p)" |
| 189 | fi |
| 190 | done |
| 191 | } |
| 192 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 193 | # revert-file {filename} |
| 194 | # revert "filename" from "filename.bak" if "filename.tmp" exists. |
| 195 | function revert-file { |
| 196 | local filename=$1 |
| 197 | local temp="${filename}.tmp" |
| 198 | local backup="${filename}.bak" |
| 199 | |
| 200 | if [ -f "${temp}" ]; then |
| 201 | echo -n "reverting ${filename} ... " |
| 202 | mv ${backup} ${filename} |
| 203 | rm ${temp} |
| 204 | echo "DONE" |
| 205 | fi |
| 206 | } |
| 207 | |
| 208 | # revert-confs [error message] |
| 209 | function revert-confs { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 210 | set -e |
| 211 | |
| 212 | echo -n "ERROR occurred ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 213 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 214 | revert-file `basename ${ZK_CONF}` |
| 215 | revert-file `basename ${HC_CONF}` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 216 | |
| 217 | echo "EXIT" |
| 218 | |
| 219 | if [ ! -z "$1" ]; then |
| 220 | echo $1 |
| 221 | fi |
| 222 | |
| 223 | set +e |
| 224 | |
| 225 | exit 1 |
| 226 | } |
| 227 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 228 | function create-zk-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 229 | echo -n "Creating ${ZK_CONF} ... " |
| 230 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 231 | # creation of zookeeper config |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 232 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 233 | local temp_zk="${ZK_CONF}.tmp" |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 234 | if [ -f ${temp_zk} ]; then |
| 235 | rm ${temp_zk} |
| 236 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 237 | touch ${temp_zk} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 238 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 239 | if [ -f ${ZK_CONF} ]; then |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 240 | mv ${ZK_CONF} ${ZK_CONF}.bak |
| 241 | local filename=`basename ${ZK_CONF}` |
| 242 | echo -n "backup old file to ${filename}.bak ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 243 | fi |
| 244 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 245 | hostarr=`echo ${ZK_HOSTS} | tr "," " "` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 246 | |
| 247 | local i=1 |
| 248 | local myid= |
| 249 | for host in ${hostarr}; do |
| 250 | if [ ${host} = ${ONOS_HOST_NAME} ]; then |
| 251 | myid=$i |
| 252 | break |
| 253 | fi |
| 254 | i=`expr $i + 1` |
| 255 | done |
| 256 | |
| 257 | if [ -z "${myid}" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 258 | local filename=`basename ${ONOS_CONF}` |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 259 | revert-confs "[ERROR in ${filename}] zookeeper.hosts must have hostname \"${ONOS_HOST_NAME}\"" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 260 | fi |
| 261 | |
| 262 | # TODO: Remove sudo. |
| 263 | # This is temporary code for the sake of compatibility with old code (which creates myid with root user). |
| 264 | sudo mv ${ZK_MY_ID} ${ZK_MY_ID}.old |
| 265 | echo ${myid} > ${ZK_MY_ID} |
| 266 | |
| 267 | echo -n "myid is assigned to ${myid} ... " |
| 268 | |
| 269 | while read line; do |
| 270 | if [[ $line =~ ^__HOSTS__$ ]]; then |
| 271 | i=1 |
| 272 | for host in ${hostarr}; do |
| 273 | # TODO: ports might be configurable |
| 274 | local hostline="server.${i}=${host}:2888:3888" |
| 275 | echo $hostline >> "${temp_zk}" |
| 276 | i=`expr $i + 1` |
| 277 | done |
| 278 | elif [[ $line =~ __DATADIR__ ]]; then |
| 279 | echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|" >> ${temp_zk} |
| 280 | else |
| 281 | echo $line >> ${temp_zk} |
| 282 | fi |
| 283 | done < ${ZK_CONF_TEMPLATE} |
| 284 | mv ${temp_zk} ${ZK_CONF} |
| 285 | |
| 286 | echo "DONE" |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 287 | } |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 288 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 289 | function create-hazelcast-conf { |
| 290 | echo -n "Creating ${HC_CONF} ... " |
| 291 | |
| 292 | local temp_hc="${HC_CONF}.tmp" |
| 293 | if [ -f ${temp_hc} ]; then |
| 294 | rm ${temp_hc} |
| 295 | fi |
| 296 | touch ${temp_hc} |
| 297 | |
| 298 | if [ -f ${HC_CONF} ]; then |
| 299 | mv ${HC_CONF} ${HC_CONF}.bak |
| 300 | local filename=`basename ${HC_CONF}` |
| 301 | echo -n "backup old file to ${filename}.bak ... " |
| 302 | fi |
| 303 | |
| 304 | # To keep indent of XML file, change IFS |
| 305 | local IFS='' |
| 306 | while read line; do |
| 307 | if [[ $line =~ __HC_NETWORK__ ]]; then |
| 308 | if [ ! -z "${HC_TCPIP_MEMBERS}" ]; then |
| 309 | # temporary change |
| 310 | IFS=' ' |
| 311 | local memberarr=`echo ${HC_TCPIP_MEMBERS} | tr "," " "` |
| 312 | echo '<multicast enabled="false" />' |
| 313 | echo '<tcp-ip enabled="true">' |
| 314 | for member in ${memberarr}; do |
| 315 | echo " <member>${member}</member>" |
| 316 | done |
| 317 | echo '</tcp-ip>' |
| 318 | IFS='' |
| 319 | else |
| 320 | echo '<multicast enabled="true">' |
| 321 | echo " <multicast-group>${HC_MULTICAST_GROUP}</multicast-group>" |
| 322 | echo " <multicast-port>${HC_MULTICAST_PORT}</multicast-port>" |
| 323 | echo '</multicast>' |
| 324 | echo '<tcp-ip enabled="false" />' |
| 325 | fi |
| 326 | else |
| 327 | echo "${line}" |
| 328 | fi |
| 329 | done < ${HC_CONF_TEMPLATE} > ${temp_hc} |
| 330 | |
| 331 | mv ${temp_hc} ${HC_CONF} |
| 332 | |
| 333 | echo "DONE" |
| 334 | } |
| 335 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 336 | function create-logback-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 337 | echo -n "Creating ${ONOS_LOGBACK} ... " |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 338 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 339 | # creation of logback config |
| 340 | if [ -f $ONOS_LOGBACK ]; then |
| 341 | local logback_file=`basename ${ONOS_LOGBACK}` |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 342 | mv ${ONOS_LOGBACK} ${ONOS_LOGBACK}.bak |
| 343 | local filename=`basename ${ONOS_LOGBACK}` |
| 344 | echo -n "backup old file to ${filename}.bak ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 345 | fi |
| 346 | sed -e "s|__FILENAME__|${ONOS_LOG}|" ${ONOS_LOGBACK_TEMPLATE} > ${ONOS_LOGBACK} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 347 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 348 | echo "DONE" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 351 | # create-conf-interactive {filename} {function to create conf} |
| 352 | function create-conf-interactive { |
| 353 | local filepath=$1 |
| 354 | local filename=`basename ${filepath}` |
| 355 | local func=$2 |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 356 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 357 | if [ -f ${filepath} ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 358 | # confirmation to overwrite existing config file |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 359 | echo -n "Overwriting ${filename} [Y/n]? " |
| 360 | while [ 1 ]; do |
| 361 | read key |
| 362 | if [ -z "${key}" -o "${key}" == "Y" ]; then |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 363 | ${func} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 364 | break |
| 365 | elif [ "${key}" == "n" ]; then |
| 366 | break |
| 367 | fi |
| 368 | echo "[Y/n]?" |
| 369 | done |
| 370 | else |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 371 | ${func} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 372 | fi |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | function create-confs { |
| 376 | local key |
| 377 | local filename |
| 378 | |
| 379 | trap revert-confs ERR |
| 380 | |
| 381 | if [ "$1" == "-f" ]; then |
| 382 | create-zk-conf |
| 383 | create-hazelcast-conf |
| 384 | create-logback-conf |
| 385 | else |
| 386 | create-conf-interactive ${ZK_CONF} create-zk-conf |
| 387 | create-conf-interactive ${HC_CONF} create-hazelcast-conf |
| 388 | create-conf-interactive ${ONOS_LOGBACK} create-logback-conf |
| 389 | fi |
| 390 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 391 | |
| 392 | trap - ERR |
| 393 | } |
| 394 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 395 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 396 | |
| 397 | ###### Functions related to ZooKeeper ###### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 398 | function 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 Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 414 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 415 | exit 1 |
| 416 | esac |
| 417 | } |
| 418 | |
| 419 | function start-zk { |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 420 | echo -n "Starting Zookeeper ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 421 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 422 | export ZOO_LOG_DIR=${ZK_LOG_DIR} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 423 | if [ -f "${ZK_CONF}" ]; then |
| 424 | # Run Zookeeper with our configuration |
| 425 | export ZOOCFG=${ZK_CONF_FILE} |
| 426 | export ZOOCFGDIR=${ONOS_CONF_DIR} |
| 427 | fi |
| 428 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 429 | $ZK_DIR/bin/zkServer.sh start |
| 430 | } |
| 431 | |
| 432 | function stop-zk { |
| 433 | kill-processes "ZooKeeper" `jps -l | grep org.apache.zookeeper.server | awk '{print $1}'` |
| 434 | } |
| 435 | |
| 436 | function status-zk { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 437 | if [ -f ${ZK_CONF} ]; then |
| 438 | export ZOOCFG=${ZK_CONF_FILE} |
| 439 | export ZOOCFGDIR=${ONOS_CONF_DIR} |
| 440 | fi |
| 441 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 442 | $ZK_DIR/bin/zkServer.sh status |
| 443 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 444 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 445 | |
| 446 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 447 | ####### Functions related to RAMCloud ###### |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 448 | function start-backend { |
| 449 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 450 | if [ $1 == "coord" ]; then |
| 451 | rc-coord startifdown |
| 452 | elif [ $1 == "server" ]; then |
| 453 | rc-server startifdown |
| 454 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 455 | fi |
| 456 | } |
| 457 | |
| 458 | function stop-backend { |
| 459 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 460 | if [ $rcsn != 0 ]; then |
| 461 | rc-server stop |
| 462 | fi |
| 463 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 464 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 465 | if [ $rccn != 0 ]; then |
| 466 | rc-coord stop |
| 467 | fi |
| 468 | } |
| 469 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 470 | function deldb { |
| 471 | # TODO: implement |
| 472 | return |
| 473 | } |
| 474 | |
| 475 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 476 | ### Functions related to RAMCloud coordinator |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 477 | function rc-coord-addr { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 478 | echo "${RC_COORD_PROTOCOL}:host=${RC_COORD_IP},port=${RC_COORD_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | function rc-server-addr { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 482 | echo "${RC_SERVER_PROTOCOL}:host=${RC_SERVER_IP},port=${RC_SERVER_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 485 | function rc-coord { |
| 486 | case "$1" in |
| 487 | start) |
| 488 | deldb |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 489 | stop-coord |
| 490 | start-coord |
| 491 | ;; |
| 492 | startifdown) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 493 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 494 | if [ $n == 0 ]; then |
| 495 | start-coord |
| 496 | else |
| 497 | echo "$n instance of RAMCloud coordinator running" |
| 498 | fi |
| 499 | ;; |
| 500 | stop) |
| 501 | stop-coord |
| 502 | ;; |
| 503 | stat*) # <- status |
| 504 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
| 505 | echo "$n RAMCloud coordinator running" |
| 506 | ;; |
| 507 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 508 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 509 | exit 1 |
| 510 | esac |
| 511 | } |
| 512 | |
| 513 | function start-coord { |
| 514 | if [ ! -d ${LOGDIR} ]; then |
| 515 | mkdir -p ${LOGDIR} |
| 516 | fi |
| 517 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 518 | rotate-log $RAMCLOUD_COORD_LOG |
| 519 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 520 | |
| 521 | local coord_addr=`rc-coord-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 522 | |
| 523 | # Run ramcloud |
| 524 | echo -n "Starting RAMCloud coordinator ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 525 | $RAMCLOUD_DIR/obj.${RAMCLOUD_BRANCH}/coordinator -L ${coord_addr} > $RAMCLOUD_COORD_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 526 | echo "STARTED" |
| 527 | } |
| 528 | |
| 529 | |
| 530 | function stop-coord { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 531 | kill-processes "RAMCloud coordinator" `pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 534 | ### Functions related to RAMCloud server |
| 535 | function rc-server { |
| 536 | case "$1" in |
| 537 | start) |
| 538 | deldb |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 539 | stop-server |
| 540 | start-server |
| 541 | ;; |
| 542 | startifdown) |
| 543 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 544 | if [ $n == 0 ]; then |
| 545 | start-server |
| 546 | else |
| 547 | echo "$n instance of RAMCloud server running" |
| 548 | fi |
| 549 | ;; |
| 550 | stop) |
| 551 | stop-server |
| 552 | ;; |
| 553 | # deldb) |
| 554 | # deldb |
| 555 | # ;; |
| 556 | stat*) # <- status |
| 557 | n=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 558 | echo "$n RAMCloud server running" |
| 559 | ;; |
| 560 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 561 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 562 | exit 1 |
| 563 | esac |
| 564 | } |
| 565 | |
| 566 | function start-server { |
| 567 | if [ ! -d ${LOGDIR} ]; then |
| 568 | mkdir -p ${LOGDIR} |
| 569 | fi |
| 570 | if [ -f $RAMCLOUD_SERVER_LOG ]; then |
| 571 | rotate-log $RAMCLOUD_SERVER_LOG |
| 572 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 573 | |
| 574 | local coord_addr=`rc-coord-addr` |
| 575 | local server_addr=`rc-server-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 576 | |
| 577 | # Run ramcloud |
| 578 | echo -n "Starting RAMCloud server ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 579 | ${RAMCLOUD_DIR}/obj.${RAMCLOUD_BRANCH}/server -M -L ${server_addr} -C ${coord_addr} --masterServiceThreads 1 --logCleanerThreads 1 --detectFailures 0 > $RAMCLOUD_SERVER_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 580 | echo "STARTED" |
| 581 | } |
| 582 | |
| 583 | function stop-server { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 584 | kill-processes "RAMCloud server" `pgrep -f obj.${RAMCLOUD_BRANCH}/server` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 585 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 586 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 587 | |
| 588 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 589 | ## Functions related to ONOS core process ## |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 590 | function onos { |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 591 | CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 592 | if [ ! -f ${CPFILE} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 593 | echo "ONOS core needs to be built" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 594 | ${MVN} -f ${ONOS_HOME}/pom.xml compile |
| 595 | fi |
| 596 | JAVA_CP=`cat ${CPFILE}` |
| 597 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
| 598 | |
| 599 | case "$1" in |
| 600 | start) |
| 601 | stop-onos |
| 602 | start-onos |
| 603 | ;; |
| 604 | startnokill) |
| 605 | start-onos |
| 606 | ;; |
| 607 | startifdown) |
| 608 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 609 | if [ $n == 0 ]; then |
| 610 | start-onos |
| 611 | else |
| 612 | echo "$n instance of onos running" |
| 613 | fi |
| 614 | ;; |
| 615 | stop) |
| 616 | stop-onos |
| 617 | ;; |
| 618 | stat*) # <- status |
| 619 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 620 | echo "$n instance of onos running" |
| 621 | ;; |
| 622 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 623 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 624 | exit 1 |
| 625 | esac |
| 626 | } |
| 627 | |
| 628 | function start-onos { |
| 629 | if [ ! -d ${LOGDIR} ]; then |
| 630 | mkdir -p ${LOGDIR} |
| 631 | fi |
| 632 | # Backup log files |
| 633 | for log in ${LOGS}; do |
| 634 | if [ -f ${log} ]; then |
| 635 | rotate-log ${log} |
| 636 | fi |
| 637 | done |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 638 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 639 | if [ ! -f ${ONOS_LOGBACK} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 640 | echo "[WARNING] ${ONOS_LOGBACK} not found." |
| 641 | echo " Run \"\$ $0 setup\" to create." |
| 642 | exit 1 |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 643 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 644 | |
Jonathan Hart | ef3dc1a | 2014-04-03 11:39:50 -0700 | [diff] [blame] | 645 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.backend=${ONOS_HOST_BACKEND}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 646 | |
| 647 | # Run ONOS |
| 648 | |
| 649 | echo -n "Starting ONOS controller ..." |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 650 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr & |
| 651 | |
| 652 | # We need to wait a bit to find out whether starting the ONOS process succeeded |
| 653 | sleep 1 |
| 654 | |
| 655 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 656 | if [ $n -ge 1 ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 657 | echo " STARTED" |
| 658 | else |
| 659 | echo " FAILED" |
| 660 | fi |
| 661 | |
| 662 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 663 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 664 | } |
| 665 | |
| 666 | function stop-onos { |
| 667 | kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'` |
| 668 | # kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 669 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 670 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 671 | |
| 672 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 673 | ################## Main #################### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 674 | case "$1" in |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 675 | setup) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 676 | create-confs $2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 677 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 678 | start) |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 679 | mode_parameter=${ONOS_HOST_ROLE} |
| 680 | if [ ! -z "$2" ]; then |
| 681 | mode_parameter=$2 |
| 682 | fi |
| 683 | |
| 684 | case "${mode_parameter}" in |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 685 | single-node) |
| 686 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 687 | start-backend coord |
| 688 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 689 | onos startifdown |
| 690 | ;; |
| 691 | coord-node) |
| 692 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 693 | start-backend coord |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 694 | onos startifdown |
| 695 | ;; |
| 696 | server-node) |
| 697 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 698 | start-backend server |
| 699 | onos startifdown |
| 700 | ;; |
| 701 | coord-and-server-node) |
| 702 | zk start |
| 703 | start-backend coord |
| 704 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 705 | onos startifdown |
| 706 | ;; |
| 707 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 708 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 709 | ;; |
| 710 | esac |
| 711 | echo |
| 712 | ;; |
| 713 | stop) |
| 714 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 715 | if [ $on != 0 ]; then |
| 716 | onos stop |
| 717 | fi |
| 718 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 719 | stop-backend |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 720 | |
| 721 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 722 | if [ $zkn != 0 ]; then |
| 723 | zk stop |
| 724 | fi |
| 725 | echo |
| 726 | ;; |
| 727 | restart) |
| 728 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 729 | if [ $on != 0 ]; then |
| 730 | onos stop |
| 731 | fi |
| 732 | |
| 733 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 734 | if [ $rcsn != 0 ]; then |
| 735 | rc-server stop |
| 736 | fi |
| 737 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 738 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 739 | if [ $rccn != 0 ]; then |
| 740 | rc-coord stop |
| 741 | fi |
| 742 | |
| 743 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 744 | if [ $zkn != 0 ]; then |
| 745 | zk restart |
| 746 | fi |
| 747 | |
| 748 | if [ $rccn != 0 ]; then |
| 749 | rc-coord startifdown |
| 750 | fi |
| 751 | |
| 752 | if [ $rcsn != 0 ]; then |
| 753 | rc-server startifdown |
| 754 | fi |
| 755 | |
| 756 | if [ $on != 0 ]; then |
| 757 | onos startifdown |
| 758 | fi |
| 759 | echo |
| 760 | ;; |
| 761 | stat*) # <- status |
| 762 | echo '[ZooKeeper]' |
| 763 | zk status |
| 764 | echo |
| 765 | echo '[RAMCloud coordinator]' |
| 766 | rc-coord status |
| 767 | echo |
| 768 | echo '[RAMCloud server]' |
| 769 | rc-server status |
| 770 | echo |
| 771 | echo '[ONOS core]' |
| 772 | onos status |
| 773 | echo |
| 774 | ;; |
| 775 | zk) |
| 776 | zk $2 |
| 777 | ;; |
| 778 | rc-c*) # <- rc-coordinator |
| 779 | rc-coord $2 |
| 780 | ;; |
| 781 | rc-s*) # <- rc-server |
| 782 | rc-server $2 |
| 783 | ;; |
| 784 | core) |
| 785 | onos $2 |
| 786 | ;; |
| 787 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 788 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 789 | exit 1 |
| 790 | esac |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 791 | |