Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Set paths |
Masayoshi Kobayashi | 9d06fc5 | 2013-06-20 23:05:30 -0700 | [diff] [blame] | 4 | #ONOS_HOME=`dirname $0` |
| 5 | ONOS_HOME=${HOME}/ONOS |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 6 | ONOS_JAR="${ONOS_HOME}/target/floodlight.jar" |
| 7 | ONOS_ONLY_JAR="${ONOS_HOME}/target/floodlight-only.jar" |
| 8 | ONOS_LOGBACK="${ONOS_HOME}/logback.xml" |
| 9 | LOGDIR=${ONOS_HOME}/onos-logs |
| 10 | ONOS_LOG="${LOGDIR}/onos.`hostname`.log" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 11 | PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 12 | LOGS="$ONOS_LOG $PCAP_LOG" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 13 | |
| 14 | # Set JVM options |
| 15 | JVM_OPTS="" |
Jonathan Hart | f756278 | 2013-04-03 19:50:36 -0700 | [diff] [blame] | 16 | JVM_OPTS="$JVM_OPTS -server -d64" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 17 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 18 | JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m" |
| 19 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
| 20 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
Jonathan Hart | f756278 | 2013-04-03 19:50:36 -0700 | [diff] [blame] | 21 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 22 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 23 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 24 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 25 | |
| 26 | # Set classpath to include titan libs |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 27 | #CLASSPATH=`echo ${ONOS_HOME}/lib/*.jar ${ONOS_HOME}/lib/titan/*.jar | sed 's/ /:/g'` |
| 28 | CLASSPATH="${ONOS_ONLY_JAR}:${ONOS_HOME}/lib/*:${ONOS_HOME}/lib/titan/*" |
HIGUCHI Yuta | 49cf4d2 | 2013-06-17 12:15:17 -0700 | [diff] [blame] | 29 | MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 30 | |
HIGUCHI Yuta | 88f3bf3 | 2013-06-20 10:37:47 -0700 | [diff] [blame] | 31 | if [ -z "${MVN}" ]; then |
| 32 | MVN="mvn" |
| 33 | fi |
| 34 | |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 35 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 36 | #<appender-ref ref="STDOUT" /> |
| 37 | |
| 38 | function lotate { |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 39 | logfile=$1 |
| 40 | nr_max=${2:-10} |
| 41 | if [ -f $logfile ]; then |
| 42 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 43 | if [ -f ${logfile}.${i} ]; then |
| 44 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 45 | fi |
| 46 | done |
| 47 | mv $logfile $logfile.1 |
| 48 | fi |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | function start { |
| 52 | if [ ! -d ${LOGDIR} ]; then |
| 53 | mkdir -p ${LOGDIR} |
| 54 | fi |
| 55 | # Backup log files |
| 56 | for log in ${LOGS}; do |
| 57 | echo "rotate log: $log" |
| 58 | if [ -f ${log} ]; then |
| 59 | lotate ${log} |
| 60 | fi |
| 61 | done |
| 62 | |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 63 | # Create a logback file if required |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 64 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 65 | <configuration scan="true" debug="true"> |
| 66 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 67 | <encoder> |
| 68 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 69 | </encoder> |
| 70 | </appender> |
| 71 | |
| 72 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 73 | <file>${ONOS_LOG}</file> |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 74 | <encoder> |
| 75 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 76 | </encoder> |
| 77 | </appender> |
| 78 | |
| 79 | <logger name="org" level="WARN"/> |
| 80 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 81 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 82 | |
| 83 | <root level="DEBUG"> |
| 84 | <appender-ref ref="FILE" /> |
| 85 | </root> |
| 86 | </configuration> |
| 87 | EOF_LOGBACK |
| 88 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 89 | # Run floodlight |
| 90 | echo "Starting ONOS controller ..." |
| 91 | echo |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 92 | #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ${ONOS_HOME}/onos.properties > /dev/null 2>&1 & |
| 93 | #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${ONOS_HOME}/onos.properties > /dev/n |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 94 | |
Masayoshi Kobayashi | 9d06fc5 | 2013-06-20 23:05:30 -0700 | [diff] [blame] | 95 | # XXX : MVN has to run at the project top dir |
| 96 | cd ${ONOS_HOME} |
Masayoshi Kobayashi | a8e3835 | 2013-06-20 16:52:40 -0700 | [diff] [blame] | 97 | ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr & |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 98 | |
| 99 | echo "Waiting for ONOS to start..." |
| 100 | COUNT=0 |
| 101 | ESTATE=0 |
| 102 | while [ "$COUNT" != "10" ]; do |
| 103 | COUNT=$((COUNT + 1)) |
| 104 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 105 | if [ "$n" -ge "1" ]; then |
| 106 | exit 0 |
| 107 | fi |
| 108 | sleep $COUNT |
| 109 | done |
| 110 | echo "Timed out" |
| 111 | exit 1 |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 112 | |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 113 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
Masayoshi Kobayashi | 8849a66 | 2013-03-14 22:18:51 +0000 | [diff] [blame] | 114 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | function stop { |
| 118 | # Kill the existing processes |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 119 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 120 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 121 | pids="$flpid $tdpid" |
| 122 | for p in ${pids}; do |
| 123 | if [ x$p != "x" ]; then |
Pavlin Radoslavov | b531d71 | 2013-03-29 15:13:43 -0700 | [diff] [blame] | 124 | kill -KILL $p |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 125 | echo "Killed existing prosess (pid: $p)" |
| 126 | fi |
| 127 | done |
| 128 | } |
| 129 | |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 130 | function check_db { |
| 131 | if [ -d "/tmp/cassandra.titan" ]; then |
| 132 | echo "Cassandra is running on local berkely db. Exitting" |
| 133 | exit |
| 134 | fi |
| 135 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
Masayoshi Kobayashi | e772c7c | 2013-02-28 00:36:33 +0000 | [diff] [blame] | 136 | if [ x$n == "x0" ]; then |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 137 | echo "Cassandra is not running. Exitting" |
| 138 | exit |
| 139 | fi |
| 140 | } |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 141 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 142 | case "$1" in |
| 143 | start) |
| 144 | stop |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 145 | check_db |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 146 | start |
| 147 | ;; |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 148 | startifdown) |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 149 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 150 | if [ $n == 0 ]; then |
| 151 | start |
| 152 | else |
| 153 | echo "$n instance of onos running" |
| 154 | fi |
| 155 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 156 | stop) |
| 157 | stop |
| 158 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 159 | status) |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 160 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 161 | echo "$n instance of onos running" |
| 162 | ;; |
| 163 | *) |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 164 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 165 | exit 1 |
| 166 | esac |