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

 

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