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