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