Files
gerrit/检查并启动服务.sh
2025-12-22 17:12:39 +08:00

95 lines
2.6 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Gerrit 服务检查和启动脚本
GERRIT_HOME="/home/renjianbo/gerrit_install"
JAVA_HOME="/usr/local/java/jdk-17.0.12+7"
echo "=========================================="
echo "检查 Gerrit 服务状态"
echo "=========================================="
echo ""
# 检查 review_site 是否存在
if [ ! -d "${GERRIT_HOME}/review_site" ]; then
echo "❌ review_site 目录不存在!"
echo ""
echo "需要重新初始化 Gerrit请执行"
echo " cd /home/renjianbo/gerrit"
echo " ./reinit_gerrit.sh"
echo ""
exit 1
fi
cd ${GERRIT_HOME}/review_site
# 检查服务状态
echo "检查服务状态..."
if [ -f "bin/gerrit.sh" ]; then
bin/gerrit.sh status 2>&1
STATUS=$?
if [ $STATUS -ne 0 ] || ! bin/gerrit.sh status 2>&1 | grep -q "Running\|Gerrit running"; then
echo ""
echo "服务未运行,正在启动..."
echo ""
# 设置 Java 环境
export JAVA_HOME=$JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
# 确保启动脚本使用 Java 17
if ! grep -q "JAVA_HOME.*jdk-17" bin/gerrit.sh 2>/dev/null; then
echo "更新启动脚本使用 Java 17..."
cp bin/gerrit.sh bin/gerrit.sh.bak
sed -i "2i export JAVA_HOME=${JAVA_HOME}\nexport PATH=\$JAVA_HOME/bin:\$PATH" bin/gerrit.sh
fi
# 启动服务
bin/gerrit.sh start
sleep 5
# 再次检查状态
echo ""
echo "检查启动结果..."
bin/gerrit.sh status 2>&1
if bin/gerrit.sh status 2>&1 | grep -q "Running\|Gerrit running"; then
echo ""
echo "✅ 服务启动成功!"
echo ""
echo "访问地址: http://101.43.95.130:8080"
else
echo ""
echo "❌ 服务启动失败,请查看日志:"
echo " tail -f ${GERRIT_HOME}/review_site/logs/error_log"
fi
else
echo ""
echo "✅ 服务正在运行"
echo ""
echo "访问地址: http://101.43.95.130:8080"
fi
else
echo "❌ 未找到 bin/gerrit.sh"
echo "review_site 可能未正确初始化"
exit 1
fi
echo ""
echo "检查端口监听..."
if command -v netstat &> /dev/null; then
netstat -tlnp 2>/dev/null | grep ":8080" || echo "⚠️ 端口 8080 未被监听"
elif command -v ss &> /dev/null; then
ss -tlnp 2>/dev/null | grep ":8080" || echo "⚠️ 端口 8080 未被监听"
fi
echo ""
echo "检查进程..."
ps aux | grep "[g]errit.war daemon" | head -2
echo ""
echo "=========================================="