无源标靶上位机
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

109 lines
2.2 KiB

#!/bin/bash
# 应用打包脚本 - 在开发环境运行
APP_NAME="my-node-app"
VERSION="1.0.0"
TARGET_DIR="./build"
DEPLOY_PACKAGE="${APP_NAME}-${VERSION}.tar.gz"
echo "打包 Node.js 应用..."
# 清理旧构建
rm -rf $TARGET_DIR
mkdir -p $TARGET_DIR
# 复制源代码
cp -r ./* $TARGET_DIR/
# 创建部署脚本
cat > $TARGET_DIR/deploy.sh << 'EOF'
#!/bin/bash
# 应用部署脚本
APP_NAME="my-node-app"
INSTALL_DIR="/opt/$APP_NAME"
SERVICE_NAME="$APP_NAME.service"
echo "正在部署 $APP_NAME..."
# 检查 Node.js 是否安装
if ! command -v node &> /dev/null; then
echo "错误: Node.js 未安装。请先安装 Node.js 20+"
exit 1
fi
# 停止现有服务
if systemctl is-active --quiet $SERVICE_NAME; then
systemctl stop $SERVICE_NAME
fi
# 禁用现有服务
if systemctl is-enabled --quiet $SERVICE_NAME; then
systemctl disable $SERVICE_NAME
fi
# 创建安装目录
mkdir -p $INSTALL_DIR
# 复制文件
cp -r ./* $INSTALL_DIR/
# 安装依赖
cd $INSTALL_DIR
npm install
# 创建 systemd 服务文件
cat > /etc/systemd/system/$SERVICE_NAME << SERVICE_EOF
[Unit]
Description=$APP_NAME Node.js Application
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$INSTALL_DIR
ExecStart=/usr/bin/npm start
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
SERVICE_EOF
# 重新加载 systemd
systemctl daemon-reload
# 启用并启动服务
systemctl enable $SERVICE_NAME
systemctl start $SERVICE_NAME
echo "部署完成! 服务状态:"
systemctl status $SERVICE_NAME --no-pager
EOF
chmod +x $TARGET_DIR/deploy.sh
# 创建安装说明
cat > $TARGET_DIR/README.md << 'EOF'
# 应用安装说明
## 要求
- Linux 系统
- Node.js 20+ 已安装
## 安装步骤
1. 上传此文件夹到目标服务器
2. 运行: ./deploy.sh
## 管理服务
- 启动: sudo systemctl start my-node-app.service
- 停止: sudo systemctl stop my-node-app.service
- 状态检查: sudo systemctl status my-node-app.service
- 查看日志: journalctl -u my-node-app.service -f
EOF
# 创建打包文件
tar -czf $DEPLOY_PACKAGE -C $TARGET_DIR .
echo "打包完成: $DEPLOY_PACKAGE"
echo "请将此文件上传到服务器并解压后运行 ./deploy.sh"