Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Set paths |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 4 | ONOS_HOME=`dirname $0` |
| 5 | ONOS_JAR="${ONOS_HOME}/target/floodlight.jar" |
| 6 | ONOS_ONLY_JAR="${ONOS_HOME}/target/floodlight-only.jar" |
| 7 | ONOS_LOGBACK="${ONOS_HOME}/logback.xml" |
| 8 | LOGDIR=${ONOS_HOME}/onos-logs |
| 9 | ONOS_LOG="${LOGDIR}/onos.`hostname`.log" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 10 | PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap" |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 11 | LOGS="$ONOS_LOG $PCAP_LOG" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 12 | |
| 13 | # Set JVM options |
| 14 | JVM_OPTS="" |
| 15 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 16 | JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 17 | JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
| 18 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 19 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \ |
| 20 | -Dcom.sun.management.jmxremote.port=7199 \ |
| 21 | -Dcom.sun.management.jmxremote.ssl=false \ |
| 22 | -Dcom.sun.management.jmxremote.authenticate=false" |
| 23 | |
| 24 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 25 | |
| 26 | # Set classpath to include titan libs |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -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" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [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 |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 34 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
| 35 | #<appender-ref ref="STDOUT" /> |
| 36 | |
| 37 | function lotate { |
| 38 | logfile=$1 |
| 39 | nr_max=${2:-10} |
| 40 | if [ -f $logfile ]; then |
| 41 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 42 | if [ -f ${logfile}.${i} ]; then |
| 43 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 44 | fi |
| 45 | done |
| 46 | mv $logfile $logfile.1 |
| 47 | fi |
| 48 | } |
| 49 | |
| 50 | function start { |
| 51 | if [ ! -d ${LOGDIR} ]; then |
| 52 | mkdir -p ${LOGDIR} |
| 53 | fi |
| 54 | # Backup log files |
| 55 | for log in ${LOGS}; do |
| 56 | echo "rotate log: $log" |
| 57 | if [ -f ${log} ]; then |
| 58 | lotate ${log} |
| 59 | fi |
| 60 | done |
| 61 | |
| 62 | # Create a logback file if required |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 63 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 64 | <configuration scan="true" debug="true"> |
| 65 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 66 | <encoder> |
| 67 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 68 | </encoder> |
| 69 | </appender> |
| 70 | |
| 71 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 72 | <file>${ONOS_LOG}</file> |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 73 | <encoder> |
| 74 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 75 | </encoder> |
| 76 | </appender> |
| 77 | |
| 78 | <logger name="org" level="WARN"/> |
| 79 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 80 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 81 | |
| 82 | <root level="DEBUG"> |
| 83 | <appender-ref ref="FILE" /> |
| 84 | </root> |
| 85 | </configuration> |
| 86 | EOF_LOGBACK |
| 87 | |
| 88 | # Run floodlight |
| 89 | echo "Starting ONOS controller ..." |
| 90 | echo |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 91 | #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ${ONOS_HOME}/onos.properties > /dev/null 2>&1 & |
| 92 | #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${ONOS_HOME}/onos.properties > /dev/n |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 93 | |
Masayoshi Kobayashi | a8e3835 | 2013-06-20 16:52:40 -0700 | [diff] [blame] | 94 | ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos-embedded.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr & |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 95 | |
| 96 | echo "Waiting for ONOS to start..." |
| 97 | COUNT=0 |
| 98 | ESTATE=0 |
| 99 | while [ "$COUNT" != "10" ]; do |
| 100 | COUNT=$((COUNT + 1)) |
| 101 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 102 | if [ "$n" -ge "1" ]; then |
| 103 | exit 0 |
| 104 | fi |
| 105 | sleep $COUNT |
| 106 | done |
| 107 | echo "Timed out" |
| 108 | exit 1 |
| 109 | |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 110 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 111 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 112 | } |
| 113 | |
| 114 | function stop { |
| 115 | # Kill the existing processes |
| 116 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
| 117 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 118 | pids="$flpid $tdpid" |
| 119 | for p in ${pids}; do |
| 120 | if [ x$p != "x" ]; then |
| 121 | kill -KILL $p |
| 122 | echo "Killed existing prosess (pid: $p)" |
| 123 | fi |
| 124 | done |
| 125 | } |
| 126 | |
| 127 | function deldb { |
| 128 | # Delete the cassandra data |
| 129 | if [ -d "/tmp/cassandra" ]; then |
| 130 | rm -rf /tmp/cassandra/* |
| 131 | fi |
| 132 | } |
| 133 | |
| 134 | case "$1" in |
| 135 | start) |
| 136 | stop |
| 137 | start |
| 138 | ;; |
| 139 | startifdown) |
| 140 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 141 | if [ $n == 0 ]; then |
| 142 | start |
| 143 | else |
| 144 | echo "$n instance of onos running" |
| 145 | fi |
| 146 | ;; |
| 147 | stop) |
| 148 | stop |
| 149 | ;; |
| 150 | deldb) |
| 151 | deldb |
| 152 | ;; |
| 153 | status) |
| 154 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 155 | echo "$n instance of onos running" |
| 156 | ;; |
| 157 | *) |
| 158 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
| 159 | exit 1 |
| 160 | esac |