66 lines
2.0 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
set -e
# ========= 可配置常量 =========
IMG_TAR="equip-reserve-latest.tar"
CONTAINER_NAME="equip-reserve"
HOST_PORT=5173
# 脚本所在目录作为根目录
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
# 各挂载子目录
EQ_DIR="${BASE_DIR}/equip-reserve"
MYSQL_DATA_DIR="${EQ_DIR}/mysql_data"
DEVICE_IMG_DIR="${EQ_DIR}/device_image"
LOGS_DIR="${EQ_DIR}/logs"
# ==============================
echo "=== Equip-Reserve 一键部署 ==="
echo "脚本目录: ${BASE_DIR}"
# ===== 防火墙配置 =====
echo "正在配置防火墙..."
if command -v ufw >/dev/null 2>&1; then
# Ubuntu 默认 ufw
echo "使用ufw配置防火墙"
ufw allow 5173/tcp comment "equip-reserve web"
ufw reload
elif command -v firewall-cmd >/dev/null 2>&1; then
# CentOS/RHEL 7+
echo "使用firewall配置防火墙"
firewall-cmd --permanent --add-port=5173/tcp
firewall-cmd --reload
else
# 纯 iptables 保底
echo "暂时使用保底iptables配置持久化需安装 iptables-persistent"
iptables -C INPUT -p tcp --dport 5173 -j ACCEPT 2>/dev/null || \
iptables -I INPUT -p tcp --dport 5173 -j ACCEPT
# 如有需要保存规则Ubuntu 18 默认无持久化,需安装 iptables-persistent
fi
echo "防火墙 5173 端口已放行"
echo "开启启动设备管理系统"
# 1. 导入镜像(如果已存在则跳过)
if ! docker images | grep -q "equip-reserve"; then
echo "正在导入离线镜像..."
docker load -i "${BASE_DIR}/${IMG_TAR}"
else
echo "镜像已存在,跳过导入"
fi
# 2. 如果旧容器还在,先停掉并删除
docker rm -f "${CONTAINER_NAME}" 2>/dev/null || true
# 3. 启动容器
echo "正在启动容器..."
docker run -d \
--name "${CONTAINER_NAME}" \
-p "${HOST_PORT}:5173" \
-v "${EQ_DIR}":/equip-reserve \
-v "${MYSQL_DATA_DIR}":/var/lib/mysql \
-v "${DEVICE_IMG_DIR}":/device_image \
-v "${LOGS_DIR}":/logs \
-e TZ=Asia/Shanghai \
equip-reserve:latest
echo "系统已启动!"
echo "浏览器访问http://<离线机IP>:${HOST_PORT}"