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