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 | |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 128 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig=${HC_CONF}" |
| 129 | |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 130 | # Uncomment to dump final JVM flags to stdout |
| 131 | #JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal" |
| 132 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 133 | # Set ONOS core main class |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 134 | MAIN_CLASS="net.onrc.onos.core.main.Main" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 135 | |
| 136 | MVN=${MVN:-mvn -o} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 137 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 138 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 139 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 140 | ############# Common functions ############# |
| 141 | function print_usage { |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 142 | local scriptname=`basename $0` |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 143 | local filename=`basename ${ONOS_CONF}` |
| 144 | local usage="Usage: setup/start/stop ONOS on this server. |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 145 | \$ ${scriptname} setup [-f] |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 146 | Set up ONOS node using ${ONOS_CONF} . |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 147 | - generate and replace config file of ZooKeeper. |
| 148 | - create myid in ZooKeeper datadir. |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 149 | - generate and replace config file for Hazelcast. |
| 150 | - generate and replace config file for RAMCloud. |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 151 | - generate and replace logback.${ONOS_HOST_NAME}.xml |
| 152 | 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] | 153 | \$ ${scriptname} start [single-node|coord-node|server-node|coord-and-server-node] |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 154 | Start ONOS node with specific RAMCloud entities |
| 155 | - single-node: start ONOS with stand-alone RAMCloud |
| 156 | - coord-node : start ONOS with RAMCloud coordinator |
| 157 | - server-node: start ONOS with RAMCloud server |
| 158 | - coord-and-server-node: start ONOS with RAMCloud coordinator and server |
| 159 | * Default behavior can be defined by ${filename} |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 160 | \$ ${scriptname} stop |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 161 | Stop all ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 162 | \$ ${scriptname} restart |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 163 | Stop and start currently running ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 164 | \$ ${scriptname} status |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 165 | Show status of ONOS-related processes |
Naoki Shiota | 05721b3 | 2014-04-29 14:41:12 -0700 | [diff] [blame] | 166 | \$ ${scriptname} {zk|rc-coord|rc-server|core} {start|stop|restart|status} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 167 | Control specific ONOS-related process" |
| 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 | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 508 | echo "${RC_COORD_PROTOCOL}:host=${RC_COORD_IP},port=${RC_COORD_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | function rc-server-addr { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 512 | echo "${RC_SERVER_PROTOCOL}:host=${RC_SERVER_IP},port=${RC_SERVER_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 515 | function rc-coord { |
| 516 | case "$1" in |
| 517 | start) |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 518 | stop-coord |
| 519 | start-coord |
| 520 | ;; |
| 521 | startifdown) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 522 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 523 | if [ $n == 0 ]; then |
| 524 | start-coord |
| 525 | else |
| 526 | echo "$n instance of RAMCloud coordinator running" |
| 527 | fi |
| 528 | ;; |
| 529 | stop) |
| 530 | stop-coord |
| 531 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 532 | deldb) |
| 533 | stop-backend |
| 534 | del-coord-info |
| 535 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 536 | stat*) # <- status |
| 537 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
| 538 | echo "$n RAMCloud coordinator running" |
| 539 | ;; |
| 540 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 541 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 542 | exit 1 |
| 543 | esac |
| 544 | } |
| 545 | |
| 546 | function start-coord { |
Yuta HIGUCHI | 7170332 | 2014-05-06 09:17:29 -0700 | [diff] [blame] | 547 | wait-zk-or-die 2 |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 548 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 549 | if [ ! -d ${LOGDIR} ]; then |
| 550 | mkdir -p ${LOGDIR} |
| 551 | fi |
| 552 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 553 | rotate-log $RAMCLOUD_COORD_LOG |
| 554 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 555 | |
| 556 | local coord_addr=`rc-coord-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 557 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 558 | # TODO Configuration for ZK address, port |
| 559 | local zk_addr="localhost:2181" |
| 560 | # RAMCloud cluster name |
| 561 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC") |
| 562 | # RAMCloud option deadServerTimeout |
| 563 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 564 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 565 | |
| 566 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 567 | # but actual RAMCloud code only uses -C argument now. |
| 568 | # (FYI: -C is documented to be deprecated in the document) |
| 569 | |
| 570 | local coord_args="-C ${coord_addr}" |
| 571 | coord_args="${coord_args} --externalStorage zk:${zk_addr}" |
| 572 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
| 573 | coord_args="${coord_args} --deadServerTimeout ${rc_coord_deadServerTimeout}" |
| 574 | |
| 575 | # Read environment variables if set |
| 576 | coord_args="${coord_args} ${RC_COORDINATOR_OPTS}" |
| 577 | |
| 578 | if [ "${ONOS_HOST_ROLE}" == "single-node" ]; then |
| 579 | # Note: Following reset is required, since RC restart is considered node failure, |
| 580 | # and tries recovery of server, which will never succeed after restart. |
| 581 | echo "Role configured to single-node mode. RAMCloud cluster will be reset on each start-up." |
| 582 | coord_args="${coord_args} --reset" |
| 583 | fi |
| 584 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 585 | # Run ramcloud |
| 586 | echo -n "Starting RAMCloud coordinator ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 587 | ${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] | 588 | echo "STARTED" |
| 589 | } |
| 590 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 591 | function del-coord-info { |
| 592 | wait-zk-or-die 1 |
| 593 | |
| 594 | if [ ! -d ${LOGDIR} ]; then |
| 595 | mkdir -p ${LOGDIR} |
| 596 | fi |
| 597 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 598 | rotate-log $RAMCLOUD_COORD_LOG |
| 599 | fi |
| 600 | |
| 601 | local coord_addr=`rc-coord-addr` |
| 602 | |
| 603 | # TODO Configuration for ZK address, port |
| 604 | local zk_addr="localhost:2181" |
| 605 | # RAMCloud cluster name |
| 606 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC") |
| 607 | # RAMCloud option deadServerTimeout |
| 608 | # (note RC default is 250ms, setting relaxed ONOS default to 1000ms) |
| 609 | local rc_coord_deadServerTimeout=$(read-conf ${ONOS_CONF} ramcloud.coordinator.deadServerTimeout 1000) |
| 610 | |
| 611 | # NOTE RAMCloud document suggests to use -L to specify listen address:port, |
| 612 | # but actual RAMCloud code only uses -C argument now. |
| 613 | # (FYI: -C is documented to be deprecated in the document) |
| 614 | |
| 615 | local coord_args="-C ${coord_addr}" |
| 616 | coord_args="${coord_args} --externalStorage zk:${zk_addr}" |
| 617 | coord_args="${coord_args} --clusterName ${rc_cluster_name}" |
| 618 | |
| 619 | # Note: --reset will reset ZK stored info and start running as acoordinator. |
| 620 | echo -n "Deleting RAMCloud cluster coordination info ... " |
| 621 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator ${coord_args} --reset &> $RAMCLOUD_COORD_LOG & |
| 622 | |
| 623 | # TODO Assuming 1sec is enough. To be sure monitor log? |
| 624 | sleep 1 |
| 625 | # Silently kill coordinator |
| 626 | (pkill -q -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator &> /dev/null) |
| 627 | |
| 628 | echo "DONE" |
| 629 | } |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 630 | |
| 631 | function stop-coord { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 632 | kill-processes "RAMCloud coordinator" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 635 | ### Functions related to RAMCloud server |
| 636 | function rc-server { |
| 637 | case "$1" in |
| 638 | start) |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 639 | stop-server |
| 640 | start-server |
| 641 | ;; |
| 642 | startifdown) |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 643 | local n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 644 | if [ $n == 0 ]; then |
| 645 | start-server |
| 646 | else |
| 647 | echo "$n instance of RAMCloud server running" |
| 648 | fi |
| 649 | ;; |
| 650 | stop) |
| 651 | stop-server |
| 652 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 653 | deldb) |
| 654 | stop-server |
| 655 | del-server-backup |
| 656 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 657 | stat*) # <- status |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 658 | n=`pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 659 | echo "$n RAMCloud server running" |
| 660 | ;; |
| 661 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 662 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 663 | exit 1 |
| 664 | esac |
| 665 | } |
| 666 | |
| 667 | function start-server { |
Yuta HIGUCHI | 7170332 | 2014-05-06 09:17:29 -0700 | [diff] [blame] | 668 | wait-zk-or-die 2 |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 669 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 670 | if [ ! -d ${LOGDIR} ]; then |
| 671 | mkdir -p ${LOGDIR} |
| 672 | fi |
| 673 | if [ -f $RAMCLOUD_SERVER_LOG ]; then |
| 674 | rotate-log $RAMCLOUD_SERVER_LOG |
| 675 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 676 | |
| 677 | local coord_addr=`rc-coord-addr` |
| 678 | local server_addr=`rc-server-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 679 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 680 | local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.server.masterServiceThreads 5) |
| 681 | local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.server.logCleanerThreads 1) |
| 682 | local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.server.detectFailures 1) |
| 683 | |
| 684 | # TODO Configuration for ZK address, port |
| 685 | local zk_addr="localhost:2181" |
| 686 | # RAMCloud cluster name |
| 687 | local rc_cluster_name=$(read-conf ${ONOS_CONF} ramcloud.clusterName "ONOS-RC") |
| 688 | # replication factor (-r) config |
| 689 | local rc_replicas=$(read-conf ${ONOS_CONF} ramcloud.server.replicas 0) |
| 690 | # backup file path (-f) config |
| 691 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 692 | mkdir -p `dirname ${rc_datafile}` |
| 693 | |
| 694 | local server_args="-L ${server_addr}" |
| 695 | server_args="${server_args} --externalStorage zk:${zk_addr}" |
| 696 | server_args="${server_args} --clusterName ${rc_cluster_name}" |
| 697 | server_args="${server_args} --masterServiceThreads ${masterServiceThreads}" |
| 698 | server_args="${server_args} --logCleanerThreads ${logCleanerThreads}" |
| 699 | server_args="${server_args} --detectFailures ${detectFailures}" |
| 700 | server_args="${server_args} --replicas ${rc_replicas}" |
| 701 | server_args="${server_args} --file ${rc_datafile}" |
| 702 | |
| 703 | # Read environment variables if set |
| 704 | server_args="${server_args} ${RC_SERVER_OPTS}" |
Yuta HIGUCHI | 45bc3cf | 2014-04-19 18:12:15 -0700 | [diff] [blame] | 705 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 706 | # Run ramcloud |
| 707 | echo -n "Starting RAMCloud server ... " |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 708 | ${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] | 709 | echo "STARTED" |
| 710 | } |
| 711 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 712 | function del-server-backup { |
| 713 | # TODO might want confirmation, since data can be lost |
| 714 | echo -n "Removing RAMCloud backup server data ... " |
| 715 | local rc_datafile=$(read-conf ${ONOS_CONF} ramcloud.server.file "/var/tmp/ramclouddata/backup.${ONOS_HOST_NAME}.log") |
| 716 | rm -f ${rc_datafile} |
| 717 | echo "DONE" |
| 718 | } |
| 719 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 720 | function stop-server { |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 721 | kill-processes "RAMCloud server" `pgrep -f ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 722 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 723 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 724 | |
| 725 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 726 | ## Functions related to ONOS core process ## |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 727 | function onos { |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 728 | CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 729 | if [ ! -f ${CPFILE} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 730 | echo "ONOS core needs to be built" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 731 | ${MVN} -f ${ONOS_HOME}/pom.xml compile |
| 732 | fi |
| 733 | JAVA_CP=`cat ${CPFILE}` |
| 734 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
| 735 | |
| 736 | case "$1" in |
| 737 | start) |
| 738 | stop-onos |
| 739 | start-onos |
| 740 | ;; |
| 741 | startnokill) |
| 742 | start-onos |
| 743 | ;; |
| 744 | startifdown) |
| 745 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 746 | if [ $n == 0 ]; then |
| 747 | start-onos |
| 748 | else |
| 749 | echo "$n instance of onos running" |
| 750 | fi |
| 751 | ;; |
| 752 | stop) |
| 753 | stop-onos |
| 754 | ;; |
| 755 | stat*) # <- status |
| 756 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 757 | echo "$n instance of onos running" |
| 758 | ;; |
| 759 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 760 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 761 | exit 1 |
| 762 | esac |
| 763 | } |
| 764 | |
| 765 | function start-onos { |
| 766 | if [ ! -d ${LOGDIR} ]; then |
| 767 | mkdir -p ${LOGDIR} |
| 768 | fi |
| 769 | # Backup log files |
| 770 | for log in ${LOGS}; do |
| 771 | if [ -f ${log} ]; then |
| 772 | rotate-log ${log} |
| 773 | fi |
| 774 | done |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 775 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 776 | if [ ! -f ${ONOS_LOGBACK} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 777 | echo "[WARNING] ${ONOS_LOGBACK} not found." |
| 778 | echo " Run \"\$ $0 setup\" to create." |
| 779 | exit 1 |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 780 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 781 | |
Jonathan Hart | ef3dc1a | 2014-04-03 11:39:50 -0700 | [diff] [blame] | 782 | 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] | 783 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 784 | JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}" |
| 785 | fi |
| 786 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 787 | # Run ONOS |
Yuta HIGUCHI | cce4f62 | 2014-04-18 16:48:53 -0700 | [diff] [blame] | 788 | |
| 789 | # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD |
| 790 | cd ${ONOS_HOME} |
| 791 | |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 792 | echo -n "Starting ONOS controller ... " |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 793 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr & |
| 794 | |
| 795 | # We need to wait a bit to find out whether starting the ONOS process succeeded |
| 796 | sleep 1 |
| 797 | |
| 798 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 799 | if [ $n -ge 1 ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 800 | echo " STARTED" |
| 801 | else |
| 802 | echo " FAILED" |
| 803 | fi |
| 804 | |
| 805 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 806 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 807 | } |
| 808 | |
| 809 | function stop-onos { |
| 810 | kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'` |
| 811 | # kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 812 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 813 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 814 | |
| 815 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 816 | ################## Main #################### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 817 | case "$1" in |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 818 | setup) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 819 | create-confs $2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 820 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 821 | start) |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 822 | mode_parameter=${ONOS_HOST_ROLE} |
| 823 | if [ ! -z "$2" ]; then |
| 824 | mode_parameter=$2 |
| 825 | fi |
| 826 | |
| 827 | case "${mode_parameter}" in |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 828 | single-node) |
| 829 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 830 | start-backend coord |
| 831 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 832 | onos startifdown |
| 833 | ;; |
| 834 | coord-node) |
| 835 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 836 | start-backend coord |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 837 | onos startifdown |
| 838 | ;; |
| 839 | server-node) |
| 840 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 841 | start-backend server |
| 842 | onos startifdown |
| 843 | ;; |
| 844 | coord-and-server-node) |
| 845 | zk start |
| 846 | start-backend coord |
| 847 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 848 | onos startifdown |
| 849 | ;; |
| 850 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 851 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 852 | ;; |
| 853 | esac |
| 854 | echo |
| 855 | ;; |
| 856 | stop) |
| 857 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 858 | if [ $on != 0 ]; then |
| 859 | onos stop |
| 860 | fi |
| 861 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 862 | stop-backend |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 863 | |
| 864 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 865 | if [ $zkn != 0 ]; then |
| 866 | zk stop |
| 867 | fi |
| 868 | echo |
| 869 | ;; |
| 870 | restart) |
| 871 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 872 | if [ $on != 0 ]; then |
| 873 | onos stop |
| 874 | fi |
| 875 | |
| 876 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 877 | if [ $rcsn != 0 ]; then |
| 878 | rc-server stop |
| 879 | fi |
| 880 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 881 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 882 | if [ $rccn != 0 ]; then |
| 883 | rc-coord stop |
| 884 | fi |
| 885 | |
| 886 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 887 | if [ $zkn != 0 ]; then |
| 888 | zk restart |
| 889 | fi |
| 890 | |
| 891 | if [ $rccn != 0 ]; then |
| 892 | rc-coord startifdown |
| 893 | fi |
| 894 | |
| 895 | if [ $rcsn != 0 ]; then |
| 896 | rc-server startifdown |
| 897 | fi |
| 898 | |
| 899 | if [ $on != 0 ]; then |
| 900 | onos startifdown |
| 901 | fi |
| 902 | echo |
| 903 | ;; |
| 904 | stat*) # <- status |
| 905 | echo '[ZooKeeper]' |
| 906 | zk status |
| 907 | echo |
| 908 | echo '[RAMCloud coordinator]' |
| 909 | rc-coord status |
| 910 | echo |
| 911 | echo '[RAMCloud server]' |
| 912 | rc-server status |
| 913 | echo |
| 914 | echo '[ONOS core]' |
| 915 | onos status |
| 916 | echo |
| 917 | ;; |
| 918 | zk) |
| 919 | zk $2 |
| 920 | ;; |
| 921 | rc-c*) # <- rc-coordinator |
| 922 | rc-coord $2 |
| 923 | ;; |
| 924 | rc-s*) # <- rc-server |
| 925 | rc-server $2 |
| 926 | ;; |
Yuta HIGUCHI | d150ece | 2014-04-29 16:25:36 -0700 | [diff] [blame] | 927 | rc) |
| 928 | rc-coord $2 |
| 929 | rc-server $2 |
| 930 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 931 | core) |
| 932 | onos $2 |
| 933 | ;; |
| 934 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 935 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 936 | exit 1 |
| 937 | esac |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 938 | |