first commit
This commit is contained in:
155
标准重新安装.sh
Executable file
155
标准重新安装.sh
Executable file
@@ -0,0 +1,155 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Gerrit 标准重新安装脚本
|
||||
# 参考: https://blog.51cto.com/wst021sh/5086764
|
||||
|
||||
set -e
|
||||
|
||||
# 配置变量
|
||||
GERRIT_HOME="/home/renjianbo/gerrit_install"
|
||||
GERRIT_VERSION="3.9.0"
|
||||
GERRIT_USER="renjianbo"
|
||||
GERRIT_PORT="8080"
|
||||
GERRIT_SSH_PORT="29418"
|
||||
SERVER_IP="101.43.95.130"
|
||||
JAVA_HOME="/usr/local/java/jdk-17.0.12+7"
|
||||
|
||||
export JAVA_HOME
|
||||
export PATH=$JAVA_HOME/bin:$PATH
|
||||
|
||||
echo "=========================================="
|
||||
echo "Gerrit 标准重新安装"
|
||||
echo "版本: ${GERRIT_VERSION}"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# 1. 停止现有服务
|
||||
echo "[1/7] 停止现有服务..."
|
||||
if [ -d "${GERRIT_HOME}/review_site" ]; then
|
||||
cd ${GERRIT_HOME}/review_site
|
||||
if [ -f "bin/gerrit.sh" ]; then
|
||||
bin/gerrit.sh stop 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
pkill -9 -f "gerrit.war" 2>/dev/null || true
|
||||
sleep 2
|
||||
echo "✓ 服务已停止"
|
||||
echo ""
|
||||
|
||||
# 2. 删除旧安装
|
||||
echo "[2/7] 删除旧安装..."
|
||||
cd ${GERRIT_HOME}
|
||||
rm -rf review_site
|
||||
echo "✓ 已删除旧安装"
|
||||
echo ""
|
||||
|
||||
# 3. 检查并下载 Gerrit
|
||||
echo "[3/7] 检查安装包..."
|
||||
if [ ! -f "gerrit-${GERRIT_VERSION}.war" ]; then
|
||||
echo "下载 Gerrit ${GERRIT_VERSION}..."
|
||||
wget -q https://gerrit-releases.storage.googleapis.com/gerrit-${GERRIT_VERSION}.war
|
||||
fi
|
||||
echo "✓ 安装包就绪"
|
||||
echo ""
|
||||
|
||||
# 4. 初始化 Gerrit
|
||||
echo "[4/7] 初始化 Gerrit(这可能需要几分钟)..."
|
||||
cd ${GERRIT_HOME}
|
||||
java -Dgerrit.canonicalWebUrl=http://${SERVER_IP}:${GERRIT_PORT}/ \
|
||||
-jar gerrit-${GERRIT_VERSION}.war init \
|
||||
-d review_site \
|
||||
--batch \
|
||||
--no-auto-start \
|
||||
--install-plugin=download-commands \
|
||||
--install-plugin=replication \
|
||||
--install-plugin=reviewnotes
|
||||
|
||||
echo "✓ 初始化完成"
|
||||
echo ""
|
||||
|
||||
# 5. 配置 Gerrit
|
||||
echo "[5/7] 配置 Gerrit..."
|
||||
cd ${GERRIT_HOME}/review_site
|
||||
|
||||
# 创建配置文件
|
||||
cat > etc/gerrit.config << EOF
|
||||
[gerrit]
|
||||
basePath = git
|
||||
canonicalWebUrl = http://${SERVER_IP}:${GERRIT_PORT}/
|
||||
serverId = $(date +%s)
|
||||
[database]
|
||||
type = h2
|
||||
database = db/ReviewDB
|
||||
[auth]
|
||||
type = DEVELOPMENT_BECOME_ANY_ACCOUNT
|
||||
gitBasicAuth = true
|
||||
[sshd]
|
||||
listenAddress = *:${GERRIT_SSH_PORT}
|
||||
[httpd]
|
||||
listenUrl = http://*:${GERRIT_PORT}/
|
||||
cookieSecure = false
|
||||
cookieSameSite = LAX
|
||||
cookiePath = /
|
||||
[cache]
|
||||
directory = cache
|
||||
[index]
|
||||
type = LUCENE
|
||||
[receive]
|
||||
enableSignedPush = false
|
||||
EOF
|
||||
|
||||
echo "✓ 配置完成"
|
||||
echo ""
|
||||
|
||||
# 6. 配置启动脚本
|
||||
echo "[6/7] 配置启动脚本..."
|
||||
cd ${GERRIT_HOME}/review_site
|
||||
|
||||
# 备份原脚本
|
||||
cp bin/gerrit.sh bin/gerrit.sh.bak
|
||||
|
||||
# 在脚本开头添加 Java 环境变量
|
||||
if ! grep -q "JAVA_HOME.*jdk-17" bin/gerrit.sh; then
|
||||
sed -i "2i export JAVA_HOME=${JAVA_HOME}\nexport PATH=\$JAVA_HOME/bin:\$PATH" bin/gerrit.sh
|
||||
fi
|
||||
|
||||
echo "✓ 启动脚本已配置"
|
||||
echo ""
|
||||
|
||||
# 7. 启动服务
|
||||
echo "[7/7] 启动 Gerrit 服务..."
|
||||
cd ${GERRIT_HOME}/review_site
|
||||
bin/gerrit.sh start
|
||||
|
||||
echo "等待服务启动..."
|
||||
sleep 8
|
||||
|
||||
# 检查服务状态
|
||||
if bin/gerrit.sh status 2>&1 | grep -q "Gerrit running\|Running"; then
|
||||
echo "✓ 服务启动成功"
|
||||
else
|
||||
echo "检查服务状态..."
|
||||
bin/gerrit.sh status 2>&1 | head -10
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "安装完成!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "访问地址: http://${SERVER_IP}:${GERRIT_PORT}"
|
||||
echo ""
|
||||
echo "重要提示:"
|
||||
echo "1. 清除浏览器 Cookie 和缓存"
|
||||
echo "2. 访问上述地址"
|
||||
echo "3. 点击 'Sign In',输入用户名(例如:admin)"
|
||||
echo "4. 第一个登录的用户将自动成为管理员"
|
||||
echo "5. 登录后应该能看到 'CREATE NEW' 按钮"
|
||||
echo ""
|
||||
echo "常用命令:"
|
||||
echo " 查看状态: cd ${GERRIT_HOME}/review_site && bin/gerrit.sh status"
|
||||
echo " 查看日志: tail -f ${GERRIT_HOME}/review_site/logs/error_log"
|
||||
echo " 停止服务: cd ${GERRIT_HOME}/review_site && bin/gerrit.sh stop"
|
||||
echo " 重启服务: cd ${GERRIT_HOME}/review_site && bin/gerrit.sh restart"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user