From 3aa9d8fe4399fc0c920e3e6eacef4eff5fccf4b8 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Fri, 20 Dec 2024 12:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=96=B9=E6=A1=88=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E5=AE=89=E8=A3=85=E7=BC=96=E8=AF=91=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assistant_snippet_Wd4Hs2Iqxj.txt | 7 ++ assistant_snippet_Yx5Hs2Iqxj.txt | 13 ++++ scripts/deploy.sh | 17 ++++- scripts/deploy_minimal.sh | 118 +++++++++++++++++++++++++++++++ scripts/prepare_deploy.sh | 100 ++++++++++++++++++++++++++ 5 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 assistant_snippet_Wd4Hs2Iqxj.txt create mode 100644 assistant_snippet_Yx5Hs2Iqxj.txt create mode 100644 scripts/deploy_minimal.sh create mode 100644 scripts/prepare_deploy.sh diff --git a/assistant_snippet_Wd4Hs2Iqxj.txt b/assistant_snippet_Wd4Hs2Iqxj.txt new file mode 100644 index 0000000..676fc5e --- /dev/null +++ b/assistant_snippet_Wd4Hs2Iqxj.txt @@ -0,0 +1,7 @@ +1|# 运行时必需的包 +2|- boost-system +3|- boost-filesystem +4|- boost-thread +5|- openssl-libs +6|- python3 +7|- python3-libs \ No newline at end of file diff --git a/assistant_snippet_Yx5Hs2Iqxj.txt b/assistant_snippet_Yx5Hs2Iqxj.txt new file mode 100644 index 0000000..98aa5a3 --- /dev/null +++ b/assistant_snippet_Yx5Hs2Iqxj.txt @@ -0,0 +1,13 @@ +1|deploy/ +2| ├── bin/ # 编译好的可执行文件 +3| │ └── collision_avoidance +4| ├── lib/ # 必要的运行时库 +5| │ ├── boost_system.so +6| │ ├── boost_filesystem.so +7| │ └── boost_thread.so +8| ├── python/ # Python 依赖包 +9| │ ├── flask +10| │ └── werkzeug +11| └── config/ # 配置文件 +12| ├── system_config.json +13| └── vehicle_control.json \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh index b0c4d50..678a80e 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -42,7 +42,16 @@ if [ -d "${PROJECT_ROOT}/packages" ]; then # Configure local repository log_info "配置本地仓库..." if [ -f "${PROJECT_ROOT}/packages/local.repo" ]; then + # Backup existing repo files + log_info "备份现有仓库配置..." + mkdir -p /etc/yum.repos.d/backup + mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ 2>/dev/null || true + + # Copy local repo configuration cp "${PROJECT_ROOT}/packages/local.repo" /etc/yum.repos.d/ + + # Clean and update repo cache + log_info "清理并更新仓库缓存..." yum clean all yum makecache else @@ -52,7 +61,7 @@ if [ -d "${PROJECT_ROOT}/packages" ]; then # Install packages from local repository log_info "从本地仓库安装依赖包..." - yum install -y --disablerepo=* --enablerepo=local \ + yum install -y \ cmake3 \ json-devel \ boost-devel \ @@ -81,6 +90,12 @@ if [ -d "${PROJECT_ROOT}/packages" ]; then exit 1 } fi + + # Restore original repo files + log_info "恢复原有仓库配置..." + rm -f /etc/yum.repos.d/local.repo + mv /etc/yum.repos.d/backup/* /etc/yum.repos.d/ 2>/dev/null || true + rmdir /etc/yum.repos.d/backup 2>/dev/null || true else # Online installation log_info "使用在线安装模式..." diff --git a/scripts/deploy_minimal.sh b/scripts/deploy_minimal.sh new file mode 100644 index 0000000..5f647b5 --- /dev/null +++ b/scripts/deploy_minimal.sh @@ -0,0 +1,118 @@ +#!/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" +} + +# Check if running as root +if [ "$EUID" -ne 0 ]; then + log_error "Please run as root" + exit 1 +fi + +# Get script directory and project root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "${SCRIPT_DIR}")" + +# Create work directory +WORK_DIR="/opt/collision_avoidance" +log_info "Creating work directory: $WORK_DIR" +mkdir -p $WORK_DIR + +# Copy files +log_info "Copying files..." +cp -r "${PROJECT_ROOT}/deploy/bin/"* "/usr/local/bin/" +cp -r "${PROJECT_ROOT}/deploy/lib/"* "/usr/lib64/" +cp -r "${PROJECT_ROOT}/deploy/python/"* "/tmp/" + +# Create config directory +CONFIG_DIR="/etc/collision_avoidance" +log_info "Creating config directory: $CONFIG_DIR" +mkdir -p $CONFIG_DIR +cp -r "${PROJECT_ROOT}/deploy/config/"* "$CONFIG_DIR/" + +# Install Python packages +log_info "Installing Python packages..." +cd /tmp +for pkg in *.whl; do + if [ -f "$pkg" ]; then + pip3 install --no-index "$pkg" + fi +done + +# Create service file +log_info "Creating system service..." +cat > /etc/systemd/system/collision-avoidance.service << EOL +[Unit] +Description=Collision Avoidance Service +After=network.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/collision_avoidance +WorkingDirectory=/usr/local/bin +User=root +Restart=always +RestartSec=3 +Environment=CONFIG_PATH=/etc/collision_avoidance +Environment=LD_LIBRARY_PATH=/usr/lib64 + +[Install] +WantedBy=multi-user.target +EOL + +# Configure firewall +log_info "Configuring firewall..." +if command -v firewall-cmd &> /dev/null; then + firewall-cmd --permanent --add-port=8010/tcp + firewall-cmd --permanent --add-port=8081/tcp + firewall-cmd --reload +else + log_warn "firewalld not detected, please configure firewall manually" +fi + +# Start service +log_info "Starting service..." +systemctl daemon-reload +systemctl enable collision-avoidance +systemctl start collision-avoidance + +# Check service status +if systemctl is-active --quiet collision-avoidance; then + log_info "Service started successfully" +else + log_error "Service failed to start, check logs" + journalctl -u collision-avoidance -n 50 + exit 1 +fi + +# Display service status +log_info "Deployment completed, service status:" +systemctl status collision-avoidance + +# Display usage instructions +echo -e "\n${GREEN}Deployment completed!${NC}" +echo "Use these commands to manage the service:" +echo " Start service: systemctl start collision-avoidance" +echo " Stop service: systemctl stop collision-avoidance" +echo " Restart service: systemctl restart collision-avoidance" +echo " Check status: systemctl status collision-avoidance" +echo " View logs: journalctl -u collision-avoidance -f" +echo -e "\nConfig files location: ${CONFIG_DIR}" +echo "WebSocket port: 8010" +echo "Mock Server port: 8081" \ No newline at end of file diff --git a/scripts/prepare_deploy.sh b/scripts/prepare_deploy.sh new file mode 100644 index 0000000..96d5b12 --- /dev/null +++ b/scripts/prepare_deploy.sh @@ -0,0 +1,100 @@ +#!/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}")" + +# Create deploy directory structure +DEPLOY_DIR="${PROJECT_ROOT}/deploy" +log_info "Creating deploy directory: ${DEPLOY_DIR}" +rm -rf "${DEPLOY_DIR}" +mkdir -p "${DEPLOY_DIR}/bin" +mkdir -p "${DEPLOY_DIR}/lib" +mkdir -p "${DEPLOY_DIR}/python" +mkdir -p "${DEPLOY_DIR}/config" + +# Build the project +log_info "Building project..." +cd "${PROJECT_ROOT}" +rm -rf build +mkdir build +cd build +cmake .. +make -j4 + +if [ $? -ne 0 ]; then + log_error "Build failed" + exit 1 +fi + +# Copy executable +log_info "Copying executable..." +cp collision_avoidance "${DEPLOY_DIR}/bin/" + +# Copy required libraries +log_info "Copying required libraries..." +LIBS=( + "libboost_system.so" + "libboost_filesystem.so" + "libboost_thread.so" + "libssl.so" + "libcrypto.so" +) + +for lib in "${LIBS[@]}"; do + # Find the library path + lib_path=$(ldd "${DEPLOY_DIR}/bin/collision_avoidance" | grep "$lib" | awk '{print $3}') + if [ -n "$lib_path" ]; then + cp "$lib_path" "${DEPLOY_DIR}/lib/" + log_info "Copied $lib" + else + log_warn "Library $lib not found" + fi +done + +# Copy Python dependencies +log_info "Copying Python dependencies..." +pip3 download --no-deps -d "${DEPLOY_DIR}/python" \ + flask==2.0.1 \ + werkzeug==2.0.1 \ + click==8.0.1 \ + itsdangerous==2.0.1 \ + Jinja2==3.0.1 \ + MarkupSafe==2.0.1 + +# Copy configuration files +log_info "Copying configuration files..." +cp "${PROJECT_ROOT}/config/system_config.json" "${DEPLOY_DIR}/config/" +cp "${PROJECT_ROOT}/config/vehicle_control.json" "${DEPLOY_DIR}/config/" + +# Create deployment archive +log_info "Creating deployment archive..." +cd "${PROJECT_ROOT}" +tar czf "${PROJECT_NAME}_deploy.tar.gz" deploy/ + +log_info "Deployment package created: ${PROJECT_NAME}_deploy.tar.gz" +echo "Package contents:" +echo " - Executable binary" +echo " - Required runtime libraries" +echo " - Python dependencies" +echo " - Configuration files" \ No newline at end of file