Install JDK1.8/Tomcat8/Opengrok for Ubuntu 14.04

JDK1.8

使用openjdk的ppa源安装:

1
2
3
4
5
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java
sudo update-alternatives --config javac


Tomcat8

参考自 How to install apache tomcat 8 on ubuntu 14.04

创建 Tomcat 用户

  • First, create a new tomcat group:

    1
    sudo groupadd tomcat
  • Then create a new tomcat user:

    1
    sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

安装 Tomcat8

下载: Tomcat 8 Downloads page

1
2
sudo mkdir /opt/tomcat
sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

权限

chown给tomcat 然后chmod 775应该就可以了, 以下是原网页所给权限(我按照这个权限给tomcat起不来):

  • give the tomcat user write access to the conf directory, and read access to the files in that directory:

    1
    2
    cd /opt/tomcat
    sudo chgrp -R tomcat conf
  • make the tomcat user the owner of the work, temp, and logs directories:

    1
    2
    3
    sudo chmod g+rwx conf
    sudo chmod g+r conf/*
    sudo chown -R tomcat work/ temp/ logs/

启动脚本(upstart/service restart/…)

  • 编辑

    1
    sudo vim /etc/init/tomcat.conf
  • 添加内容:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    description "Tomcat Server"

    start on runlevel [2345]
    stop on runlevel [!2345]
    respawn
    respawn limit 10 5

    setuid tomcat
    setgid tomcat

    env JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
    env CATALINA_HOME=/opt/tomcat

    # Modify these options as needed
    env JAVA_OPTS="-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
    env CATALINA_OPTS="-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

    pre-start script
    exec > /tmp/finalx.debug.log 2>&1
    echo "this"
    end script

    script
    echo "env: $(env)"
    echo "whoami: $(id)"
    ls -l $CATALINA_HOME/bin/catalina.sh
    exec $CATALINA_HOME/bin/catalina.sh run
    echo "after $CATALINA_HOME/bin/catalina.sh"
    end script

    # cleanup temp directory after stop
    post-stop script
    rm -rf $CATALINA_HOME/temp/*
    end script
  • reload the Upstart configuration

    1
    2
    3
    4
    sudo initctl reload-configuration
    sudo initctl start tomcat
    # 本地测试:
    http://localhost:8080

Opengrok

  • 下载最新release: https://github.com/OpenGrok/OpenGrok/releases
  • 解压之后在tomcat的webapps里做个link到source.war, tomcat会自动解包并生成source目录:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    0  |pateo@15:39:15 /opt/tomcat/webapps>$ ls -l /opt/tomcat/webapps/
    total 24
    drwxr-xr-x 14 root root 4096 9月 26 17:33 docs
    drwxr-xr-x 6 root root 4096 9月 26 17:33 examples
    drwxr-xr-x 5 root root 4096 9月 26 17:33 host-manager
    drwxr-xr-x 5 root root 4096 9月 26 17:33 manager
    drwxr-xr-x 3 root root 4096 9月 26 17:33 ROOT
    drwxr-x--- 6 tomcat tomcat 4096 9月 28 11:32 source
    lrwxrwxrwx 1 root root 53 9月 28 11:32 source.war -> /home/pateo/bin/Grok/opengrok-1.1-rc14/lib/source.war
  • 修改opengrok脚本:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    0  |pateo@15:41:21 ~/bin/Grok/opengrok-1.1-rc14>$ git diff
    diff --git a/opengrok-1.1-rc14/bin/OpenGrok b/opengrok-1.1-rc14/bin/OpenGrok
    index 77fb65f..37d338d 100755
    --- a/opengrok-1.1-rc14/bin/OpenGrok
    +++ b/opengrok-1.1-rc14/bin/OpenGrok
    @@ -91,6 +91,9 @@
    # (*) Any Non-Empty String will enable these options
    #

    +#finalx
    +OPENGROK_WEBAPP_CFGADDR="none"
    +
    #
    # Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
    #
    @@ -335,7 +338,8 @@ DefaultInstanceConfiguration()
    fi

    # OPTIONAL: JVM Options
    - JAVA_OPTS="${JAVA_OPTS:--Xmx2048m}"
    + # finalx
    + JAVA_OPTS="${JAVA_OPTS:--Xmx4096m}"

    # OPTIONAL: Full Path to History Utilities
    BK="`Which bk`"
  • 创建opengrok 的目录并修改权限让当前user和tomcat都可以访问:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # $ sudo usermod -a -G tomcat pateo
    # logout and login
    # $ ls -l /var/ | grep opengrok
    # drwxr-xr-x 6 pateo tomcat 4096 9月 27 17:55 opengrok
    $ mkdir -p /var/opengrok
    $ cd /var/opengrok
    $ mkdir -p data etc log src
    $ ls -l
    drwxrwxr-x 4 pateo pateo 4096 9月 28 15:25 data
    drwxrwxr-x 2 pateo pateo 4096 9月 29 10:29 etc
    drwxrwxr-x 2 pateo pateo 4096 9月 28 21:03 log
    drwxrwxr-x 2 pateo pateo 4096 9月 28 17:28 src
  • 把working projects链接到opengrok的src中, 然后index(如果link的projects结构有变化, 或者第一次index完需要重启tomcat)

    1
    2
    3
    4
    5
    6
    7
    /var/opengrok/src>$ ls -l
    total 0
    lrwxrwxrwx 1 pateo pateo 47 9月 28 17:28 android-6.0.1_r79 -> /home/pateo/projects/readonly/android-6.0.1_r79
    lrwxrwxrwx 1 pateo pateo 32 9月 28 17:28 Project_XXX -> /home/pateo/projects/readonly/Project_XXX

    $ ~/bin/Grok/opengrok-1.1-rc14/bin/OpenGrok index
    #$ sudo service tomcat restart

在关掉history的情况下, index两个android project大约需要4小时

1
2
3
# To ignore skipping just the history cache creation for a particular
#directory and all of it's subdirectories, touch an empty
# .opengrok_skip_history file at the root of that directory