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