修改部署脚本

This commit is contained in:
Tian jianyong 2024-12-20 18:20:06 +08:00
parent e954766881
commit 0100107314
4 changed files with 20 additions and 305 deletions

View File

@ -146,6 +146,7 @@ cp "${PROJECT_ROOT}/tools/test_websocket.html" "${DEPLOY_DIR}/tools/"
# Copy deployment scripts
log_info "Copying deployment scripts..."
cp "${PROJECT_ROOT}/scripts/deploy.sh" "${DEPLOY_DIR}/scripts/"
cp "${PROJECT_ROOT}/scripts/uninstall.sh" "${DEPLOY_DIR}/scripts/"
chmod +x "${DEPLOY_DIR}/scripts/"*.sh
# Create deployment archive

View File

@ -1,194 +0,0 @@
#!/bin/bash
# Color definitions for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Print usage
usage() {
echo "Usage: $0"
echo "This script prepares packages"
}
# Parse command line arguments
if [ $# -gt 0 ]; then
log_error "This script does not accept any arguments"
usage
exit 1
fi
# Check if running on CentOS
if [ ! -f /etc/centos-release ]; then
log_error "This script must be run on CentOS"
exit 1
fi
# Get script directory and project root
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "${SCRIPT_DIR}")"
PROJECT_NAME="$(basename "${PROJECT_ROOT}")"
# Check if running from the correct directory
if [ ! -f "${PROJECT_ROOT}/CMakeLists.txt" ] || \
[ ! -d "${PROJECT_ROOT}/src" ] || \
[ ! -d "${PROJECT_ROOT}/scripts" ]; then
log_error "This script must be run from the project root directory (CollisionAvoidance)"
log_error "Current directory: $(pwd)"
log_error "Please run: cd /path/to/CollisionAvoidance && ./scripts/prepare_offline_packages.sh"
exit 1
fi
# Create packages directory
PACKAGES_DIR="${PROJECT_ROOT}/packages"
log_info "Creating packages directory: ${PACKAGES_DIR}"
mkdir -p "${PACKAGES_DIR}"
# Install necessary tools
log_info "Installing required tools..."
yum install -y yum-utils createrepo || {
log_error "Failed to install required tools"
exit 1
}
# Define base packages
PACKAGES=(
"cmake3"
"json-devel"
"boost-devel"
"openssl-devel"
"python3"
"python3-pip"
"python3-devel"
"python3-libs"
"python3-setuptools"
"gcc"
"gcc-c++"
"make"
"autoconf"
"automake"
"libtool"
)
# Download packages
log_info "Downloading packages and their dependencies..."
cd "${PACKAGES_DIR}" || {
log_error "Failed to enter packages directory"
exit 1
}
for pkg in "${PACKAGES[@]}"; do
log_info "Downloading $pkg and its dependencies..."
yumdownloader --resolve --destdir="${PACKAGES_DIR}" --arch=x86_64 "$pkg" || {
log_error "Failed to download $pkg"
exit 1
}
done
# Create local repository
log_info "Creating local repository..."
createrepo "${PACKAGES_DIR}" || {
log_error "Failed to create local repository"
exit 1
}
# Create repository configuration file
cat > "${PACKAGES_DIR}/local.repo" << EOL
[local]
name=Local Repository
baseurl=file://${PACKAGES_DIR}
enabled=1
gpgcheck=0
EOL
# Create Python requirements file
log_info "Creating Python requirements file..."
cat > requirements.txt << EOL
flask==2.0.1
werkzeug==2.0.1
click==8.0.1
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
EOL
# Create Python packages directory
PYTHON_PACKAGES_DIR="${PACKAGES_DIR}/python_packages"
mkdir -p "${PYTHON_PACKAGES_DIR}"
# Download Python packages
log_info "Downloading Python packages..."
if ! pip3 download -r requirements.txt -d "${PYTHON_PACKAGES_DIR}"; then
log_error "Failed to download Python packages"
exit 1
fi
# Create package list
log_info "Creating package list..."
if ! ls *.rpm > offline-deps.txt 2>/dev/null; then
log_error "No RPM packages found in the directory"
log_error "Please check the previous error messages"
exit 1
fi
# Sort package list to handle dependencies
log_info "Sorting package list for dependency order..."
if ! grep "boost-.*\.rpm" offline-deps.txt > boost-deps.txt 2>/dev/null; then
log_warn "No boost packages found"
fi
if ! grep -v "boost-.*\.rpm" offline-deps.txt > other-deps.txt 2>/dev/null; then
log_warn "No non-boost packages found"
fi
cat boost-deps.txt other-deps.txt > offline-deps.txt 2>/dev/null
rm -f boost-deps.txt other-deps.txt
# Return to project root directory
cd "${PROJECT_ROOT}" || {
log_error "Failed to return to project root directory"
exit 1
}
# Create archive of the project
log_info "Creating project archive..."
ARCHIVE_NAME="${PROJECT_NAME}.tar.gz"
ARCHIVE_PATH="${PROJECT_ROOT}/../${ARCHIVE_NAME}"
tar czf "${ARCHIVE_PATH}" \
--exclude=".git" \
--exclude="build" \
--exclude="*.tar.gz" \
-C "${PROJECT_ROOT}/.." "${PROJECT_NAME}" || {
log_error "Failed to create project archive"
exit 1
}
log_info "Successfully created ${ARCHIVE_NAME}"
# Print summary
echo -e "\n${GREEN}Offline package preparation completed!${NC}"
echo "Created files:"
echo " - ${PACKAGES_DIR}/offline-deps.txt (System package list)"
echo " - ${PACKAGES_DIR}/requirements.txt (Python package list)"
echo " - ${PACKAGES_DIR}/local.repo (Local repository configuration)"
echo " - ${PACKAGES_DIR}/*.rpm (System packages)"
echo " - ${PACKAGES_DIR}/repodata/* (Repository metadata)"
echo " - ${PACKAGES_DIR}/${PYTHON_PACKAGES_DIR}/* (Python packages)"
echo " - ${ARCHIVE_PATH} (Complete project archive)"
echo -e "\nNext steps:"
echo "1. Transfer ${ARCHIVE_NAME} to the target server"
echo "2. Extract the archive on the target server"
echo "3. Copy local.repo to /etc/yum.repos.d/ on the target server"
echo "4. Run the deployment script"

