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