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