View File

@ -1,12 +1,12 @@
#!/bin/bash
# 颜色定义
# Color definitions for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 日志函数
# Logging functions
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
@ -19,48 +19,40 @@ log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 检查是否为 root 用户
# Check if running as root
if [ "$EUID" -ne 0 ]; then
log_error "请使用 root 用户运行此脚本"
log_error "Please run as root"
exit 1
fi
# 停止服务
log_info "停止服务..."
# Stop and disable service
log_info "Stopping service..."
systemctl stop collision-avoidance
systemctl disable collision-avoidance
# 删除服务文件
log_info "删除服务文件..."
# Remove service file
log_info "Removing service file..."
rm -f /etc/systemd/system/collision-avoidance.service
systemctl daemon-reload
# 删除可执行文件
log_info "删除可执行文件..."
# Remove files
log_info "Removing files..."
rm -f /usr/local/bin/collision_avoidance
# 删除配置文件
log_info "删除配置文件..."
rm -rf /etc/collision_avoidance
# 删除工作目录
log_info "删除工作目录..."
rm -rf /opt/collision_avoidance
# 关闭防火墙端口
log_info "关闭防火墙端口..."
# Remove Python packages
log_info "Removing Python packages..."
pip3 uninstall -y flask werkzeug click itsdangerous Jinja2 MarkupSafe
# Remove firewall rules
log_info "Removing firewall rules..."
if command -v firewall-cmd &> /dev/null; then
firewall-cmd --permanent --remove-port=8010/tcp
firewall-cmd --permanent --remove-port=8081/tcp
firewall-cmd --reload
else
log_warn "未检测到 firewalld请手动配置防火墙"
log_warn "firewalld not detected, please remove firewall rules manually"
fi
log_info "卸载完成"
echo -e "\n${GREEN}系统清理完成!${NC}"
echo "如果需要,请手动删除以下依赖包:"
echo " - Development Tools"
echo " - cmake3"
echo " - nlohmann-json-devel"
echo " - boost-devel"
echo " - openssl-devel"
log_info "Uninstallation completed"

View File

@ -1,84 +0,0 @@
#!/bin/bash
# Color definitions for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Get script directory and project root
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "${SCRIPT_DIR}")"
PROJECT_NAME="$(basename "${PROJECT_ROOT}")"
# Check if the archive exists
ARCHIVE_PATH="${PROJECT_ROOT}/../${PROJECT_NAME}.tar.gz"
if [ ! -f "${ARCHIVE_PATH}" ]; then
log_error "Archive file not found: ${ARCHIVE_PATH}"
log_error "Please run prepare_offline_packages.sh first"
exit 1
fi
# Create a temporary test directory
TEST_DIR=$(mktemp -d)
log_info "Creating test directory: ${TEST_DIR}"
# Copy archive to test directory
cp "${ARCHIVE_PATH}" "${TEST_DIR}/"
# Print verification steps
echo -e "\n${GREEN}Verification Steps:${NC}"
echo "1. Prepare a clean CentOS 7 system (physical machine or VM)"
echo "2. Copy these files to the test system:"
echo " - ${ARCHIVE_PATH}"
echo ""
echo "3. On the test system, run:"
echo " cd /tmp"
echo " tar xzf ${PROJECT_NAME}.tar.gz"
echo " cd ${PROJECT_NAME}"
echo " sudo ./scripts/deploy.sh"
echo ""
echo "4. Verify the installation:"
echo " - Check if all packages are installed:"
echo " rpm -qa | grep -E 'boost|cmake3|python3'"
echo ""
echo " - Check Python packages:"
echo " pip3 list | grep -E 'flask|werkzeug|click|itsdangerous|Jinja2|MarkupSafe'"
echo ""
echo " - Check if service is running:"
echo " systemctl status collision-avoidance"
echo ""
echo " - Check service logs:"
echo " journalctl -u collision-avoidance"
echo ""
echo " - Check ports:"
echo " ss -tunlp | grep -E '8010|8081'"
echo ""
echo "5. Test the service:"
echo " - Open http://localhost:8010 in browser"
echo " - Check if mock server is running on port 8081"
echo ""
echo "If any step fails, please check:"
echo "1. /var/log/messages for system errors"
echo "2. journalctl -u collision-avoidance for service errors"
echo "3. Check if all required ports are available"
echo "4. Verify system requirements (memory, disk space)"
echo ""
log_info "Verification guide has been created"
echo -e "Follow the steps above to verify the installation in a clean environment"
# Clean up
rm -rf "${TEST_DIR}"