Ticket #13089: 0001-Jetty-embedded.-Redundant-etc-logback.xml-removed.patch

File 0001-Jetty-embedded.-Redundant-etc-logback.xml-removed.patch, 15.1 KB (added by iwakeh, 5 years ago)

embedded jetty, some ant task, some logging

  • build.xml

    From 209e5f9ad6d9ea2d23453cfde5466bf7fd4a8138 Mon Sep 22 19:00:00 2014
    From: iwakeh <iwakeh@users.ourproject.org>
    Date: Mon, 22 Sep 2014 19:00:00 +0000
    Subject: [PATCH] Jetty embedded. Redundant etc/logback.xml removed.
    
    ---
     build.xml                                          | 107 ++++++++++++++++++---
     etc/logback.xml                                    |  57 -----------
     etc/onionoo-jetty.xml                              |  31 ++++++
     logback.xml                                        |  28 ++++--
     .../org/torproject/onionoo/server/ServerMain.java  |  33 +++++++
     5 files changed, 176 insertions(+), 80 deletions(-)
     delete mode 100644 etc/logback.xml
     create mode 100644 etc/onionoo-jetty.xml
     create mode 100644 src/main/java/org/torproject/onionoo/server/ServerMain.java
    
    diff --git a/build.xml b/build.xml
    index d6e1278..d01b409 100644
    a b  
    11<project default="run" name="onionoo" basedir=".">
     2  <property name="onionoo.protocol.version" value="1.1"/>
     3  <property name="releasejar.version" value="${onionoo.protocol.version}.1"/>
     4  <!-- to be discussed protomajor.protominor.server.api -->
     5  <property name="apijar.version" value="${releasejar.version}.1"/>
     6
    27  <property name="maxmemory.value" value="4g"/>
    38  <property name="javasources" value="src/main/java"/>
    49  <property name="tests" value="src/test/java"/>
    510  <property name="classes" value="classes"/>
     11  <property name="dist" value="dist"/>
    612  <property name="config" value="etc"/>
    713  <property name="webxmlfile" value="${config}/web.xml"/>
    814  <property name="contextxmltemplate"
     
    1117  <property name="webxmltemplate"
    1218            value="${config}/web.xml.template"/>
    1319  <property name="webxml" value="${config}/web.xml"/>
    14   <property name="warfile" value="onionoo.war"/>
     20  <property name="warfile" value="${dist}/onionoo-${releasejar.version}.war"/>
     21  <property name="jarfile" value="${dist}/onionoo-${releasejar.version}.jar"/>
    1522  <property name="source-and-target-java-version" value="1.7" />
    1623  <path id="classpath">
    1724    <pathelement path="${classes}"/>
     
    2229      <include name="gson-2.1.jar"/>
    2330      <include name="junit4-4.10.jar"/>
    2431      <include name="servlet-api-3.0.jar"/>
     32      <include name="jetty8-server-8.1.3.v20120416.jar"/>
     33      <include name="jetty8-servlet-8.1.3.v20120416.jar"/>
     34      <include name="jetty8-util-8.1.3.v20120416.jar"/>
     35      <include name="jetty8-http-8.1.3.v20120416.jar"/>
     36      <include name="jetty8-io-8.1.3.v20120416.jar"/>
     37      <include name="jetty8-xml-8.1.3.v20120416.jar"/>
     38      <include name="jetty8-webapp-8.1.3.v20120416.jar"/>
     39      <include name="jetty8-continuation-8.1.3.v20120416.jar"/>
     40      <include name="jetty8-security-8.1.3.v20120416.jar"/>
    2541      <include name="logback-classic-1.0.4.jar"/>
    2642      <include name="logback-core-1.0.4.jar"/>
    2743      <include name="slf4j-api-1.6.5.jar"/>
     
    3046      <include name="descriptor.jar"/>
    3147    </fileset>
    3248    <fileset dir="${config}">
    33       <include name="logback.xml"/>
     49      <include name="logback.xml,onionoo-jetty.xml"/>
    3450    </fileset>
    3551  </path>
    3652
     
    3854    <copy file="${contextxmltemplate}" tofile="${contextxml}"/>
    3955    <copy file="${webxmltemplate}" tofile="${webxml}"/>
    4056    <mkdir dir="${classes}"/>
     57    <mkdir dir="${dist}"/>
    4158  </target>
    4259
    4360  <target name="clean" >
    4461    <delete includeEmptyDirs="true">
    4562      <fileset dir="${classes}" defaultexcludes="false" includes="**" />
     63      <fileset dir="${dist}"  defaultexcludes="false" includes="**" />
    4664    </delete>
    47     <delete file="${warfile}"/>
    4865  </target>
    4966
    5067  <target name="metrics-lib">
     
    87104      </batchtest>
    88105    </junit>
    89106  </target>
     107
    90108  <target name="war"
    91109          depends="compile">
     110    <copy file="logback.xml" todir="${classes}" />
     111    <copy file="logback.xml" todir="${config}" />
    92112    <war destfile="${warfile}"
    93113         webxml="${webxmlfile}">
    94114      <fileset dir="web"/>
    95       <lib dir="deps/metrics-lib">
    96         <include name="descriptor.jar"/>
    97       </lib>
    98       <lib dir="/usr/share/java">
    99         <include name="slf4j-api-1.6.5.jar"/>
    100         <include name="logback-classic-1.0.4.jar"/>
    101         <include name="logback-core-1.0.4.jar"/>
    102         <include name="commons-codec-1.6.jar"/>
    103         <include name="commons-compress-1.4.1.jar"/>
    104         <include name="commons-lang-2.6.jar"/>
    105         <include name="gson-2.1.jar"/>
    106       </lib>
    107       <classes dir="${classes}"/>
     115      <zipgroupfileset dir="deps/metrics-lib">
     116        <include name="descriptor.jar"/>
     117      </zipgroupfileset>
     118      <zipgroupfileset dir="/usr/share/java">
     119        <include name="commons-codec-1.6.jar"/>
     120        <include name="commons-compress-1.4.1.jar"/>
     121        <include name="commons-lang-2.6.jar"/>
     122        <include name="gson-2.1.jar"/>
     123        <include name="junit4-4.10.jar"/>
     124        <include name="servlet-api-3.0.jar"/>
     125        <include name="jetty8-server-8.1.3.v20120416.jar"/>
     126        <include name="jetty8-servlet-8.1.3.v20120416.jar"/>
     127        <include name="jetty8-util-8.1.3.v20120416.jar"/>
     128        <include name="jetty8-http-8.1.3.v20120416.jar"/>
     129        <include name="jetty8-io-8.1.3.v20120416.jar"/>
     130        <include name="jetty8-xml-8.1.3.v20120416.jar"/>
     131        <include name="jetty8-webapp-8.1.3.v20120416.jar"/>
     132        <include name="jetty8-continuation-8.1.3.v20120416.jar"/>
     133        <include name="jetty8-security-8.1.3.v20120416.jar"/>
     134        <include name="logback-classic-1.0.4.jar"/>
     135        <include name="logback-core-1.0.4.jar"/>
     136        <include name="slf4j-api-1.6.5.jar"/>
     137      </zipgroupfileset>
     138
     139      <fileset dir="${classes}"
     140               includes="**/*" />   
     141      <fileset dir="${config}" includes="onionoo-jetty.xml" />   
     142
    108143      <zipfileset dir="${config}"
    109144                  prefix="WEB-INF/classes"
    110145                  includes="logback.xml"/>
    111146      <metainf dir="${config}"
    112147               includes="context.xml"/>
     148      <Manifest>
     149        <attribute name="Created-By" value="The Onionoo Project" />
     150        <attribute name="Implementation-Title" value="Onionoo Server"/>
     151        <attribute name="Implementation-Version" value="${releasejar.version}"/>
     152        <attribute name="Onionoo-Protocol-Version"
     153                   value="${onionoo.protocol.version}" />
     154        <attribute name="Main-Class" value="org.torproject.onionoo.server.ServerMain" />
     155       
     156    </Manifest>
    113157    </war>
    114158  </target>
     159
    115160  <target name="run" depends="compile">
    116161    <copy file="logback.xml" todir="${classes}" />
    117162    <java fork="true"
     
    120161      <classpath refid="classpath"/>
    121162    </java>
    122163  </target>
     164
     165  <target name="releasejar" depends="compile">
     166    <jar destfile="${jarfile}"
     167         basedir="${classes}">
     168
     169      <zipgroupfileset dir="/usr/share/java">
     170        <include name="commons-codec-1.6.jar"/>
     171        <include name="commons-compress-1.4.1.jar"/>
     172        <include name="commons-lang-2.6.jar"/>
     173        <include name="gson-2.1.jar"/>
     174        <include name="servlet-api-3.0.jar"/>
     175        <include name="logback-classic-1.0.4.jar"/>
     176        <include name="logback-core-1.0.4.jar"/>
     177        <include name="slf4j-api-1.6.5.jar"/>
     178      </zipgroupfileset>
     179      <zipgroupfileset dir="deps/metrics-lib">
     180        <include name="descriptor.jar"/>
     181      </zipgroupfileset>
     182
     183      <fileset dir="${classes}"
     184               excludes="org/torproject/onionoo/server/" />
     185      <fileset dir="${basedir}" includes="logback.xml" />
     186      <exclude name="**/Test*.class"/>
     187      <Manifest>
     188        <attribute name="Created-By" value="The Onionoo Project" />
     189        <attribute name="Implementation-Title" value="Onionoo Server"/>
     190        <attribute name="Implementation-Version" value="${releasejar.version}"/>
     191        <attribute name="Onionoo-Protocol-Version"
     192                   value="${onionoo.protocol.version}" />
     193        <attribute name="Main-Class" value="org.torproject.onionoo.cron.Main" />
     194    </Manifest>
     195  </jar>
     196  </target>
     197
     198
     199
     200
    123201</project>
    124202
  • deleted file etc/logback.xml

    diff --git a/etc/logback.xml b/etc/logback.xml
    deleted file mode 100644
    index 812c7c9..0000000
    + -  
    1 <configuration debug="false">
    2 
    3   <!-- don't forget the trailing slash! -->
    4   <property name="logfile-base" value="/var/log/tomcat6/" />
    5   <property name="utc-date-pattern" value="%date{yyyy-MM-dd HH:mm:ss, UTC}" />
    6 
    7   <appender name="FILEALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
    8     <file>${logfile-base}onionoo-all.log</file>
    9     <encoder>
    10       <pattern>${utc-date-pattern} %level %logger{25}:%line %msg%n</pattern>
    11     </encoder>
    12     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    13       <!-- rollover daily -->
    14       <FileNamePattern>${logfile-base}onionoo-all.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
    15       <maxHistory>10</maxHistory>
    16       <timeBasedFileNamingAndTriggeringPolicy
    17             class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
    18         <!-- or whenever the file size reaches 1MB -->
    19         <maxFileSize>1MB</maxFileSize>
    20       </timeBasedFileNamingAndTriggeringPolicy>
    21     </rollingPolicy>
    22   </appender>
    23 
    24   <appender name="FILEERR" class="ch.qos.logback.core.FileAppender">
    25     <file>${logfile-base}onionoo-err.log</file>
    26     <encoder>
    27       <pattern>%date %level %logger{30}(%line): %msg%n</pattern>
    28     </encoder>
    29     <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
    30       <level>ERROR</level>
    31     </filter>
    32   </appender>
    33   <appender name="FILESTATISTICS" class="ch.qos.logback.core.FileAppender">
    34     <file>${logfile-base}onionoo-statistics.log</file>
    35     <encoder>
    36       <pattern>${utc-date-pattern} %msg%n</pattern>
    37     </encoder>
    38     <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
    39       <level>INFO</level>
    40     </filter>
    41   </appender>
    42 
    43   <logger name="org.torproject" >
    44     <appender-ref ref="FILEERR" />
    45   </logger>
    46   <logger name="org.torproject.onionoo.server.PerformanceMetrics" >
    47     <appender-ref ref="FILESTATISTICS" />
    48   </logger>
    49   <logger name="statistics"  >
    50     <appender-ref ref="FILESTATISTICS" />
    51   </logger>
    52 
    53   <root level="ALL">
    54     <appender-ref ref="FILEALL" />
    55   </root>
    56 </configuration>
    57 
  • new file etc/onionoo-jetty.xml

    diff --git a/etc/onionoo-jetty.xml b/etc/onionoo-jetty.xml
    new file mode 100644
    index 0000000..cdf43f4
    - +  
     1<?xml version="1.0"?>
     2<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
     3  "http://www.eclipse.org/jetty/configure.dtd">
     4 
     5<Configure id="OnionooServer" class="org.eclipse.jetty.server.Server" >
     6  <Set name="dumpAfterStart">false</Set>
     7
     8  <Set name="ThreadPool">
     9    <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
     10      <Set name="minThreads">10</Set>
     11      <Set name="maxThreads">250</Set>
     12      <Set name="detailedDump">false</Set>
     13    </New>
     14  </Set>
     15
     16  <New id="onionoo" class="org.eclipse.jetty.webapp.WebAppContext">
     17    <Set name="logUrlOnStart">true</Set>
     18    <Set name="war">onionoo-1.1.1.war</Set>   
     19  </New>
     20
     21 <Call name="addConnector">
     22   <Arg>
     23     <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
     24       <Set name="port">8080</Set>
     25     </New>
     26   </Arg>
     27 </Call>
     28 <Set name="handler">
     29   <!-- maybe add more handlers (statistics, logging, etc.) later -->
     30   <New class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
     31     <Call name="addHandler">
     32       <Arg> 
     33         <Ref id="onionoo"/>
     34       </Arg>
     35     </Call>
     36   </New>
     37 </Set>
     38
     39</Configure>
  • logback.xml

    diff --git a/logback.xml b/logback.xml
    index f6d16d0..fd11f04 100644
    a b  
    11<configuration debug="false">
    22
    3   <!-- don't forget the trailing slash! -->
    4   <property name="logfile-base" value="/srv/onionoo.torproject.org/onionoo/" />
     3  <!-- a path and a prefix -->
     4  <property name="logfile-base" value="./onionoo-" />
     5
     6  <!-- log file names -->
     7  <property name="fileall-logname" value="${logfile-base}all" />
     8  <property name="fileerr-logname" value="${logfile-base}err" />
     9  <property name="filestatistics-logname" value="${logfile-base}statistics" />
     10
     11  <!-- date pattern -->
    512  <property name="utc-date-pattern" value="%date{yyyy-MM-dd HH:mm:ss, UTC}" />
    613
     14  <!-- appender section -->
    715  <appender name="FILEALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
    8     <file>${logfile-base}onionoo-all.log</file>
     16    <file>${fileall-logname}.log</file>
    917    <encoder>
    1018      <pattern>${utc-date-pattern} %level [runtime: %r] %logger{20}:%line %msg%n</pattern>
    1119    </encoder>
    1220    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    1321      <!-- rollover daily -->
    14       <FileNamePattern>${logfile-base}onionoo-all.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
     22      <FileNamePattern>${fileall-logname}.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
    1523      <maxHistory>10</maxHistory>
    1624      <timeBasedFileNamingAndTriggeringPolicy
    1725            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
     
    2230  </appender>
    2331
    2432  <appender name="FILEERR" class="ch.qos.logback.core.FileAppender">
    25     <file>${logfile-base}onionoo-err.log</file>
     33    <file>${fileerr-logname}.log</file>
    2634    <encoder>
    2735      <pattern>${utc-date-pattern} %level %logger{30}(%line): %msg%n</pattern>
    2836    </encoder>
     
    3442  </appender>
    3543
    3644  <appender name="FILESTATISTICS" class="ch.qos.logback.core.FileAppender">
    37     <file>${logfile-base}onionoo-statistics.log</file>
     45    <file>${filestatistics-logname}.log</file>
    3846    <encoder>
    3947      <pattern>${utc-date-pattern} [runtime: %r] %msg%n</pattern>
    4048    </encoder>
     
    4755    </filter>
    4856  </appender>
    4957
     58  <!-- logger section -->
    5059  <logger name="org.torproject" >
    5160    <appender-ref ref="FILEERR" />
    5261  </logger>
     62
    5363  <logger name="org.torproject.onionoo.cron.Main" >
    5464    <appender-ref ref="FILESTATISTICS" />
    5565  </logger>
    5666
    57   <!-- a named logger -->
     67  <logger name="org.torproject.onionoo.server.PerformanceMetrics" >
     68    <appender-ref ref="FILESTATISTICS" />
     69  </logger>
     70
    5871  <logger name="statistics" >
    5972    <appender-ref ref="FILESTATISTICS" />
    6073  </logger>
     
    6275  <root level="ALL">
    6376    <appender-ref ref="FILEALL" />
    6477  </root>
     78
    6579</configuration>
    6680
  • new file src/main/java/org/torproject/onionoo/server/ServerMain.java

    diff --git a/src/main/java/org/torproject/onionoo/server/ServerMain.java b/src/main/java/org/torproject/onionoo/server/ServerMain.java
    new file mode 100644
    index 0000000..4cdb1ab
    - +  
     1package org.torproject.onionoo.server;
     2
     3import org.eclipse.jetty.server.Server;
     4import org.eclipse.jetty.server.handler.ContextHandlerCollection;
     5import org.eclipse.jetty.server.handler.HandlerCollection;
     6import org.eclipse.jetty.servlet.ServletHandler;
     7import org.eclipse.jetty.util.resource.Resource;
     8import org.eclipse.jetty.webapp.WebAppContext;
     9import org.eclipse.jetty.xml.XmlConfiguration;
     10import org.slf4j.LoggerFactory;
     11
     12public class ServerMain {
     13
     14  private static final org.slf4j.Logger log = LoggerFactory
     15      .getLogger(ServerMain.class);
     16
     17  public static void main(String[] args) {
     18    Server server = null;
     19    try {
     20      Resource onionooXml = Resource.newSystemResource("onionoo-jetty.xml");
     21      log.info("Trying to read configuration ... " + onionooXml);
     22      XmlConfiguration configuration =
     23          new XmlConfiguration(onionooXml.getInputStream());
     24      server = (Server) configuration.configure();
     25      server.start();
     26      server.join();
     27    } catch (Exception ex) {
     28      log.error("Exiting, b/c of " + ex.getMessage(), ex);
     29      System.exit(1);
     30    }
     31  }
     32
     33}