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