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