OpenGrok是一个快速、便于使用的源代码搜索与对照引擎。它帮助你搜索,对照,定位你的源代码树。它能够识别各种程序源文件格式和版本控制历史记录。
搭建环境依赖:
1.opengrok-1.1-rc33.tar.gz PS:rc35后脚本开始从shell切换到python
2.universal-ctags
3.apache-tomcat-8.5.32
4.OpenJDK 1.8
1.OpenJDK 1.8安装
参考https://blog.csdn.net/dgj8300/article/details/81625992进行安装,安装完成后,执行java -version进行版本查询
Desktop-System:~/ctags/ctags-master$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2~14.04-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
Desktop-System:~/ctags/ctags-master$
2.universal-ctags安装
在https://github.com/universal-ctags/ctags下载压缩包ctags-master.zip,放到linux下:
apt-get install install autoconf automake libtool pkg-config
zip ctags-master.zip
cd ctags-master/
./autogen.sh
./configure --prefix=/where/you/want # defaults to /usr/local
Make
sudo make install # may require extra privileges depending on where to install
Desktop-System:~/ctags/ctags-master$ ctags --help
Universal Ctags 0.0.0, Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Aug 10 2018, 15:44:23
URL: https://ctags.io/
Optional compiled features: +wildcards, +regex, +iconv, +option-directory
//最后将生成的目标文件copy到 /usr/local/bin/:
cp /opt/ctags/bin/* /usr/local/bin/
3.apache-tomcat-8.5.32安装
参考:https://blog.csdn.net/gatieme/article/details/53073548
下载网站:http://tomcat.apache.org/download-80.cgi
manager配置:https://blog.csdn.net/u012326462/article/details/81038660
https://www.cnblogs.com/centos2017/p/9257593.html
登陆权限设置/开机启动/错误处理:https://blog.csdn.net/dgj8300/article/details/85064718
注意java环境的添加,需要在/opt/apache-tomcat/bin下:
vi setclasspath.sh
#---------------------
# java path
#---------------------
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 #根据个人openjdk环境进行配置
JRE_HOME=$JAVA_HOME/jre
JAVA_BIN=$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
#PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASSPATH
4.opengrok-1.1-rc33 安装
从https://github.com/oracle/opengrok/releases下载
opengrok-1.1-rc33.tar.gz,放到/opt/目录下,
tar xzvf opengrok-1.1-rc33.tar.gz /opt/
mv opengrok-0.11.1 opengrok
cd opengrok/bin/
vi opengrok.py
需要支持多项目,本人对OpenGrok脚本进行了修改,修改如下(以版本opengrok-1.1-rc33为例):
主要修改了缓存的位置以及生成项目文件时的路径,这样修改,对于多项目方便管控。
#!/bin/sh
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# See LICENSE.txt included in this distribution for the specific
# language governing permissions and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at LICENSE.txt.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
# Portions Copyright (c) 2017-2018, Chris Fraire .
#
#
# opengrok.jar wrapper for initial setup and cron job updating.
# Please see the Usage() function below for supported environment variables.
#
#
# Print usage to stdout and exit.
#
#增加tomcat安装路径到环境变量OPENGROK_WAR_TARGET_TOMCAT
export OPENGROK_WAR_TARGET_TOMCAT=/opt/apache-tomcat
Usage()
{
progname=`basename $0`
exec >&2
echo ""
echo "Usage: ${progname} "
echo " ${progname} index []"
echo " ${progname} indexpart [ ..]"
echo " ${progname} clearHistory "
echo " ${progname} usage|help [--detailed]"
echo ""
echo " The \"indexpart\" assumes that it will be run with configuration"
echo " pointed to via the OPENGROK_READ_XML_CONFIGURATION environment"
echo " variable."
echo ""
if [ "$1" != "--detailed" ]; then
echo " Optional environment variables:"
echo " OPENGROK_CONFIGURATION - location of your configuration"
echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf \\"
echo " ${0} ... "
echo ""
echo " Use help --detailed, or see the code for more information on"
echo " configuration options and variables."
else
cat < inputFile [inputFile ...] outputFile
# EftarFile == An Extremely Fast Tagged Attribute Read-only File System
EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
# HARDCODED: Generated EftarFile (See web/*.jsp)
EFTAR_OUTPUT_FILE="${DATA_ROOT}/index/dtags.eftar"
# Be Quiet? (set indirectly by command line arguments in the main program)
#QUIET=""
# or alternatively, Be Verbose!
#VERBOSE="-v"
if [ -n "${OPENGROK_VERBOSE}" ]
then
VERBOSE="-v"
QUIET=""
fi
if [ -n "${OPENGROK_PROGRESS}" ]
then
PROGRESS="--progress"
fi
if [ "$OPENGROK_ASSIGNMENTS" != "" ]; then
ASSIGNMENTS="`echo $OPENGROK_ASSIGNMENTS | sed 's/[:space:]+/_/g'`"
ASSIGNMENTS="-A `echo $ASSIGNMENTS | sed 's/,/ -A /g'`"
fi
if [ -f "${XML_CONFIGURATION}" ]; then
CHK_INDEX_CONF="${XML_CONFIGURATION}"
fi
}
#
# Helper Functions - Logging
#
# In general, non-interactive use like cron jobs and automated
# installation environments should not generate unnecessary
# progress information or warnings, as usage and configuration
# will have generally been debugged prior to automation.
#
Progress()
{
if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
then
echo "${@}"
fi
}
Warning()
{
if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
then
echo "WARNING: ${@}" 1>&2
fi
}
Error()
{
echo "ERROR: ${@}" 1>&2
}
FatalError()
{
exec >&2
echo ""
echo "FATAL ERROR: ${@} - Aborting!"
echo ""
${DO} exit 2
}
#
# Helper Functions - Autodetection of Runtime Environment
#
Which()
{
path="`which ${1} 2>/dev/null`"
if [ -x "${path}" ]
then
echo "${path}"
fi
}
LocateBinary() {
for f in $@
do
file=`which "$f" 2>/dev/null | grep -v '^no '`
if test -n "$file" -a -x "$file"
then
echo $file
return 0
fi
done
echo ""
return 1
}
FindCtags()
{
#
# Search for Exuberant ctags intelligently, skipping
# over other ctags implementations.
#
binary=""
found=0
for program in ctags-exuberant exctags ctags; do
for path in `echo $PATH | tr ':' '\n'`; do
if [ -x "$path/$program" ]; then
binary="$path/$program"
# Verify that this tool is or is based on Exuberant Ctags.
$binary --version 2>&1 | grep "Exuberant Ctags" > /dev/null
if [ $? -eq 0 ]; then
found=1
break
fi
fi
done
if [ $found -eq 1 ]; then
break;
fi
done
if [ $found -ne 1 ]; then
Error "Unable to determine Exuberant/Universal CTags command name" \
"for ${OS_NAME} ${OS_VERSION}"
return
fi
echo ${binary}
}
FindJavaHome()
{
javaHome=""
case "${OS_NAME}:${OS_VERSION}" in
SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.7.0" ;;
SunOS:5.11) javaHome="/usr/jdk/latest" ;;
SunOS:5.12) javaHome="/usr/jdk/latest" ;;
Darwin:*) javaHome=`/usr/libexec/java_home` ;;
Linux:*)
if [ -f /etc/alternatives/java ]
then
javaHome=`ls -l /etc/alternatives/java | cut -f 2 -d \> `
javaHome=`dirname $javaHome`
javaHome=`dirname $javaHome`
fi
;;
esac
if [ -z "${javaHome}" ]
then
Error "Unable to determine Java 7 Home" \
"for ${OS_NAME} ${OS_VERSION}"
return
fi
if [ ! -d "${javaHome}" ]
then
Error "Missing Java Home ${javaHome}"
return
fi
echo "${javaHome}"
}
FindApplicationServerType()
{
# Use this function to determine which environment the deploy the
# web application function into. Some users (especially
# developers) will have many deployment environments or will wish
# to specify directly the application server to deploy to.
# Either use the environment variable OPENGROK_APP_SERVER or
# reimplement this function in your configuration file (as
# specified by OPENGROK_CONFIGURATION)
if [ -n "${OPENGROK_APP_SERVER}" ]
then
echo "${OPENGROK_APP_SERVER}"
return
fi
# This implementation favours Tomcat, but needs a lot of work,
# especially if Glassfish is preferred or it is under the control
# of SMF (Service Management Facility)
# Maybe a better implementation would be to call Application
# Server specific WAR Directory and see if they exist.
if [ -d "/var/tomcat8/webapps" \
-o -d "/var/lib/tomcat8/webapps" \
]
then
echo "Tomcat"
return
fi
if [ -x "/etc/init.d/appserv" -a -d "/var/appserver/domains" ]
then
echo "Glassfish"
return
fi
if [ -d "/etc/resin" -o -d "/usr/local/share/resin" ]
then
echo "Resin"
return
fi
# Assume Tomcat
echo "Tomcat"
}
DetermineWarDirectoryTomcat()
{
if [ -n "${OPENGROK_WAR_TARGET_TOMCAT}" ]
then
echo "${OPENGROK_WAR_TARGET_TOMCAT}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_TOMCAT_BASE} \
/var/lib/tomcat8 \
/var/tomcat8
do
if [ -d "${prefix}/webapps" ]
then
echo "${prefix}/webapps"
return
fi
done
}
DetermineWarDirectoryGlassfish()
{
if [ -n "${OPENGROK_WAR_TARGET_GLASSFISH}" ]
then
echo "${OPENGROK_WAR_TARGET_GLASSFISH}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_GLASSFISH_BASE} \
/var/appserver
do
if [ -d "${prefix}/domains" ]
then
if [ -z "${domainDirectory}" ]
then
domainDirectory="${prefix}/domains"
fi
fi
done
if [ -z "${domainDirectory}" ]
then
return
fi
# User Specified Domain
if [ -n "${OPENGROK_GLASSFISH_DOMAIN}" ]
then
directory="${domainDirectory}/${OPENGROK_GLASSFISH_DOMAIN}/autodeploy"
if [ ! -d "${directory}" ]
then
FatalError "Missing Specified Glassfish Domain " \
"${OPENGROK_GLASSFISH_DOMAIN}"
fi
echo "${directory}"
return
fi
# Arbitrary Domain Selection
firstDomain=`ls -1 ${domainDirectory} | head -1`
if [ -z "${firstDomain}" ]
then
FatalError "Failed to dynamically determine Glassfish Domain from " \
"${domainDirectory}"
fi
echo "${domainDirectory}/${firstDomain}/autodeploy"
}
DetermineWarDirectoryResin()
{
if [ -n "${OPENGROK_WAR_TARGET_RESIN}" ]
then
echo "${OPENGROK_WAR_TARGET_RESIN}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_RESIN_BASE} \
/var/resin \
/opt/resin
do
if [ -d "${prefix}/webapps" ]
then
echo "${prefix}/webapps"
return
fi
done
}
#
# Implementation
#
# The variable "DO" can usefully be set to "echo" to aid in script debugging
#
LoadStandardEnvironment()
{
# Setup a standard execution environment (if required)
cronexec="/pkgs/sbin/CronExecutionEnvironment.sh"
OPENGROK_STANDARD_ENV="${OPENGROK_STANDARD_ENV:-$cronexec}"
if [ -f "${OPENGROK_STANDARD_ENV}" ]
then
Progress "Loading ${OPENGROK_STANDARD_ENV} ..."
. "${OPENGROK_STANDARD_ENV}"
fi
}
#
# Load custom configuration and then fill remaining stuff with defaults.
#
LoadInstanceConfiguration()
{
#
# Note: As all functions have been defined by the time this routine
# is called, your configuration can, if desired, override functions
# in addition to setting the variables mentioned in the function
# DefaultInstanceConfiguration(), this maybe useful to override
# functionality used to determine the default deployment environment
# find dependencies or validate the configuration, for example.
#
if [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
then
# Load the Local OpenGrok Configuration Environment
Progress "Loading ${OPENGROK_CONFIGURATION} ..."
. "${OPENGROK_CONFIGURATION}"
fi
Progress "Loading the default instance configuration ..."
DefaultInstanceConfiguration
}
ValidateConfiguration()
{
if [ ! -x "${OPENGROK_CTAGS}" ]
then
FatalError "Missing Dependent Application - Exuberant/Universal CTags"
fi
if [ ! -d "${SRC_ROOT}" ]
then
FatalError "OpenGrok Source Path ${SRC_ROOT} doesn't exist"
fi
if [ -n "${QUIET}" -a -n "${VERBOSE}" ]
then
Warning "Both Quiet and Verbose Mode Enabled - Choosing Verbose"
QUIET=""
VERBOSE="-v"
fi
}
CreateRuntimeRequirements()
{
if [ ! -d "${DATA_ROOT}" ]
then
Warning "OpenGrok generated data path ${DATA_ROOT} doesn't exist"
Progress " Attempting to create generated data directory ... "
${DO} mkdir -p "${DATA_ROOT}"
fi
if [ ! -d "${DATA_ROOT}" ]
then
FatalError "OpenGrok data path ${DATA_ROOT} doesn't exist"
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
Warning "OpenGrok generated etc path ${OPENGROK_INSTANCE_BASE}/etc " \
"doesn't exist"
Progress " Attempting to create generated etc directory ... "
${DO} mkdir -p "${OPENGROK_INSTANCE_BASE}/etc"
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
FatalError "OpenGrok etc path ${OPENGROK_INSTANCE_BASE}/etc " \
"doesn't exist"
fi
if [ -n "${LOGGER_CONFIG_PATH}" -a ! -f "${LOGGER_CONFIG_PATH}" ]
then
Progress " Creating default ${LOGGER_CONFIG_PATH} ... "
if [ ! -f "${LOGGER_CONF_SOURCE}" ]
then
Warning "Can't find distribution logging configuration" \
"(${LOGGER_CONF_SOURCE}) to install as default" \
"logging configuration (${LOGGER_CONFIG_PATH})"
else
filename="opengrok%g.%u.log"
fullpath="${OPENGROK_INSTANCE_BASE}/log/opengrok%g.%u.log"
${DO} grep -v java.util.logging.FileHandler.pattern \
"${LOGGER_CONF_SOURCE}" > "${LOGGER_CONFIG_PATH}"
${DO} grep java.util.logging.FileHandler.pattern \
"${LOGGER_CONF_SOURCE}" | \
sed "s|$filename|$fullpath|g" >> "${LOGGER_CONFIG_PATH}"
if [ ! -d ${OPENGROK_INSTANCE_BASE}/log ]
then
${DO} mkdir ${OPENGROK_INSTANCE_BASE}/log
fi
fi
fi
}
MinimalInvocation()
{
${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
${JAVA_DEBUG} \
${LOGGER_PROPERTIES} \
-jar "${OPENGROK_JAR}" \
${VERBOSE} ${QUIET} \
"${@}"
}
CommonInvocation()
{
MinimalInvocation \
${OPENGROK_IGNORE_PATTERNS} \
${HISTORY_TAGS} \
${GENERATE_HISTORY} \
${RENAMED_FILES_HISTORY} \
${SCAN_DEPTH} \
${PROGRESS} \
${OPENGROK_LOCKING:+--lock} ${OPENGROK_LOCKING} \
${OPENGROK_CTAGS:+-c} ${OPENGROK_CTAGS} \
${OPENGROK_MANDOC:+--mandoc} ${OPENGROK_MANDOC} \
${CTAGS_OPTIONS_FILE:+-o} ${CTAGS_OPTIONS_FILE} \
${OPENGROK_FLUSH_RAM_BUFFER_SIZE} ${SKIN} ${LEADING_WILDCARD} \
${OPENGROK_PARALLELISM:+--threads} ${OPENGROK_PARALLELISM} \
${ASSIGNMENTS} \
${READ_XML_CONF} \
${WEBAPP_CONFIG} \
${CHK_INDEX_CONF:+--checkIndexVersion} ${CHK_INDEX_CONF} \
${OPENGROK_PROFILER:+--profiler} \
"${@}"
}
StdInvocation()
{
CommonInvocation \
-W "${XML_CONFIGURATION}" \
${SCAN_FOR_REPOSITORY} \
${ENABLE_PROJECTS} \
${DEFAULT_PROJECTS} \
-s "${SRC_ROOT}" \
-d "${DATA_ROOT}" \
"${@}"
}
UpdateGeneratedData()
{
StdInvocation
}
UpdateDataPartial()
{
extra_args=""
for arg in "$@"; do
if [ -n "$extra_args" ]; then
extra_args="$extra_args -H $arg"
else
extra_args="-H $arg"
fi
done
CommonInvocation $extra_args "$@"
}
UpdateDescriptionCache()
{
# OPTIONAL : Update the EftarFile data
if [ -n "${PATH_DESC}" -a -s "${PATH_DESC}" ]
then
${DO} ${JAVA} -classpath "${OPENGROK_JAR}" \
${EFTAR_UPDATE} "${PATH_DESC}" "${EFTAR_OUTPUT_FILE}"
fi
}
OpenGrokUsage()
{
[ "$1" = "--detailed" ] && helpargs=$1
echo "Options for opengrok.jar:" 1>&2
${DO} ${JAVA} ${JAVA_OPTS} -jar "${OPENGROK_JAR}" '-?' $helpargs
}
DeployWar()
{
applicationServer="`FindApplicationServerType`"
case "${applicationServer}" in
Tomcat) warTarget="`DetermineWarDirectoryTomcat`" ;;
Glassfish) warTarget="`DetermineWarDirectoryGlassfish`" ;;
Resin) warTarget="`DetermineWarDirectoryResin`" ;;
*) FatalError "Unsupported Application Server ${applicationServer}" ;;
esac
if [ -z "${warTarget}" ]
then
FatalError "Unable to determine Deployment Directory for " \
"${applicationServer}"
fi
if [ ! -f "${OPENGROK_DIST_WAR}" ]
then
FatalError "Missing Web Application Archive ${OPENGROK_DIST_WAR}"
fi
if [ ! -d "${warTarget}" ]
then
FatalError "Missing Deployment Directory ${warTarget}"
fi
APP_CONTEXT="${WAR_NAME}" #以${WAR_NAME}命名
FINAL_WAR_NAME="${WAR_NAME}" #以${WAR_NAME}命名
if [ "$applicationServer" = "Tomcat" ]
then
if [ ! -z ${OPENGROK_WEBAPP_CONTEXT+x} ] # OPENGROK_WEBAPP_CONTEXT is set
then
APP_CONTEXT="${OPENGROK_WEBAPP_CONTEXT}"
# strip leading /
case ${APP_CONTEXT} in
/*) APP_CONTEXT=`echo ${APP_CONTEXT} | sed 's|^/||'`
esac
FINAL_WAR_NAME=`echo ${APP_CONTEXT} | sed 's|/|#|g'`
if [ -z "${FINAL_WAR_NAME}" ]
then
FINAL_WAR_NAME="ROOT"
fi
fi
fi
Progress "Installing ${OPENGROK_DIST_WAR} to ${warTarget} ..."
#复制*.war到tomcat路径下的webapps目录下
sudo cp -p "${OPENGROK_DIST_WAR}" "${warTarget}/webapps/${FINAL_WAR_NAME}.war"
if [ $? != 0 ]
then
FatalError "Web Application Installation FAILED"
fi
# If user does not use default OPENGROK_INSTANCE_BASE then attempt to
# extract WEB-INF/web.xml from source.war using jar or zip utility, update
# the hardcoded values and then update source.war with the new
# WEB-INF/web.xml.
if [ "${OPENGROK_INSTANCE_BASE}" != '/var/opengrok' ]
then
EXTRACT_COMMAND=""
COMPRESS_COMMAND=""
if [ -n "`Which jar`" ]
then
EXTRACT_COMMAND="jar -xf"
COMPRESS_COMMAND="jar -uf"
elif [ -n "`Which zip`" ] && [ -n "`Which unzip`" ]
then
EXTRACT_COMMAND="unzip"
COMPRESS_COMMAND="zip -rf"
fi
if [ -n "${EXTRACT_COMMAND}" ]
then
#打开复制的*.war目录,进行解压,并替换XML_CONFIGURATION项,再压缩
cd "${warTarget}/webapps"
eval "${EXTRACT_COMMAND} ${warTarget}/webapps/${FINAL_WAR_NAME}.war WEB-INF/web.xml"
if [ "${OPENGROK_INSTANCE_BASE}" != '/var/opengrok' ]
then
sed -e 's:/var/opengrok/etc/configuration.xml:'"$XML_CONFIGURATION"':g' \
"${warTarget}/webapps/WEB-INF/web.xml" \
> "${warTarget}/webapps/WEB-INF/web.xml.tmp"
mv "${warTarget}/webapps/WEB-INF/web.xml.tmp" \
"${warTarget}/webapps/WEB-INF/web.xml"
fi
eval "${COMPRESS_COMMAND} ${warTarget}/webapps/${FINAL_WAR_NAME}.war WEB-INF/web.xml"
rm -rf "${warTarget}/WEB-INF"
fi
fi
Progress
Progress "Start your application server (${applicationServer}), " \
"if it is not already"
Progress "running, or wait until it loads the just installed web " \
"application."
Progress
Progress "OpenGrok should be available on :/${APP_CONTEXT}"
Progress " where HOST and PORT are configured in ${applicationServer}."
Progress
}
#
# Clear history index for given project.
#
ClearHistory()
{
Progress "Removing history index data for repository ${1}"
MinimalInvocation -s "${SRC_ROOT}" -d "${DATA_ROOT}" --deleteHistory "${1}"
}
#
# Main Program
#
if [ $# -eq 0 ]
then
Usage
fi
LoadStandardEnvironment
LoadInstanceConfiguration
case "${1}" in
deploy)
DeployWar
;;
update)
ValidateConfiguration
CreateRuntimeRequirements
UpdateGeneratedData && UpdateDescriptionCache
;;
updateQuietly)
ValidateConfiguration
CreateRuntimeRequirements
QUIET="-q"
VERBOSE=""
UpdateGeneratedData && UpdateDescriptionCache
;;
updateDesc)
UpdateDescriptionCache
;;
bootstrap)
ValidateConfiguration
CreateRuntimeRequirements
StdInvocation "--updateConfig"
;;
index)
if [ $# -gt 2 ]
then
Usage
fi
if [ -n "${2}" ]
then
SRC_ROOT="${2}"
fi
ValidateConfiguration
CreateRuntimeRequirements
UpdateGeneratedData && UpdateDescriptionCache
;;
indexpart)
if [ $# -ne 2 ]
then
Usage
fi
shift
if [ -z "$OPENGROK_READ_XML_CONFIGURATION" ]; then
FatalError "need configuration via OPENGROK_READ_XML_CONFIGURATION"
fi
ValidateConfiguration
CreateRuntimeRequirements
UpdateDataPartial $@
;;
clearHistory)
if [ $# -ne 3 ]
then
Usage
fi
SRC_ROOT="${2}"
shift 2
if [ -z "${1}" ]; then
Usage
fi
ClearHistory "${1}"
;;
usage|help)
OpenGrokUsage $2
Usage $2
;;
*)
Usage
;;
esac
#注释退出
#exit $?
同时针对上面的脚本修改,增加了一个傻瓜式创建OpenGrok多工程的脚本:
支持一键创建和删除OpenGrok项目。
#!/bin/sh
ReturnCheck()
{
if [ $1 -ne 0 ]; then
echo "$2 failed!"
else
echo "$2 succeed!"
fi
};
CreateNewProject(){
if [ "$1" == "create" ];then
if [ "" == "$2" ];then
echo "
parm2 is empty!
eg:
./runOpenGrok.sh create [project name] [source code path]
"
exit
fi
if [ "" == "$3" ];then
echo "
parm3 is empty!
eg:
./runOpenGrok.sh create [project name] [source code path]
"
exit
elif [ ! -d "$3" ];then
echo "
parm3 is not a dir or dir is not exist!
eg:
./runOpenGrok.sh create [project name] [source code path]
"
exit
fi
# $2 : project name
# $3 : source code path
export WAR_NAME="$2"
export SRC_CODE_NAME="$3"
#1.Create database dir :/opt/opengrok/database/${WAR_NAME}
echo "Create database dir to $2..."
sudo mkdir /opt/opengrok/database/${WAR_NAME}
ReturnCheck $? "Create database dir to $2 "
#2.Create softlink :/opt/opengrok/database/$2/$2
echo "Create softlink to $3..."
sudo ln -s $3 /opt/opengrok/database/$2/$2
ReturnCheck $? "Create softlink to $3 "
#3.Copy $2.war to /opt/opengrok/lib
echo "Copy $2.war to /opt/opengrok/lib..."
sudo cp /opt/opengrok/lib/source.war /opt/opengrok/lib/$2.war
ReturnCheck $? "Copy $2.war to /opt/opengrok/lib "
#4.Copy $2.war to /opt/apache-tomcat/webapps
echo "Copy $2.war to /opt/apache-tomcat/webapps..."
sudo cp /opt/opengrok/lib/source.war /opt/apache-tomcat/webapps/$2.war
ReturnCheck $? "Copy $2.war to /opt/apache-tomcat/webapps "
#5.Set $2.war config
echo "Set $2.war config..."
. /opt/opengrok/bin/TOpenGrok deploy
ReturnCheck $? "Set $2.war config "
#6.Set $3 code db
echo "Set $3 code db..."
. /opt/opengrok/bin/TOpenGrok index /opt/opengrok/database/$2
ReturnCheck $? "Set $3 code db "
fi
};
Help()
{
echo "=====================Help======================
创建OpenGrok工程:
sudo ./runOpenGrok.sh create [工程名] [工程源代码路径]
OpenGrok工程同步:
sudo ./runOpenGrok.sh sync [工程名]
删除OpenGrok工程:
sudo ./runOpenGrok.sh remove [工程名]
重启tomcat:
sudo ./runOpenGrok.sh re-tomcat
==============================================="
};
RemoveProject(){
if [ "" == "$1" ];then
echo "
parm1 is empty!
eg:
./runOpenGrok.sh remove [project name]
"
exit
fi
#1.remove db
echo "remove cache db ..."
sudo rm /opt/opengrok/database/$1 -rf
sudo rm /opt/opengrok/cache/$1 -rf
ReturnCheck $? "remove cache db from /opt/opengrok/cache/$1/* "
#2.remove $1.war
echo "remove $1.war ..."
sudo rm /opt/opengrok/lib/$1.war
sudo rm /opt/apache-tomcat/webapps/$1.war
sudo rm /opt/apache-tomcat/webapps/$1 -rf
sudo rm /opt/apache-tomcat/$1.war
ReturnCheck $? "remove $1.war "
}
SyncProject(){
if [ "" == "$1" ];then
echo "
parm2 is empty!
eg:
./runOpenGrok.sh sync [project name]
"
exit
elif [ ! -d "/opt/opengrok/database/$1" ];then
echo "
parm2 is not a dir or dir is not exist!
eg:
./runOpenGrok.sh sync [project name]
"
exit
fi
export WAR_NAME="$1"
echo "Sync code from /opt/opengrok/database/$1 to db..."
. /opt/opengrok/bin/TOpenGrok index /opt/opengrok/database/$1
ReturnCheck $? "Sync code from /opt/opengrok/database/$1 to db "
}
case "${1}" in
sync)
SyncProject $2 $3
;;
create)
CreateNewProject $1 $2 $3
;;
remove)
RemoveProject $2
;;
re-tomcat)
sudo service tomcat8 stop
sleep 5
sudo service tomcat8 start
;;
help)
Help
;;
*)
Help
;;
esac
错误解决:
出现以下错误:
Caused by: java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:848)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:390)
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:282)
… 12 more
解决方案:
在tomcat的/apache-tomcat/conf/server.xml添加https支持:
在工程的web.xml文件中加入https的支持
SSL
/*
CONFIDENTIAL