Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 2 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 3 | ### Env vars used by this script. (default value) ### |
| 4 | # $ONOS_HOME : path of root directory of ONOS repository (this script's dir) |
| 5 | # $ONOS_CONF_DIR : path of ONOS config directory (~/ONOS/conf) |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 6 | # $ONOS_CONF : path of ONOS node config file (~/ONOS/conf/onos_node.`hostname`.conf or onos_node.conf) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 7 | # $ONOS_PROPS : path of ONOS properties file (~/ONOS/conf/onos.properties) |
| 8 | # $ONOS_LOGBACK : path of logback config file (~/ONOS/conf/logback.`hostname`.xml) |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 9 | # $ONOS_LOGDIR : path of log output directory (~/ONOS/onos-logs) |
| 10 | # $ONOS_LOGBASE : base name of log output file (onos.`hostname`) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 11 | # $RAMCLOUD_HOME : path of root directory of RAMCloud repository (~/ramcloud) |
| 12 | # $RAMCLOUD_BRANCH : branch name of RAMCloud to use (master) |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 13 | # $ZK_HOME : path of root directory of ZooKeeper (~/zookeeper-3.4.5) |
| 14 | # $ZK_LIB_DIR : path of ZooKeeper library (/var/lib/zookeeper) |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 15 | # $ZK_LOG_DIR : path of ZooKeeper log output directory (~/ONOS/onos-logs/zk-`hostname`) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 16 | # $JVM_OPTS : JVM options ONOS starts with |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 17 | # $ZK_CONF : path of ZooKeeper config file (~/ONOS/conf/zoo.cfg) |
| 18 | # $HC_CONF : path of Hazelcast config file (~/ONOS/conf/hazelcast.xml) |
| 19 | # $RAMCLOUD_CONF : path of RAMCloud config file (~/ONOS/conf/ramcloud.conf) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 20 | ##################################################### |
| 21 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 22 | ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 23 | ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf} |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 24 | ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.`hostname`.conf} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 25 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 26 | source ${ONOS_HOME}/scripts/common/utils.sh |
| 27 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 28 | if [ ! -f ${ONOS_CONF} ]; then |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 29 | # falling back to default config file |
| 30 | ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf |
| 31 | if [ ! -f ${ONOS_CONF} ]; then |
| 32 | echo "${ONOS_CONF} not found." |
| 33 | exit 1 |
| 34 | fi |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 35 | fi |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 36 | |
| 37 | |
| 38 | ### Variables read from ONOS config file ### |
| 39 | ONOS_HOST_NAME=$(read-conf ${ONOS_CONF} host.name `hostname`) |
| 40 | ONOS_HOST_IP=$(read-conf ${ONOS_CONF} host.ip) |
| 41 | ONOS_HOST_ROLE=$(read-conf ${ONOS_CONF} host.role) |
| 42 | ONOS_HOST_BACKEND=$(read-conf ${ONOS_CONF} host.backend) |
| 43 | ZK_HOSTS=$(read-conf ${ONOS_CONF} zookeeper.hosts ${ONOS_HOST_NAME}) |
| 44 | RC_COORD_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.coordinator.protocol "fast+udp") |
| 45 | RC_COORD_IP=$(read-conf ${ONOS_CONF} ramcloud.coordinator.ip ${ONOS_HOST_IP}) |
| 46 | RC_COORD_PORT=$(read-conf ${ONOS_CONF} ramcloud.coordinator.port 12246) |
| 47 | RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp") |
| 48 | RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP}) |
| 49 | RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242) |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 50 | HC_HOST_PORT=$(read-conf ${ONOS_CONF} hazelcast.host.port 5701) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 51 | HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members) |
| 52 | HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3") |
| 53 | HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 54 | ############################################ |
| 55 | |
| 56 | |
| 57 | ############## Other variables ############# |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 58 | ONOS_TEMPLATE_DIR=${ONOS_CONF_DIR}/template |
| 59 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 60 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
| 61 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 62 | ZK_HOME=${ZK_HOME:-~/zookeeper-3.4.5} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 63 | ZK_CONF=${ZK_CONF:-${ONOS_CONF_DIR}/zoo.cfg} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 64 | ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 65 | # Adding ONOS_HOST_NAME dir since file name (zookeeper.out) cannot be controlled. |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 66 | ZK_LOG_DIR=${ZK_LOG_DIR:-${ONOS_HOME}/onos-logs/zk-${ONOS_HOST_NAME}} |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 67 | ZK_LIB_DIR=${ZK_LIB_DIR:-/var/lib/zookeeper} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 68 | ZK_MY_ID=${ZK_LIB_DIR}/myid |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 69 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 70 | HC_CONF=${HC_CONF:-${ONOS_CONF_DIR}/hazelcast.xml} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 71 | HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template |
| 72 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 73 | RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 74 | RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log |
| 75 | RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 76 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 77 | RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_CONF_DIR}/ramcloud.conf} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 78 | |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 79 | export LD_LIBRARY_PATH=${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}:$LD_LIBRARY_PATH |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 80 | |
| 81 | ## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 82 | ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_CONF_DIR}/logback.${ONOS_HOST_NAME}.xml} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 83 | ONOS_LOGBACK_BACKUP=${ONOS_LOGBACK}.bak |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 84 | ONOS_LOGBACK_TEMPLATE=${ONOS_TEMPLATE_DIR}/logback.xml.template |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 85 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 86 | LOGBASE=${ONOS_LOGBASE:-onos.${ONOS_HOST_NAME}} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 87 | ONOS_LOG="${LOGDIR}/${LOGBASE}.log" |
| 88 | PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap" |
| 89 | LOGS="$ONOS_LOG $PCAP_LOG" |
| 90 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 91 | ONOS_PROPS=${ONOS_PROPS:-${ONOS_CONF_DIR}/onos.properties} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 92 | JMX_PORT=${JMX_PORT:-7189} |
| 93 | |
| 94 | # Set JVM options |
| 95 | JVM_OPTS="${JVM_OPTS:-}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 96 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 97 | #JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 98 | |
| 99 | # Uncomment or specify appropriate value as JVM_OPTS environment variables. |
| 100 | #JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 101 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 102 | #JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m" |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 103 | |
| 104 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC" |
| 105 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC" |
| 106 | JVM_OPTS="$JVM_OPTS -XX:+AggressiveOpts" |
| 107 | |
| 108 | # We may want to remove UseFastAccessorMethods option: http://bugs.java.com/view_bug.do?bug_id=6385687 |
| 109 | JVM_OPTS="$JVM_OPTS -XX:+UseFastAccessorMethods" |
| 110 | |
| 111 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192" |
| 112 | JVM_OPTS="$JVM_OPTS -XX:FreqInlineSize=8192" |
| 113 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500" |
| 114 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 115 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 116 | |
| 117 | # Workaround for Thread Priority http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html |
| 118 | JVM_OPTS="$JVM_OPTS -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42" |
| 119 | |
| 120 | JVM_OPTS="$JVM_OPTS -XX:+UseCompressedOops" |
| 121 | |
| 122 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT" |
| 123 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false" |
| 124 | JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" |
| 125 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 126 | JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j" |
| 127 | |
Naoki Shiota | d8ea71a | 2014-04-23 17:04:51 -0700 | [diff] [blame] | 128 | JVM_OPTS="${JVM_OPTS} -Dnet.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig=${HC_CONF}" |
| 129 | |
Yuta HIGUCHI | 1835459 | 2014-04-01 13:53:42 -0700 | [diff] [blame] | 130 | # Uncomment to dump final JVM flags to stdout |
| 131 | #JVM_OPTS="$JVM_OPTS -XX:+PrintFlagsFinal" |
| 132 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 133 | # Set ONOS core main class |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 134 | MAIN_CLASS="net.onrc.onos.core.main.Main" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 135 | |
| 136 | MVN=${MVN:-mvn -o} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 137 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 138 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 139 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 140 | ############# Common functions ############# |
| 141 | function print_usage { |
| 142 | local filename=`basename ${ONOS_CONF}` |
| 143 | local usage="Usage: setup/start/stop ONOS on this server. |
| 144 | \$ $0 setup [-f] |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 145 | Set up ONOS node using ${ONOS_CONF} . |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 146 | - generate and replace config file of ZooKeeper. |
| 147 | - create myid in ZooKeeper datadir. |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 148 | - generate and replace config file for Hazelcast. |
| 149 | - generate and replace config file for RAMCloud. |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 150 | - generate and replace logback.${ONOS_HOST_NAME}.xml |
| 151 | If -f option is used, all existing files will be overwritten without confirmation. |
| 152 | \$ $0 start [single-node|coord-node|server-node|coord-and-server-node] |
| 153 | Start ONOS node with specific RAMCloud entities |
| 154 | - single-node: start ONOS with stand-alone RAMCloud |
| 155 | - coord-node : start ONOS with RAMCloud coordinator |
| 156 | - server-node: start ONOS with RAMCloud server |
| 157 | - coord-and-server-node: start ONOS with RAMCloud coordinator and server |
| 158 | * Default behavior can be defined by ${filename} |
| 159 | \$ $0 stop |
| 160 | Stop all ONOS-related processes |
| 161 | \$ $0 restart |
| 162 | Stop and start currently running ONOS-related processes |
| 163 | \$$0 status |
| 164 | Show status of ONOS-related processes |
| 165 | \$ $0 {zk|rc-coord|rc-server|core} {start|stop|restart|status} |
| 166 | Control specific ONOS-related process" |
| 167 | |
| 168 | echo "${usage}" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | function rotate-log { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 172 | local logfile=$1 |
| 173 | local nr_max=${2:-10} |
| 174 | if [ -f $logfile ]; then |
| 175 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 176 | if [ -f ${logfile}.${i} ]; then |
| 177 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 178 | fi |
| 179 | done |
| 180 | mv $logfile $logfile.1 |
| 181 | fi |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | # kill-processes {module-name} {array of pids} |
| 185 | function kill-processes { |
| 186 | # Kill the existing processes |
| 187 | local pids=$2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 188 | if [ ! -z "$pids" ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 189 | echo -n "Stopping $1 ... " |
| 190 | fi |
| 191 | for p in ${pids}; do |
| 192 | if [ x$p != "x" ]; then |
| 193 | kill -KILL $p |
| 194 | echo "Killed existing process (pid: $p)" |
| 195 | fi |
| 196 | done |
| 197 | } |
| 198 | |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 199 | function handle-error { |
| 200 | set -e |
| 201 | |
| 202 | revert-confs |
| 203 | |
| 204 | set +e |
| 205 | |
| 206 | exit 1 |
| 207 | } |
| 208 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 209 | # revert-confs [error message] |
| 210 | function revert-confs { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 211 | echo -n "ERROR occurred ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 212 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 213 | revert-file `basename ${ZK_CONF}` |
| 214 | revert-file `basename ${HC_CONF}` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 215 | |
| 216 | echo "EXIT" |
| 217 | |
| 218 | if [ ! -z "$1" ]; then |
| 219 | echo $1 |
| 220 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 223 | function create-zk-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 224 | echo -n "Creating ${ZK_CONF} ... " |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 225 | |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 226 | # Create the ZooKeeper lib directory |
| 227 | if [ ! -d ${ZK_LIB_DIR} ]; then |
| 228 | local SUDO=${SUDO:-} |
| 229 | local whoami=`whoami` |
| 230 | { |
| 231 | ${SUDO} mkdir ${ZK_LIB_DIR} |
| 232 | ${SUDO} chown ${whoami} ${ZK_LIB_DIR} |
| 233 | } || { |
| 234 | echo "FAILED" |
| 235 | echo "[ERROR] Failed to create directory ${ZK_LIB_DIR}." |
| 236 | echo "[ERROR] Please retry after setting \"env SUDO=sudo\"" |
| 237 | exit 1 |
| 238 | } |
| 239 | fi |
| 240 | |
| 241 | # creation of ZooKeeper config |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 242 | local temp_zk=`begin-conf-creation ${ZK_CONF}` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 243 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 244 | hostarr=`echo ${ZK_HOSTS} | tr "," " "` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 245 | |
| 246 | local i=1 |
| 247 | local myid= |
| 248 | for host in ${hostarr}; do |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 249 | if [ "${host}" = "${ONOS_HOST_NAME}" -o "${host}" = "${ONOS_HOST_IP}" ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 250 | myid=$i |
| 251 | break |
| 252 | fi |
| 253 | i=`expr $i + 1` |
| 254 | done |
| 255 | |
| 256 | if [ -z "${myid}" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 257 | local filename=`basename ${ONOS_CONF}` |
Naoki Shiota | 35f8d5c | 2014-04-08 11:13:18 -0700 | [diff] [blame] | 258 | 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] | 259 | fi |
| 260 | |
Yuta HIGUCHI | 6945089 | 2014-04-16 09:10:55 -0700 | [diff] [blame] | 261 | if [ -f "${ZK_MY_ID}" ]; then |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 262 | # 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] | 263 | local SUDO=${SUDO:-} |
| 264 | { |
| 265 | ${SUDO} mv -f ${ZK_MY_ID} ${ZK_MY_ID}.old |
| 266 | } || { |
| 267 | echo "FAILED" |
| 268 | echo "[ERROR] Failed to rename ${ZK_MY_ID}." |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 269 | echo "[ERROR] Please retry after setting \"env SUDO=sudo\"" |
Yuta HIGUCHI | 6945089 | 2014-04-16 09:10:55 -0700 | [diff] [blame] | 270 | exit 1 |
| 271 | } |
| 272 | fi |
| 273 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 274 | echo ${myid} > ${ZK_MY_ID} |
| 275 | |
| 276 | echo -n "myid is assigned to ${myid} ... " |
| 277 | |
| 278 | while read line; do |
| 279 | if [[ $line =~ ^__HOSTS__$ ]]; then |
| 280 | i=1 |
| 281 | for host in ${hostarr}; do |
| 282 | # TODO: ports might be configurable |
| 283 | local hostline="server.${i}=${host}:2888:3888" |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 284 | echo $hostline |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 285 | i=`expr $i + 1` |
| 286 | done |
| 287 | elif [[ $line =~ __DATADIR__ ]]; then |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 288 | echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 289 | else |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 290 | echo $line |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 291 | fi |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 292 | done < ${ZK_CONF_TEMPLATE} > ${temp_zk} |
| 293 | |
| 294 | end-conf-creation ${ZK_CONF} |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 295 | |
| 296 | echo "DONE" |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 297 | } |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 298 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 299 | function create-hazelcast-conf { |
| 300 | echo -n "Creating ${HC_CONF} ... " |
| 301 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 302 | local temp_hc=`begin-conf-creation ${HC_CONF}` |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 303 | |
| 304 | # To keep indent of XML file, change IFS |
| 305 | local IFS='' |
| 306 | while read line; do |
| 307 | if [[ $line =~ __HC_NETWORK__ ]]; then |
| 308 | if [ ! -z "${HC_TCPIP_MEMBERS}" ]; then |
| 309 | # temporary change |
| 310 | IFS=' ' |
| 311 | local memberarr=`echo ${HC_TCPIP_MEMBERS} | tr "," " "` |
| 312 | echo '<multicast enabled="false" />' |
| 313 | echo '<tcp-ip enabled="true">' |
| 314 | for member in ${memberarr}; do |
| 315 | echo " <member>${member}</member>" |
| 316 | done |
| 317 | echo '</tcp-ip>' |
| 318 | IFS='' |
| 319 | else |
| 320 | echo '<multicast enabled="true">' |
| 321 | echo " <multicast-group>${HC_MULTICAST_GROUP}</multicast-group>" |
| 322 | echo " <multicast-port>${HC_MULTICAST_PORT}</multicast-port>" |
| 323 | echo '</multicast>' |
| 324 | echo '<tcp-ip enabled="false" />' |
| 325 | fi |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 326 | elif [[ $line =~ __HC_PORT__ ]]; then |
| 327 | echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|" |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 328 | else |
| 329 | echo "${line}" |
| 330 | fi |
| 331 | done < ${HC_CONF_TEMPLATE} > ${temp_hc} |
| 332 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 333 | end-conf-creation ${HC_CONF} |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 334 | |
| 335 | echo "DONE" |
| 336 | } |
| 337 | |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 338 | function create-ramcloud-conf { |
| 339 | echo -n "Creating ${RAMCLOUD_CONF} ... " |
| 340 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 341 | local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}` |
| 342 | |
| 343 | echo "ramcloud.coordinatorIp=${RC_COORD_PROTOCOL}:host=${RC_COORD_IP}" > ${temp_rc} |
| 344 | echo "ramcloud.coordinatorPort=port=${RC_COORD_PORT}" >> ${temp_rc} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 345 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 346 | end-conf-creation ${RAMCLOUD_CONF} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 347 | |
| 348 | echo "DONE" |
| 349 | } |
| 350 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 351 | function create-logback-conf { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 352 | echo -n "Creating ${ONOS_LOGBACK} ... " |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 353 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 354 | # creation of logback config |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 355 | local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}` |
| 356 | |
| 357 | sed -e "s|__FILENAME__|${ONOS_LOG}|" ${ONOS_LOGBACK_TEMPLATE} > ${temp_lb} |
| 358 | |
| 359 | end-conf-creation ${ONOS_LOGBACK} |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 360 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 361 | echo "DONE" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 364 | function create-confs { |
| 365 | local key |
| 366 | local filename |
| 367 | |
Naoki Shiota | 9a1e6d1 | 2014-04-03 14:47:12 -0700 | [diff] [blame] | 368 | trap handle-error ERR |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 369 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 370 | echo "Config file : ${ONOS_CONF}" |
| 371 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 372 | if [ "$1" == "-f" ]; then |
| 373 | create-zk-conf |
| 374 | create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 375 | create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 376 | create-logback-conf |
| 377 | else |
| 378 | create-conf-interactive ${ZK_CONF} create-zk-conf |
| 379 | create-conf-interactive ${HC_CONF} create-hazelcast-conf |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 380 | create-conf-interactive ${RAMCLOUD_CONF} create-ramcloud-conf |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 381 | create-conf-interactive ${ONOS_LOGBACK} create-logback-conf |
| 382 | fi |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 383 | |
| 384 | trap - ERR |
| 385 | } |
| 386 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 387 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 388 | |
| 389 | ###### Functions related to ZooKeeper ###### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 390 | function zk { |
| 391 | case "$1" in |
| 392 | start) |
| 393 | start-zk |
| 394 | ;; |
| 395 | stop) |
| 396 | stop-zk |
| 397 | ;; |
| 398 | stat*) # <- status |
| 399 | status-zk |
| 400 | ;; |
| 401 | re*) # <- restart |
| 402 | stop-zk |
| 403 | start-zk |
| 404 | ;; |
| 405 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 406 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 407 | exit 1 |
| 408 | esac |
| 409 | } |
| 410 | |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 411 | function load-zk-cfg { |
| 412 | if [ -f "${ZK_CONF}" ]; then |
| 413 | local filename=`basename ${ZK_CONF}` |
| 414 | local dirname=`dirname ${ZK_CONF}` |
| 415 | |
| 416 | # Run ZooKeeper with our configuration |
| 417 | export ZOOCFG=${filename} |
| 418 | export ZOOCFGDIR=${dirname} |
| 419 | fi |
| 420 | } |
| 421 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 422 | function start-zk { |
Pavlin Radoslavov | d8f30d9 | 2014-04-18 13:03:09 -0700 | [diff] [blame] | 423 | echo -n "Starting ZooKeeper ... " |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 424 | |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 425 | export ZOO_LOG_DIR=${ZK_LOG_DIR} |
Yuta HIGUCHI | 13d1dbf | 2014-04-17 20:51:38 -0700 | [diff] [blame] | 426 | mkdir -p ${ZK_LOG_DIR} |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 427 | |
| 428 | load-zk-cfg |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 429 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 430 | ${ZK_HOME}/bin/zkServer.sh start |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | function stop-zk { |
| 434 | kill-processes "ZooKeeper" `jps -l | grep org.apache.zookeeper.server | awk '{print $1}'` |
| 435 | } |
| 436 | |
| 437 | function status-zk { |
Naoki Shiota | b7eb55d | 2014-04-21 18:21:36 -0700 | [diff] [blame] | 438 | load-zk-cfg |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 439 | |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 440 | ${ZK_HOME}/bin/zkServer.sh status |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 441 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 442 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 443 | |
| 444 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 445 | ####### Functions related to RAMCloud ###### |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 446 | function start-backend { |
| 447 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 448 | if [ $1 == "coord" ]; then |
| 449 | rc-coord startifdown |
| 450 | elif [ $1 == "server" ]; then |
| 451 | rc-server startifdown |
| 452 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 453 | fi |
| 454 | } |
| 455 | |
| 456 | function stop-backend { |
| 457 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 458 | if [ $rcsn != 0 ]; then |
| 459 | rc-server stop |
| 460 | fi |
| 461 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 462 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 463 | if [ $rccn != 0 ]; then |
| 464 | rc-coord stop |
| 465 | fi |
| 466 | } |
| 467 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 468 | function deldb { |
| 469 | # TODO: implement |
| 470 | return |
| 471 | } |
| 472 | |
| 473 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 474 | ### Functions related to RAMCloud coordinator |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 475 | function rc-coord-addr { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 476 | echo "${RC_COORD_PROTOCOL}:host=${RC_COORD_IP},port=${RC_COORD_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | function rc-server-addr { |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 480 | echo "${RC_SERVER_PROTOCOL}:host=${RC_SERVER_IP},port=${RC_SERVER_PORT}" |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 483 | function rc-coord { |
| 484 | case "$1" in |
| 485 | start) |
| 486 | deldb |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 487 | stop-coord |
| 488 | start-coord |
| 489 | ;; |
| 490 | startifdown) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 491 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 492 | if [ $n == 0 ]; then |
| 493 | start-coord |
| 494 | else |
| 495 | echo "$n instance of RAMCloud coordinator running" |
| 496 | fi |
| 497 | ;; |
| 498 | stop) |
| 499 | stop-coord |
| 500 | ;; |
| 501 | stat*) # <- status |
| 502 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
| 503 | echo "$n RAMCloud coordinator running" |
| 504 | ;; |
| 505 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 506 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 507 | exit 1 |
| 508 | esac |
| 509 | } |
| 510 | |
| 511 | function start-coord { |
| 512 | if [ ! -d ${LOGDIR} ]; then |
| 513 | mkdir -p ${LOGDIR} |
| 514 | fi |
| 515 | if [ -f $RAMCLOUD_COORD_LOG ]; then |
| 516 | rotate-log $RAMCLOUD_COORD_LOG |
| 517 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 518 | |
| 519 | local coord_addr=`rc-coord-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 520 | |
| 521 | # Run ramcloud |
| 522 | echo -n "Starting RAMCloud coordinator ... " |
Naoki Shiota | 7220972 | 2014-04-08 14:32:17 -0700 | [diff] [blame] | 523 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/coordinator -L ${coord_addr} > $RAMCLOUD_COORD_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 524 | echo "STARTED" |
| 525 | } |
| 526 | |
| 527 | |
| 528 | function stop-coord { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 529 | kill-processes "RAMCloud coordinator" `pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 532 | ### Functions related to RAMCloud server |
| 533 | function rc-server { |
| 534 | case "$1" in |
| 535 | start) |
| 536 | deldb |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 537 | stop-server |
| 538 | start-server |
| 539 | ;; |
| 540 | startifdown) |
| 541 | local n=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 542 | if [ $n == 0 ]; then |
| 543 | start-server |
| 544 | else |
| 545 | echo "$n instance of RAMCloud server running" |
| 546 | fi |
| 547 | ;; |
| 548 | stop) |
| 549 | stop-server |
| 550 | ;; |
| 551 | # deldb) |
| 552 | # deldb |
| 553 | # ;; |
| 554 | stat*) # <- status |
| 555 | n=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 556 | echo "$n RAMCloud server running" |
| 557 | ;; |
| 558 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 559 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 560 | exit 1 |
| 561 | esac |
| 562 | } |
| 563 | |
| 564 | function start-server { |
| 565 | if [ ! -d ${LOGDIR} ]; then |
| 566 | mkdir -p ${LOGDIR} |
| 567 | fi |
| 568 | if [ -f $RAMCLOUD_SERVER_LOG ]; then |
| 569 | rotate-log $RAMCLOUD_SERVER_LOG |
| 570 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 571 | |
| 572 | local coord_addr=`rc-coord-addr` |
| 573 | local server_addr=`rc-server-addr` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 574 | |
Yuta HIGUCHI | 45bc3cf | 2014-04-19 18:12:15 -0700 | [diff] [blame] | 575 | local masterServiceThreads=$(read-conf ${ONOS_CONF} ramcloud.masterServiceThreads 5) |
| 576 | local logCleanerThreads=$(read-conf ${ONOS_CONF} ramcloud.logCleanerThreads 1) |
| 577 | local detectFailures=$(read-conf ${ONOS_CONF} ramcloud.detectFailures 0) |
| 578 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 579 | # Run ramcloud |
| 580 | echo -n "Starting RAMCloud server ... " |
Yuta HIGUCHI | 45bc3cf | 2014-04-19 18:12:15 -0700 | [diff] [blame] | 581 | ${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}/server -M -L ${server_addr} -C ${coord_addr} --masterServiceThreads ${masterServiceThreads} --logCleanerThreads ${logCleanerThreads} --detectFailures ${detectFailures} > $RAMCLOUD_SERVER_LOG 2>&1 & |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 582 | echo "STARTED" |
| 583 | } |
| 584 | |
| 585 | function stop-server { |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 586 | kill-processes "RAMCloud server" `pgrep -f obj.${RAMCLOUD_BRANCH}/server` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 587 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 588 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 589 | |
| 590 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 591 | ## Functions related to ONOS core process ## |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 592 | function onos { |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 593 | CPFILE=${ONOS_HOME}/.javacp.${ONOS_HOST_NAME} |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 594 | if [ ! -f ${CPFILE} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 595 | echo "ONOS core needs to be built" |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 596 | ${MVN} -f ${ONOS_HOME}/pom.xml compile |
| 597 | fi |
| 598 | JAVA_CP=`cat ${CPFILE}` |
| 599 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
| 600 | |
| 601 | case "$1" in |
| 602 | start) |
| 603 | stop-onos |
| 604 | start-onos |
| 605 | ;; |
| 606 | startnokill) |
| 607 | start-onos |
| 608 | ;; |
| 609 | startifdown) |
| 610 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 611 | if [ $n == 0 ]; then |
| 612 | start-onos |
| 613 | else |
| 614 | echo "$n instance of onos running" |
| 615 | fi |
| 616 | ;; |
| 617 | stop) |
| 618 | stop-onos |
| 619 | ;; |
| 620 | stat*) # <- status |
| 621 | n=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 622 | echo "$n instance of onos running" |
| 623 | ;; |
| 624 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 625 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 626 | exit 1 |
| 627 | esac |
| 628 | } |
| 629 | |
| 630 | function start-onos { |
| 631 | if [ ! -d ${LOGDIR} ]; then |
| 632 | mkdir -p ${LOGDIR} |
| 633 | fi |
| 634 | # Backup log files |
| 635 | for log in ${LOGS}; do |
| 636 | if [ -f ${log} ]; then |
| 637 | rotate-log ${log} |
| 638 | fi |
| 639 | done |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 640 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 641 | if [ ! -f ${ONOS_LOGBACK} ]; then |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 642 | echo "[WARNING] ${ONOS_LOGBACK} not found." |
| 643 | echo " Run \"\$ $0 setup\" to create." |
| 644 | exit 1 |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 645 | fi |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 646 | |
Jonathan Hart | ef3dc1a | 2014-04-03 11:39:50 -0700 | [diff] [blame] | 647 | 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] | 648 | if [ "${ONOS_HOST_BACKEND}" = "ramcloud" ]; then |
| 649 | JVM_OPTS="${JVM_OPTS} -Dramcloud.config.path=${RAMCLOUD_CONF}" |
| 650 | fi |
| 651 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 652 | # Run ONOS |
Yuta HIGUCHI | cce4f62 | 2014-04-18 16:48:53 -0700 | [diff] [blame] | 653 | |
| 654 | # Need to cd ONOS_HOME. onos.properties currently specify hazelcast config path relative to CWD |
| 655 | cd ${ONOS_HOME} |
| 656 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 657 | echo -n "Starting ONOS controller ..." |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 658 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr & |
| 659 | |
| 660 | # We need to wait a bit to find out whether starting the ONOS process succeeded |
| 661 | sleep 1 |
| 662 | |
| 663 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 664 | if [ $n -ge 1 ]; then |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 665 | echo " STARTED" |
| 666 | else |
| 667 | echo " FAILED" |
| 668 | fi |
| 669 | |
| 670 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 671 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 672 | } |
| 673 | |
| 674 | function stop-onos { |
| 675 | kill-processes "ONOS controller" `jps -l | grep ${MAIN_CLASS} | awk '{print $1}'` |
| 676 | # kill-processes "tcpdump" `ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 677 | } |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 678 | ############################################ |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 679 | |
| 680 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 681 | ################## Main #################### |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 682 | case "$1" in |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 683 | setup) |
Naoki Shiota | 4e92851 | 2014-04-03 15:49:35 -0700 | [diff] [blame] | 684 | create-confs $2 |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 685 | ;; |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 686 | start) |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 687 | mode_parameter=${ONOS_HOST_ROLE} |
| 688 | if [ ! -z "$2" ]; then |
| 689 | mode_parameter=$2 |
| 690 | fi |
| 691 | |
| 692 | case "${mode_parameter}" in |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 693 | single-node) |
| 694 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 695 | start-backend coord |
| 696 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 697 | onos startifdown |
| 698 | ;; |
| 699 | coord-node) |
| 700 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 701 | start-backend coord |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 702 | onos startifdown |
| 703 | ;; |
| 704 | server-node) |
| 705 | zk start |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 706 | start-backend server |
| 707 | onos startifdown |
| 708 | ;; |
| 709 | coord-and-server-node) |
| 710 | zk start |
| 711 | start-backend coord |
| 712 | start-backend server |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 713 | onos startifdown |
| 714 | ;; |
| 715 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 716 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 717 | ;; |
| 718 | esac |
| 719 | echo |
| 720 | ;; |
| 721 | stop) |
| 722 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 723 | if [ $on != 0 ]; then |
| 724 | onos stop |
| 725 | fi |
| 726 | |
Naoki Shiota | 9df15d3 | 2014-03-27 14:26:20 -0700 | [diff] [blame] | 727 | stop-backend |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 728 | |
| 729 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 730 | if [ $zkn != 0 ]; then |
| 731 | zk stop |
| 732 | fi |
| 733 | echo |
| 734 | ;; |
| 735 | restart) |
| 736 | on=`jps -l | grep "${MAIN_CLASS}" | wc -l` |
| 737 | if [ $on != 0 ]; then |
| 738 | onos stop |
| 739 | fi |
| 740 | |
| 741 | rcsn=`pgrep -f obj.${RAMCLOUD_BRANCH}/server | wc -l` |
| 742 | if [ $rcsn != 0 ]; then |
| 743 | rc-server stop |
| 744 | fi |
| 745 | |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 746 | rccn=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 747 | if [ $rccn != 0 ]; then |
| 748 | rc-coord stop |
| 749 | fi |
| 750 | |
| 751 | zkn=`jps -l | grep org.apache.zookeeper.server | wc -l` |
| 752 | if [ $zkn != 0 ]; then |
| 753 | zk restart |
| 754 | fi |
| 755 | |
| 756 | if [ $rccn != 0 ]; then |
| 757 | rc-coord startifdown |
| 758 | fi |
| 759 | |
| 760 | if [ $rcsn != 0 ]; then |
| 761 | rc-server startifdown |
| 762 | fi |
| 763 | |
| 764 | if [ $on != 0 ]; then |
| 765 | onos startifdown |
| 766 | fi |
| 767 | echo |
| 768 | ;; |
| 769 | stat*) # <- status |
| 770 | echo '[ZooKeeper]' |
| 771 | zk status |
| 772 | echo |
| 773 | echo '[RAMCloud coordinator]' |
| 774 | rc-coord status |
| 775 | echo |
| 776 | echo '[RAMCloud server]' |
| 777 | rc-server status |
| 778 | echo |
| 779 | echo '[ONOS core]' |
| 780 | onos status |
| 781 | echo |
| 782 | ;; |
| 783 | zk) |
| 784 | zk $2 |
| 785 | ;; |
| 786 | rc-c*) # <- rc-coordinator |
| 787 | rc-coord $2 |
| 788 | ;; |
| 789 | rc-s*) # <- rc-server |
| 790 | rc-server $2 |
| 791 | ;; |
| 792 | core) |
| 793 | onos $2 |
| 794 | ;; |
| 795 | *) |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 796 | print_usage |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 797 | exit 1 |
| 798 | esac |
Naoki Shiota | 590c18d | 2014-03-31 17:52:59 -0700 | [diff] [blame] | 799 | |