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