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) |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 9 | # $ONOS_LOGDIR : path of log output directory (~/ONOS/onos-logs) |
| 10 | # $ONOS_LOGBASE : base name of log output file (onos.`hostname`) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 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 | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 15 | # $ZK_LOG_DIR : path of ZooKeeper log output directory (~/ONOS/onos-logs/zk-`hostname`) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 16 | # $JVM_OPTS : JVM options ONOS starts with |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 17 | # $ZK_CONF : path of ZooKeeper config file (~/ONOS/conf/zoo.cfg) |
| 18 | # $HC_CONF : path of Hazelcast config file (~/ONOS/conf/hazelcast.xml) |
| 19 | # $RAMCLOUD_CONF : path of RAMCloud config file (~/ONOS/conf/ramcloud.conf) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 20 | ##################################################### |
| 21 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 22 | ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 23 | ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf} |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 24 | ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.`hostname`.conf} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 25 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 26 | source ${ONOS_HOME}/scripts/common/utils.sh |
| 27 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 28 | if [ ! -f ${ONOS_CONF} ]; then |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 29 | # falling back to default config file |
| 30 | ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf |
| 31 | if [ ! -f ${ONOS_CONF} ]; then |
| 32 | echo "${ONOS_CONF} not found." |
| 33 | exit 1 |
| 34 | fi |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 35 | fi |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 36 | |
| 37 | |
| 38 | ### Variables read from ONOS config file ### |
| 39 | ONOS_HOST_NAME=$(read-conf ${ONOS_CONF} host.name `hostname`) |
| 40 | ONOS_HOST_IP=$(read-conf ${ONOS_CONF} host.ip) |
| 41 | ONOS_HOST_ROLE=$(read-conf ${ONOS_CONF} host.role) |
| 42 | ONOS_HOST_BACKEND=$(read-conf ${ONOS_CONF} host.backend) |
| 43 | ZK_HOSTS=$(read-conf ${ONOS_CONF} zookeeper.hosts ${ONOS_HOST_NAME}) |
| 44 | RC_COORD_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.coordinator.protocol "fast+udp") |
| 45 | RC_COORD_IP=$(read-conf ${ONOS_CONF} ramcloud.coordinator.ip ${ONOS_HOST_IP}) |
| 46 | RC_COORD_PORT=$(read-conf ${ONOS_CONF} ramcloud.coordinator.port 12246) |
| 47 | RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp") |
| 48 | RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP}) |
| 49 | RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242) |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 50 | HC_HOST_PORT=$(read-conf ${ONOS_CONF} hazelcast.host.port 5701) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 51 | HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members) |
| 52 | HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3") |
| 53 | HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 54 | ############################################ |
| 55 | |
| 56 | |
| 57 | ############## Other variables ############# |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 58 | ONOS_TEMPLATE_DIR=${ONOS_CONF_DIR}/template |
| 59 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 60 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
| 61 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 62 | ZK_HOME=${ZK_HOME:-~/zookeeper-3.4.5} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 63 | ZK_CONF=${ZK_CONF:-${ONOS_CONF_DIR}/zoo.cfg} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 64 | ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 65 | # Adding ONOS_HOST_NAME dir since file name (zookeeper.out) cannot be controlled. |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 66 | ZK_LOG_DIR=${ZK_LOG_DIR:-${ONOS_HOME}/onos-logs/zk-${ONOS_HOST_NAME}} |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 67 | ZK_LIB_DIR=${ZK_LIB_DIR:-/var/lib/zookeeper} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 68 | ZK_MY_ID=${ZK_LIB_DIR}/myid |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 69 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 70 | HC_CONF=${HC_CONF:-${ONOS_CONF_DIR}/hazelcast.xml} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 71 | HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template |
| 72 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 73 | RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 74 | RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log |
| 75 | RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 76 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 77 | RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_CONF_DIR}/ramcloud.conf} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 78 | |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 79 | 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] | 80 | |
| 81 | ## 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] | 82 | ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_CONF_DIR}/logback.${ONOS_HOST_NAME}.xml} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 83 | ONOS_LOGBACK_BACKUP=${ONOS_LOGBACK}.bak |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 84 | ONOS_LOGBACK_TEMPLATE=${ONOS_TEMPLATE_DIR}/logback.xml.template |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 85 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 86 | LOGBASE=${ONOS_LOGBASE:-onos.${ONOS_HOST_NAME}} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 87 | ONOS_LOG="${LOGDIR}/${LOGBASE}.log" |
| 88 | PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap" |
| 89 | LOGS="$ONOS_LOG $PCAP_LOG" |
| 90 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 91 | ONOS_PROPS=${ONOS_PROPS:-${ONOS_CONF_DIR}/onos.properties} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 92 | JMX_PORT=${JMX_PORT:-7189} |
| 93 | |
| 94 | # Set JVM options |
| 95 | JVM_OPTS="${JVM_OPTS:-}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 96 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 97 | #JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 98 | |
| 99 | # Uncomment or specify appropriate value as JVM_OPTS environment variables. |
| 100 | #JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 101 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 102 | #JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 103 | |
| 104 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC" |
| 105 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC" |
| 106 | JVM_OPTS="$JVM_OPTS -XX:+AggressiveOpts" |
| 107 | |
| 108 | # We may want to remove UseFastAccessorMethods option: http://bugs.java.com/view_bug.do?bug_id=6385687 |
| 109 | JVM_OPTS="$JVM_OPTS -XX:+UseFastAccessorMethods" |
| 110 | |
| 111 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192" |
| 112 | JVM_OPTS="$JVM_OPTS -XX:FreqInlineSize=8192" |
| 113 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500" |
| 114 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 115 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 116 | |
| 117 | # Workaround for Thread Priority http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html |
| 118 | JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42" |
| 119 | |
| 120 | JVM_OPTS="$JVM_OPTS -XX:+UseCompressedOops" |
| 121 | |
| 122 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT" |
| 123 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false" |
| 124 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" |
| 125 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 126 | JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j" |
| 127 | |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 128 | # Uncomment to dump final JVM flags to stdout |
| 129 | #JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal" |
| 130 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 131 | # Set ONOS core main class |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 132 | MAIN_CLASS="net.onrc.onos.core.main.Main" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 133 | |
| 134 | MVN=${MVN:-mvn -o} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 135 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 136 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 137 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 138 | ############# Common functions ############# |
| 139 | function print_usage { |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 140 | local scriptname=`basename $0` |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 141 | local filename=`basename ${ONOS_CONF}` |
| 142 | local usage="Usage: setup/start/stop ONOS on this server. |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 143 | \$ ${scriptname} setup [-f] |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 144 | Set up ONOS node using ${ONOS_CONF} . |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 145 | - generate and replace config file of ZooKeeper. |
| 146 | - create myid in ZooKeeper datadir. |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 147 | - generate and replace config file for Hazelcast. |
| 148 | - generate and replace config file for RAMCloud. |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 149 | - generate and replace logback.${ONOS_HOST_NAME}.xml |
| 150 | If -f option is used, all existing files will be overwritten without confirmation. |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 151 | \$ ${scriptname} start [single-node|coord-node|server-node|coord-and-server-node] |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 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} |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 158 | \$ ${scriptname} stop |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 159 | Stop all ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 160 | \$ ${scriptname} restart |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 161 | Stop and start currently running ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 162 | \$ ${scriptname} status |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 163 | Show status of ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 164 | \$ ${scriptname} {zk|rc-coord|rc-server|core} {start|stop|restart|status} |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 165 | Control specific ONOS-related process |
| 166 | \$ ${scriptname} rc deldb |
| 167 | Delete data in RAMCloud" |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 168 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 169 | echo "${usage}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | function rotate-log { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 173 | local logfile=$1 |
| 174 | local nr_max=${2:-10} |
| 175 | if [ -f $logfile ]; then |
| 176 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 177 | if [ -f ${logfile}.${i} ]; then |
| 178 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 179 | fi |
| 180 | done |
| 181 | mv $logfile $logfile.1 |
| 182 | fi |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | # kill-processes {module-name} {array of pids} |
| 186 | function kill-processes { |
| 187 | # Kill the existing processes |
| 188 | local pids=$2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 189 | if [ ! -z "$pids" ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 190 | echo -n "Stopping $1 ... " |
| 191 | fi |
| 192 | for p in ${pids}; do |
| 193 | if [ x$p != "x" ]; then |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 194 | ( |
| 195 | # Ask process with SIGTERM first, if that did not kill the process |
| 196 | # wait 1s and if process still exist, force process to be killed. |
| 197 | kill -TERM $p && kill -0 $p && sleep 1 && kill -0 $p && kill -KILL $p |
| 198 | ) 2> /dev/null |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 199 | echo "Killed existing process (pid: $p)" |
| 200 | fi |
| 201 | done |
| 202 | } |
| 203 | |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 204 | function handle-error { |
| 205 | set -e |
| 206 | |
| 207 | revert-confs |
| 208 | |
| 209 | set +e |
| 210 | |
| 211 | exit 1 |
| 212 | } |
| 213 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 214 | # revert-confs [error message] |
| 215 | function revert-confs { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 216 | echo -n "ERROR occurred ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 217 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 218 | revert-file `basename ${ZK_CONF}` |
| 219 | revert-file `basename ${HC_CONF}` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 220 | |
| 221 | echo "EXIT" |
| 222 | |
| 223 | if [ ! -z "$1" ]; then |
| 224 | echo $1 |
| 225 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 228 | function create-zk-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 229 | echo -n "Creating ${ZK_CONF} ... " |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 230 | |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 231 | # Create the ZooKeeper lib directory |
| 232 | if [ ! -d ${ZK_LIB_DIR} ]; then |
| 233 | local SUDO=${SUDO:-} |
| 234 | local whoami=`whoami` |
| 235 | { |
| 236 | ${SUDO} mkdir ${ZK_LIB_DIR} |
| 237 | ${SUDO} chown ${whoami} ${ZK_LIB_DIR} |
| 238 | } || { |
| 239 | echo "FAILED" |
| 240 | echo "[ERROR] Failed to create directory ${ZK_LIB_DIR}." |
| 241 | echo "[ERROR] Please retry after setting \"env SUDO=sudo\"" |
| 242 | exit 1 |
| 243 | } |
| 244 | fi |
| 245 | |
| 246 | # creation of ZooKeeper config |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 247 | local temp_zk=`begin-conf-creation ${ZK_CONF}` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 248 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 249 | hostarr=`echo ${ZK_HOSTS} | tr "," " "` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 250 | |
| 251 | local i=1 |
| 252 | local myid= |
| 253 | for host in ${hostarr}; do |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 254 | if [ "${host}" = "${ONOS_HOST_NAME}" -o "${host}" = "${ONOS_HOST_IP}" ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 255 | myid=$i |
| 256 | break |
| 257 | fi |
| 258 | i=`expr $i + 1` |
| 259 | done |
| 260 | |
| 261 | if [ -z "${myid}" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 262 | local filename=`basename ${ONOS_CONF}` |
Naoki Shiota | 35f8d5c | 2014-04-08 11:13:18 -0700 | [diff] [blame] | 263 | 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] | 264 | fi |
| 265 | |
Yuta HIGUCHI | 6945089 | 2014-04-16 09:10:55 -0700 | [diff] [blame] | 266 | if [ -f "${ZK_MY_ID}" ]; then |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 267 | # 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] | 268 | local SUDO=${SUDO:-} |
| 269 | { |
| 270 | ${SUDO} mv -f ${ZK_MY_ID} ${ZK_MY_ID}.old |
| 271 | } || { |
| 272 | echo "FAILED" |
| 273 | echo "[ERROR] Failed to rename ${ZK_MY_ID}." |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 274 | echo "[ERROR] Please retry after setting \"env SUDO=sudo\"" |
Yuta HIGUCHI | 6945089 | 2014-04-16 09:10:55 -0700 | [diff] [blame] | 275 | exit 1 |
| 276 | } |
| 277 | fi |
| 278 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 279 | echo ${myid} > ${ZK_MY_ID} |
| 280 | |
| 281 | echo -n "myid is assigned to ${myid} ... " |
| 282 | |
| 283 | while read line; do |
| 284 | if [[ $line =~ ^__HOSTS__$ ]]; then |
| 285 | i=1 |
| 286 | for host in ${hostarr}; do |
| 287 | # TODO: ports might be configurable |
| 288 | local hostline="server.${i}=${host}:2888:3888" |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 289 | echo $hostline |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 290 | i=`expr $i + 1` |
| 291 | done |
| 292 | elif [[ $line =~ __DATADIR__ ]]; then |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 293 | echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 294 | else |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 295 | echo $line |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 296 | fi |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 297 | done < ${ZK_CONF_TEMPLATE} > ${temp_zk} |
| 298 | |
| 299 | end-conf-creation ${ZK_CONF} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 300 | |
| 301 | echo "DONE" |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 302 | } |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 303 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 304 | function create-hazelcast-conf { |
| 305 | echo -n "Creating ${HC_CONF} ... " |
| 306 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 307 | local temp_hc=`begin-conf-creation ${HC_CONF}` |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 308 | |
| 309 | # To keep indent of XML file, change IFS |
| 310 | local IFS='' |
| 311 | while read line; do |
| 312 | if [[ $line =~ __HC_NETWORK__ ]]; then |
| 313 | if [ ! -z "${HC_TCPIP_MEMBERS}" ]; then |
| 314 | # temporary change |
| 315 | IFS=' ' |
| 316 | local memberarr=`echo ${HC_TCPIP_MEMBERS} | tr "," " "` |
| 317 | echo '<multicast enabled="false" />' |
| 318 | echo '<tcp-ip enabled="true">' |
| 319 | for member in ${memberarr}; do |
| 320 | echo " <member>${member}</member>" |
| 321 | done |
| 322 | echo '</tcp-ip>' |
| 323 | IFS='' |
| 324 | else |
| 325 | echo '<multicast enabled="true">' |
| 326 | echo " <multicast-group>${HC_MULTICAST_GROUP}</multicast-group>" |
| 327 | echo " <multicast-port>${HC_MULTICAST_PORT}</multicast-port>" |
| 328 | echo '</multicast>' |
| 329 | echo '<tcp-ip enabled="false" />' |
| 330 | fi |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 331 | elif [[ $line =~ __HC_PORT__ ]]; then |
| 332 | echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|" |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 333 | else |
| 334 | echo "${line}" |
| 335 | fi |
| 336 | done < ${HC_CONF_TEMPLATE} > ${temp_hc} |
| 337 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 338 | end-conf-creation ${HC_CONF} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 339 | |
| 340 | echo "DONE" |
| 341 | } |
| 342 | |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 343 | function create-ramcloud-conf { |
| 344 | echo -n "Creating ${RAMCLOUD_CONF} ... " |
| 345 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 346 | local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}` |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 347 | |
| 348 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC") |
| 349 | |
| 350 | # TODO make ZooKeeper address configurable. |
| 351 | echo "ramcloud.locator=zk:localhost:2181" > ${temp_rc} |
| 352 | echo "ramcloud.clusterName=${rc_cluster_name}" >> ${temp_rc} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 353 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 354 | end-conf-creation ${RAMCLOUD_CONF} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 355 | |
| 356 | echo "DONE" |
| 357 | } |
| 358 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 359 | function create-logback-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 360 | echo -n "Creating ${ONOS_LOGBACK} ... " |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 361 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 362 | # creation of logback config |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 363 | local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}` |
| 364 | |
| 365 | sed -e "s|__FILENAME__|${ONOS_LOG}|" ${ONOS_LOGBACK_TEMPLATE} > ${temp_lb} |
| 366 | |
| 367 | end-conf-creation ${ONOS_LOGBACK} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 368 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 369 | echo "DONE" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 372 | function create-confs { |
| 373 | local key |
| 374 | local filename |
| 375 | |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 376 | trap handle-error ERR |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 377 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 378 | echo "Config file : ${ONOS_CONF}" |
| 379 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 380 | if [ "$1" == "-f" ]; then |
| 381 | create-zk-conf |
| 382 | create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 383 | create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 384 | create-logback-conf |
| 385 | else |
| 386 | create-conf-interactive ${ZK_CONF} create-zk-conf |
| 387 | create-conf-interactive ${HC_CONF} create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 388 | create-conf-interactive ${RAMCLOUD_CONF} create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 389 | create-conf-interactive ${ONOS_LOGBACK} create-logback-conf |
| 390 | fi |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 391 | |
| 392 | trap - ERR |
| 393 | } |
| 394 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 395 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 396 | |
| 397 | ###### Functions related to ZooKeeper ###### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 398 | function zk { |
| 399 | case "$1" in |
| 400 | start) |
| 401 | start-zk |
| 402 | ;; |
| 403 | stop) |
| 404 | stop-zk |
| 405 | ;; |
| 406 | stat*) # <- status |
| 407 | status-zk |
| 408 | ;; |
| 409 | re*) # <- restart |
| 410 | stop-zk |
| 411 | start-zk |
| 412 | ;; |
| 413 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 414 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 415 | exit 1 |
| 416 | esac |
| 417 | } |
| 418 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 419 | function load-zk-cfg { |
| 420 | if [ -f "${ZK_CONF}" ]; then |
| 421 | local filename=`basename ${ZK_CONF}` |
| 422 | local dirname=`dirname ${ZK_CONF}` |
| 423 | |
| 424 | # Run ZooKeeper with our configuration |
| 425 | export ZOOCFG=${filename} |
| 426 | export ZOOCFGDIR=${dirname} |
| 427 | fi |
| 428 | } |
| 429 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 430 | function start-zk { |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 431 | echo -n "Starting ZooKeeper ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 432 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 433 | export ZOO_LOG_DIR=${ZK_LOG_DIR} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 434 | mkdir -p ${ZK_LOG_DIR} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 435 | |
| 436 | load-zk-cfg |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 437 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 438 | ${ZK_HOME}/bin/zkServer.sh start |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | function stop-zk { |
| 442 | kill-processes "ZooKeeper" `jps -l | grep org.apache.zookeeper.server | awk '{print $1}'` |
| 443 | } |
| 444 | |
| 445 | function status-zk { |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 446 | load-zk-cfg |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 447 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 448 | ${ZK_HOME}/bin/zkServer.sh status |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 449 | } |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 450 | |
| 451 | function check-zk { |
| 452 | # assumption here is that ZK status script is the last command in status-zk. |
| 453 | status-zk &> /dev/null |
| 454 | local zk_status=$? |
| 455 | if [ "$zk_status" -ne 0 ]; then |
| 456 | return 1; |
| 457 | fi |
| 458 | return 0 |
| 459 | } |
| 460 | |
| 461 | # wait-zk-or-die {timeout-sec} |
| 462 | function wait-zk-or-die { |
| 463 | local retries=${1:-1} |
| 464 | # do-while retries >= 0 |
| 465 | while true; do |
| 466 | check-zk |
| 467 | local zk_status=$? |
| 468 | if [ "$zk_status" -eq 0 ]; then |
| 469 | return 0 |
| 470 | fi |
| 471 | sleep 1; |
| 472 | ((retries -= 1)) |
| 473 | (( retries >= 0 )) || break |
| 474 | done |
| 475 | echo "ZooKeeper is not running." |
| 476 | exit 1 |
| 477 | } |
| 478 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 479 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 480 | |
| 481 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 482 | ####### Functions related to RAMCloud ###### |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 483 | function start-backend { |
| 484 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 485 | if [ $1 == "coord" ]; then |
| 486 | rc-coord startifdown |
| 487 | elif [ $1 == "server" ]; then |
| 488 | rc-server startifdown |
| 489 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 490 | fi |
| 491 | } |
| 492 | |
| 493 | function stop-backend { |
| 494 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 495 | if [ $rcsn != 0 ]; then |
| 496 | rc-server stop |
| 497 | fi |
| 498 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 499 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 500 | if [ $rccn != 0 ]; then |
| 501 | rc-coord stop |
| 502 | fi |
| 503 | } |
| 504 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 505 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 506 | ### Functions related to RAMCloud coordinator |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 507 | function rc-coord-addr { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 508 | local host=${RC_COORD_IP} |
| 509 | if [ -z "${host}" ]; then |
| 510 | # falling back to 0.0.0.0 |
| 511 | host="0.0.0.0" |
| 512 | fi |
| 513 | echo "${RC_COORD_PROTOCOL}:host=${host},port=${RC_COORD_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | function rc-server-addr { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 517 | local host=${RC_SERVER_IP} |
| 518 | if [ -z "${host}" ]; then |
| 519 | # falling back to 0.0.0.0 |
| 520 | host="0.0.0.0" |
| 521 | fi |
| 522 | echo "${RC_SERVER_PROTOCOL}:host=${host},port=${RC_SERVER_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 525 | function rc-coord { |
| 526 | case "$1" in |
| 527 | start) |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 528 | stop-coord |
| 529 | start-coord |
| 530 | ;; |
| 531 | startifdown) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 532 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 533 | if [ $n == 0 ]; then |
| 534 | start-coord |
| 535 | else |
| 536 | echo "$n instance of RAMCloud coordinator running" |
| 537 | fi |
| 538 | ;; |
| 539 | stop) |
| 540 | stop-coord |
| 541 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 542 | deldb) |
| 543 | stop-backend |
| 544 | del-coord-info |
| 545 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 546 | stat*) # <- status |
| 547 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
| 548 | echo "$n RAMCloud coordinator running" |
| 549 | ;; |
| 550 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 551 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 552 | exit 1 |
| 553 | esac |
| 554 | } |
| 555 | |
| 556 | function start-coord { |
Yuta HIGUCHI | 7170332 | 2014-05-06 09:17:29 -0700 | [diff] [blame] | 557 | wait-zk-or-die 2 |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 558 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 559 | if [ ! -d ${LOGDIR} ]; then |
| 560 | mkdir -p ${LOGDIR} |
| 561 | fi |
| 562 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 563 | rotate-log $RAMCLOUD_COORD_LOG |
| 564 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 565 | |
| 566 | local coord_addr=`rc-coord-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 567 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 568 | # TODO Configuration for ZK address, port |
| 569 | local zk_addr="localhost:2181" |
| 570 | # RAMCloud cluster name |
| 571 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC") |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 572 | # RAMCloud transport timeout |
| 573 | local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 574 | # RAMCloud option deadServerTimeout |
| 575 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 576 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 577 | |
| 578 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 579 | # but actual RAMCloud code only uses -C argument now. |
| 580 | # (FYI: -C is documented to be deprecated in the document) |
| 581 | |
| 582 | local coord_args="-C ${coord_addr}" |
| 583 | coord_args="${coord_args} --externalStorage zk:${zk_addr}" |
| 584 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 585 | coord_args="${coord_args} --timeout ${rc_timeout}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 586 | coord_args="${coord_args} --deadServerTimeout ${rc_coord_deadServerTimeout}" |
| 587 | |
| 588 | # Read environment variables if set |
| 589 | coord_args="${coord_args} ${RC_COORDINATOR_OPTS}" |
| 590 | |
| 591 | if [ "${ONOS_HOST_ROLE}" == "single-node" ]; then |
| 592 | # Note: Following reset is required, since RC restart is considered node failure, |
| 593 | # and tries recovery of server, which will never succeed after restart. |
| 594 | echo "Role configured to single-node mode. RAMCloud cluster will be reset on each start-up." |
| 595 | coord_args="${coord_args} --reset" |
| 596 | fi |
| 597 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 598 | # Run ramcloud |
| 599 | echo -n "Starting RAMCloud coordinator ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 600 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} > $RAMCLOUD_COORD_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 601 | echo "STARTED" |
| 602 | } |
| 603 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 604 | function del-coord-info { |
| 605 | wait-zk-or-die 1 |
| 606 | |
| 607 | if [ ! -d ${LOGDIR} ]; then |
| 608 | mkdir -p ${LOGDIR} |
| 609 | fi |
| 610 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 611 | rotate-log $RAMCLOUD_COORD_LOG |
| 612 | fi |
| 613 | |
| 614 | local coord_addr=`rc-coord-addr` |
| 615 | |
| 616 | # TODO Configuration for ZK address, port |
| 617 | local zk_addr="localhost:2181" |
| 618 | # RAMCloud cluster name |
| 619 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC") |
| 620 | # RAMCloud option deadServerTimeout |
| 621 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 622 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 623 | |
| 624 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 625 | # but actual RAMCloud code only uses -C argument now. |
| 626 | # (FYI: -C is documented to be deprecated in the document) |
| 627 | |
| 628 | local coord_args="-C ${coord_addr}" |
| 629 | coord_args="${coord_args} --externalStorage zk:${zk_addr}" |
| 630 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
| 631 | |
| 632 | # Note: --reset will reset ZK stored info and start running as acoordinator. |
| 633 | echo -n "Deleting RAMCloud cluster coordination info ... " |
| 634 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} --reset &> $RAMCLOUD_COORD_LOG & |
| 635 | |
| 636 | # TODO Assuming 1sec is enough. To be sure monitor log? |
| 637 | sleep 1 |
| 638 | # Silently kill coordinator |
Yuta HIGUCHI | ce9f3ee | 2014-05-14 09:48:40 -0700 | [diff] [blame] | 639 | (pkill -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator &> /dev/null) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 640 | |
| 641 | echo "DONE" |
| 642 | } |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 643 | |
| 644 | function stop-coord { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 645 | kill-processes "RAMCloud coordinator" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 648 | ### Functions related to RAMCloud server |
| 649 | function rc-server { |
| 650 | case "$1" in |
| 651 | start) |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 652 | stop-server |
| 653 | start-server |
| 654 | ;; |
| 655 | startifdown) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 656 | local n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 657 | if [ $n == 0 ]; then |
| 658 | start-server |
| 659 | else |
| 660 | echo "$n instance of RAMCloud server running" |
| 661 | fi |
| 662 | ;; |
| 663 | stop) |
| 664 | stop-server |
| 665 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 666 | deldb) |
| 667 | stop-server |
| 668 | del-server-backup |
| 669 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 670 | stat*) # <- status |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 671 | n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 672 | echo "$n RAMCloud server running" |
| 673 | ;; |
| 674 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 675 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 676 | exit 1 |
| 677 | esac |
| 678 | } |
| 679 | |
| 680 | function start-server { |
Yuta HIGUCHI | 7170332 | 2014-05-06 09:17:29 -0700 | [diff] [blame] | 681 | wait-zk-or-die 2 |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 682 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 683 | if [ ! -d ${LOGDIR} ]; then |
| 684 | mkdir -p ${LOGDIR} |
| 685 | fi |
| 686 | if [ -f $RAMCLOUD_SERVER_LOG ]; then |
| 687 | rotate-log $RAMCLOUD_SERVER_LOG |
| 688 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 689 | |
| 690 | local coord_addr=`rc-coord-addr` |
| 691 | local server_addr=`rc-server-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 692 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 693 | local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.server.masterServiceThreads 5) |
| 694 | local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.server.logCleanerThreads 1) |
Yuta HIGUCHI | 52efcbb | 2014-05-16 09:30:33 -0700 | [diff] [blame] | 695 | local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.server.detectFailures 0) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 696 | |
| 697 | # TODO Configuration for ZK address, port |
| 698 | local zk_addr="localhost:2181" |
| 699 | # RAMCloud cluster name |
| 700 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC") |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 701 | # RAMCloud transport timeout |
| 702 | local rc_timeout=$(read-conf ${ONOS_CONF} ramcloud.timeout 1000) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 703 | # replication factor (-r) config |
| 704 | local rc_replicas=$(read-conf ${ONOS_CONF} ramcloud.server.replicas 0) |
| 705 | # backup file path (-f) config |
| 706 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 707 | mkdir -p `dirname ${rc_datafile}` |
| 708 | |
| 709 | local server_args="-L ${server_addr}" |
| 710 | server_args="${server_args} --externalStorage zk:${zk_addr}" |
| 711 | server_args="${server_args} --clusterName ${rc_cluster_name}" |
Yuta HIGUCHI | ea7eba0 | 2014-05-14 11:13:52 -0700 | [diff] [blame] | 712 | server_args="${server_args} --timeout ${rc_timeout}" |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 713 | server_args="${server_args} --masterServiceThreads ${masterServiceThreads}" |
| 714 | server_args="${server_args} --logCleanerThreads ${logCleanerThreads}" |
| 715 | server_args="${server_args} --detectFailures ${detectFailures}" |
| 716 | server_args="${server_args} --replicas ${rc_replicas}" |
| 717 | server_args="${server_args} --file ${rc_datafile}" |
| 718 | |
| 719 | # Read environment variables if set |
| 720 | server_args="${server_args} ${RC_SERVER_OPTS}" |
Yuta HIGUCHI | 45bc3cf | 2014-04-19 18:12:15 -0700 | [diff] [blame] | 721 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 722 | # Run ramcloud |
| 723 | echo -n "Starting RAMCloud server ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 724 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server ${server_args} > $RAMCLOUD_SERVER_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 725 | echo "STARTED" |
| 726 | } |
| 727 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 728 | function del-server-backup { |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 729 | echo -n "Delete RAMCloud backup server data [y/N]? " |
| 730 | while [ 1 ]; do |
| 731 | read key |
| 732 | if [ "${key}" == "Y" -o "${key}" == "y" ]; then |
| 733 | break |
| 734 | elif [ -z "${key}" -o "${key}" == "N" -o "${key}" == "n" ]; then |
| 735 | echo "Cancelled." |
| 736 | return |
| 737 | fi |
| 738 | echo "[y/N]? " |
| 739 | done |
| 740 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 741 | echo -n "Removing RAMCloud backup server data ... " |
| 742 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 743 | rm -f ${rc_datafile} |
| 744 | echo "DONE" |
| 745 | } |
| 746 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 747 | function stop-server { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 748 | kill-processes "RAMCloud server" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 749 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 750 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 751 | |
| 752 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 753 | ## Functions related to ONOS core process ## |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 754 | function onos { |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 755 | CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 756 | if [ ! -f ${CPFILE} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 757 | echo "ONOS core needs to be built" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 758 | ${MVN} -f ${ONOS_HOME}/pom.xml compile |
| 759 | fi |
| 760 | JAVA_CP=`cat ${CPFILE}` |
| 761 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
| 762 | |
| 763 | case "$1" in |
| 764 | start) |
| 765 | stop-onos |
| 766 | start-onos |
| 767 | ;; |
| 768 | startnokill) |
| 769 | start-onos |
| 770 | ;; |
| 771 | startifdown) |
| 772 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 773 | if [ $n == 0 ]; then |
| 774 | start-onos |
| 775 | else |
| 776 | echo "$n instance of onos running" |
| 777 | fi |
| 778 | ;; |
| 779 | stop) |
| 780 | stop-onos |
| 781 | ;; |
| 782 | stat*) # <- status |
| 783 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 784 | echo "$n instance of onos running" |
| 785 | ;; |
| 786 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 787 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 788 | exit 1 |
| 789 | esac |
| 790 | } |
| 791 | |
| 792 | function start-onos { |
| 793 | if [ ! -d ${LOGDIR} ]; then |
| 794 | mkdir -p ${LOGDIR} |
| 795 | fi |
| 796 | # Backup log files |
| 797 | for log in ${LOGS}; do |
| 798 | if [ -f ${log} ]; then |
| 799 | rotate-log ${log} |
| 800 | fi |
| 801 | done |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 802 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 803 | if [ ! -f ${ONOS_LOGBACK} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 804 | echo "[WARNING] ${ONOS_LOGBACK} not found." |
| 805 | echo " Run \"\$ $0 setup\" to create." |
| 806 | exit 1 |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 807 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 808 | |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 809 | if [ ! -f ${HC_CONF} ]; then |
| 810 | echo "[WARNING] ${HC_CONF} not found." |
| 811 | echo " Run \"\$ $0 setup\" to create." |
| 812 | exit 1 |
| 813 | fi |
| 814 | |
| 815 | # specify hazelcast.xml to datagrid |
| 816 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig=${HC_CONF}" |
| 817 | |
| 818 | # specify backend config |
Jonathan Hart | ef3dc1a | 2014-04-03 11:39:50 -0700 | [diff] [blame] | 819 | 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] | 820 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 821 | JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}" |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 822 | elif [ "${ONOS_HOST_BACKEND}" = "hazelcast" ]; then |
| 823 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datastore.hazelcast.baseConfig=${HC_CONF}" |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 824 | fi |
| 825 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 826 | # Run ONOS |
Yuta HIGUCHI | cce4f62 | 2014-04-18 16:48:53 -0700 | [diff] [blame] | 827 | |
| 828 | # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD |
| 829 | cd ${ONOS_HOME} |
| 830 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 831 | echo -n "Starting ONOS controller ... " |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 832 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr & |
| 833 | |
| 834 | # We need to wait a bit to find out whether starting the ONOS process succeeded |
| 835 | sleep 1 |
| 836 | |
| 837 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 838 | if [ $n -ge 1 ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 839 | echo " STARTED" |
| 840 | else |
| 841 | echo " FAILED" |
| 842 | fi |
| 843 | |
| 844 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 845 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 846 | } |
| 847 | |
| 848 | function stop-onos { |
| 849 | kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'` |
| 850 | # kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 851 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 852 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 853 | |
| 854 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 855 | ################## Main #################### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 856 | case "$1" in |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 857 | setup) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 858 | create-confs $2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 859 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 860 | start) |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 861 | mode_parameter=${ONOS_HOST_ROLE} |
| 862 | if [ ! -z "$2" ]; then |
| 863 | mode_parameter=$2 |
| 864 | fi |
| 865 | |
| 866 | case "${mode_parameter}" in |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 867 | single-node) |
| 868 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 869 | start-backend coord |
| 870 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 871 | onos startifdown |
| 872 | ;; |
| 873 | coord-node) |
| 874 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 875 | start-backend coord |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 876 | onos startifdown |
| 877 | ;; |
| 878 | server-node) |
| 879 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 880 | start-backend server |
| 881 | onos startifdown |
| 882 | ;; |
| 883 | coord-and-server-node) |
| 884 | zk start |
| 885 | start-backend coord |
| 886 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 887 | onos startifdown |
| 888 | ;; |
| 889 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 890 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 891 | ;; |
| 892 | esac |
| 893 | echo |
| 894 | ;; |
| 895 | stop) |
| 896 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 897 | if [ $on != 0 ]; then |
| 898 | onos stop |
| 899 | fi |
| 900 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 901 | stop-backend |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 902 | |
| 903 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 904 | if [ $zkn != 0 ]; then |
| 905 | zk stop |
| 906 | fi |
| 907 | echo |
| 908 | ;; |
| 909 | restart) |
| 910 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 911 | if [ $on != 0 ]; then |
| 912 | onos stop |
| 913 | fi |
| 914 | |
| 915 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 916 | if [ $rcsn != 0 ]; then |
| 917 | rc-server stop |
| 918 | fi |
| 919 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 920 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 921 | if [ $rccn != 0 ]; then |
| 922 | rc-coord stop |
| 923 | fi |
| 924 | |
| 925 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 926 | if [ $zkn != 0 ]; then |
| 927 | zk restart |
| 928 | fi |
| 929 | |
| 930 | if [ $rccn != 0 ]; then |
| 931 | rc-coord startifdown |
| 932 | fi |
| 933 | |
| 934 | if [ $rcsn != 0 ]; then |
| 935 | rc-server startifdown |
| 936 | fi |
| 937 | |
| 938 | if [ $on != 0 ]; then |
| 939 | onos startifdown |
| 940 | fi |
| 941 | echo |
| 942 | ;; |
| 943 | stat*) # <- status |
| 944 | echo '[ZooKeeper]' |
| 945 | zk status |
| 946 | echo |
| 947 | echo '[RAMCloud coordinator]' |
| 948 | rc-coord status |
| 949 | echo |
| 950 | echo '[RAMCloud server]' |
| 951 | rc-server status |
| 952 | echo |
| 953 | echo '[ONOS core]' |
| 954 | onos status |
| 955 | echo |
| 956 | ;; |
| 957 | zk) |
| 958 | zk $2 |
| 959 | ;; |
| 960 | rc-c*) # <- rc-coordinator |
| 961 | rc-coord $2 |
| 962 | ;; |
| 963 | rc-s*) # <- rc-server |
| 964 | rc-server $2 |
| 965 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 966 | rc) |
Naoki Shiota | 9109a1e | 2014-05-13 11:11:01 -0700 | [diff] [blame] | 967 | # TODO make deldb command more organized (clarify when it can work) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 968 | rc-coord $2 |
| 969 | rc-server $2 |
| 970 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 971 | core) |
| 972 | onos $2 |
| 973 | ;; |
| 974 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 975 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 976 | exit 1 |
| 977 | esac |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 978 | |