修改部署文件
This commit is contained in:
parent
b65b6a60ab
commit
28c3291d77
@ -1,5 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set up logging
|
||||
LOGFILE="/tmp/deploy.log"
|
||||
exec 1> >(tee -a "$LOGFILE")
|
||||
exec 2> >(tee -a "$LOGFILE" >&2)
|
||||
|
||||
# Color definitions for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
@ -48,10 +53,37 @@ rpm -Uvh --nodeps python3*.rpm
|
||||
WORK_DIR="/opt/collision_avoidance"
|
||||
log_info "Creating work directory: $WORK_DIR"
|
||||
mkdir -p $WORK_DIR
|
||||
mkdir -p $WORK_DIR/bin
|
||||
mkdir -p $WORK_DIR/lib
|
||||
mkdir -p $WORK_DIR/tools
|
||||
mkdir -p $WORK_DIR/config
|
||||
|
||||
# Copy files
|
||||
log_info "Copying files..."
|
||||
|
||||
# Check SELinux status
|
||||
log_info "Checking SELinux status..."
|
||||
if command -v getenforce &> /dev/null; then
|
||||
selinux_status=$(getenforce)
|
||||
log_info "SELinux status: $selinux_status"
|
||||
if [ "$selinux_status" = "Enforcing" ]; then
|
||||
log_info "Setting SELinux contexts..."
|
||||
|
||||
# 设置应用目录的 SELinux 上下文
|
||||
log_info "Setting context for application directories..."
|
||||
chcon -R -t usr_t $WORK_DIR
|
||||
chcon -t bin_t $WORK_DIR/bin
|
||||
chcon -t lib_t $WORK_DIR/lib
|
||||
chcon -t etc_t $WORK_DIR/config
|
||||
|
||||
# 恢复默认上下文
|
||||
log_info "Restoring default contexts..."
|
||||
restorecon -Rv $WORK_DIR
|
||||
fi
|
||||
else
|
||||
log_warn "SELinux tools not found"
|
||||
fi
|
||||
|
||||
for dir in bin lib python tools config; do
|
||||
if [ ! -d "${PROJECT_ROOT}/${dir}" ]; then
|
||||
log_error "Directory not found: ${PROJECT_ROOT}/${dir}"
|
||||
@ -61,14 +93,16 @@ done
|
||||
|
||||
# Copy executable
|
||||
log_info "Copying executable..."
|
||||
if ! cp -v "${PROJECT_ROOT}/bin/"* "/usr/local/bin/"; then
|
||||
log_error "Failed to copy executable"
|
||||
exit 1
|
||||
if [ "$EXECUTABLE_COPIED" != "1" ]; then
|
||||
if ! cp -v "${PROJECT_ROOT}/bin/"* "$WORK_DIR/bin/"; then
|
||||
log_error "Failed to copy executable"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Copy libraries
|
||||
log_info "Copying libraries..."
|
||||
if ! cp -v "${PROJECT_ROOT}/lib/"* "/usr/lib64/"; then
|
||||
if ! cp -v "${PROJECT_ROOT}/lib/"* "$WORK_DIR/lib/"; then
|
||||
log_error "Failed to copy libraries"
|
||||
exit 1
|
||||
fi
|
||||
@ -88,7 +122,7 @@ if ! cp -v "${PROJECT_ROOT}/tools/"* "$WORK_DIR/tools/"; then
|
||||
fi
|
||||
|
||||
# Create config directory
|
||||
CONFIG_DIR="/etc/collision_avoidance"
|
||||
CONFIG_DIR="$WORK_DIR/config"
|
||||
log_info "Creating config directory: $CONFIG_DIR"
|
||||
mkdir -p $CONFIG_DIR
|
||||
cp -r "${PROJECT_ROOT}/config/"* "$CONFIG_DIR/"
|
||||
@ -111,13 +145,13 @@ After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/collision_avoidance
|
||||
WorkingDirectory=/usr/local/bin
|
||||
ExecStart=$WORK_DIR/bin/collision_avoidance
|
||||
WorkingDirectory=$WORK_DIR/bin
|
||||
User=root
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
Environment=CONFIG_PATH=/etc/collision_avoidance
|
||||
Environment=LD_LIBRARY_PATH=/usr/lib64
|
||||
Environment=CONFIG_PATH=$WORK_DIR/config
|
||||
Environment=LD_LIBRARY_PATH=$WORK_DIR/lib
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
Loading…
Reference in New Issue
Block a user