opengrok搭建流程

前言:

https://github.com/oracle/opengrok/wiki/How-to-setup-OpenGrok

如上是官方文檔,照理話說一步一步走是沒有問題的,以下內容是針對我個人實際情況進行,親測可用

1、下載opengrok

從github下載:https://github.com/OpenGrok/OpenGrok/releases

我使用的1.3.7版本,下載路徑:https://github.com/oracle/opengrok/releases/download/1.3.7/opengrok-1.3.7.tar.gz

2、下載tomcat

從官網下載:https://tomcat.apache.org/download-80.cgi

我使用的tomcat 8

3、安裝Universal Ctags

安裝編譯需要的工具:sudo apt install pkgconf autoconf

下載源碼:git clone https://github.com/universal-ctags/ctags.git,或通過github網頁下載不含git庫的代碼亦可;

依次執行如下指令,其中<$ctagInstallPath>爲任意指定路徑,若未指定,默認安裝在/usr/local下(make install時需root權限)

./autogen.sh
./configure --prefix=<$ctagInstallPath>
make
make install

4、部署tomcat

Ubuntu系統如果默認安裝了openjdk,其實是不用配置環境變量的,解壓(設解壓後路徑爲<$tomcatPath>)以後直接運行<$tomcatPath>/bin/startup.sh即可;

使用瀏覽器輸入網址localhost:8080驗證tomcat是否正常運行;

將opengrok解壓(設解壓後路徑爲<$opengrokPath>),的<$opengrokPath>/lib/source.war複製到<$tomcatPath>/webapps/下(我在此重命名爲了opengrok.war,這樣對應的網頁地址就會變成localhost:8080/opengrok)

待tomcat將war包解壓後,在瀏覽器中輸入localhost:8080/<$warfileName>查看,此時應該會告知你缺少configuration.xml,此屬於正常現象,configuration.xml會在做完索引後生成;

5、創建index

創建腳本opengrok_index.sh:

#!/bin/bash

opengrok_path="<$opengrokPath>"
source_root="<$sourcePath>"
indexing_root="<$indexPath>"
ctags_root="<$ctagInstallPath>"

# 1. create index dir
if [ !-d ${indexing_root}/ ];then
    mkdir -p ${indexing_root}
fi

# 2. export the OpenGrok environment variables                                                                                                                                                                       
export OPENGROK_TOMCAT_BASE=<$tomcatPath>
export OPENGROK_INSTANCE_BASE=opengrok
export JAVA_OPTS="-Xmx2048m"

# 3. update code base
cd ${source_root}
git reset --hard HEAD
git clean -fd ./
cd -

# java -jar ${opengrok_path}/lib/opengrok.jar for command help                                                                                                                                                       
java $JAVA_OPTS -d64 -jar ${opengrok_path}/lib/opengrok.jar
-P \
-H \
-S \
-G \
-v \
-c ${ctags_root} \
-s ${source_root} \
-d ${indexing_root} \
-U http://localhost:8080/opengrok \
-W ${indexing_root}/configuration.xml \

執行該腳本,等待一段時間,此時可以記住${indexing_root}/configuration.xml這個路徑,下一步要用

待index創建完畢後,打開<$tomcatPath>/webapps/opengrok/WEB-INF/web.xml(若未修改source.war,請替換opengrok爲source,若修改爲了其他名字,以此類推)

修改<param-name>CONFIGURATION</param-name>下方對應<param-value>爲${indexing_root}/configuration.xml

    <display-name>OpenGrok</display-name>
    <description>A wicked fast source browser</description>
    <context-param>
        <description>Full path to the configuration file where OpenGrok can read its configuration</description>
        <param-name>CONFIGURATION</param-name>
        <param-value>${indexing_root}/configuration.xml</param-value>
    </context-param>

再次打開localhost:8080/opengrok查看,應該是可以用了;

6、創建定時任務

使用crontab創建定時任務;

新建一個opengrok.cron文件,並按照格式寫入定時規則以及需要執行的腳本,此處需要執行的腳本即爲第5步的opengrok_index.sh:


0 4 * * * /<$pathTo>/opengrok_index.sh

注意每個字段用空格隔開,crontab格式及更多用法可參考http://www.tracefact.net/tech/080.html,此處設置的意思是每天凌晨4:00執行一次opengrok_index.sh;

然後執行指令添加:

contab opengrok.cron

添加成功後課通過如下指令查看是否添加成功:

$ crontab -l
0 4 * * * /<$pathTo>/opengrok_index.sh

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章