added:增加Linux-server

This commit is contained in:
Vaica committed 2026-06-21 20:42:44 +08:00
1 parent 6fe4e9d23f
commit d78f3f811b
90 files changed
+16784 -1

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
#!/bin/bash
# Write Server 启动脚本
# 使用 PM2 管理进程
set -e
echo "==================================="
echo " Write Server 启动脚本"
echo "==================================="
# 检查 .env 文件
if [ ! -f .env ]; then
echo "错误: 未找到 .env 文件"
echo "请先复制 .env.example 为 .env 并填写配置"
exit 1
fi
# 加载环境变量
source .env
# 检查 BLOG_ROOT
if [ -z "$BLOG_ROOT" ]; then
echo "错误: BLOG_ROOT 未配置"
exit 1
fi
if [ ! -d "$BLOG_ROOT" ]; then
echo "错误: BLOG_ROOT 目录不存在: $BLOG_ROOT"
exit 1
fi
# 检查 Node.js
if ! command -v node &> /dev/null; then
echo "错误: Node.js 未安装"
exit 1
fi
# 检查 PM2
if ! command -v pm2 &> /dev/null; then
echo "错误: PM2 未安装"
echo "请运行: sudo npm install -g pm2"
exit 1
fi
# 检查是否已构建
if [ ! -d ".next" ]; then
echo "项目未构建,开始构建..."
npm run build
fi
# 停止现有进程(如果存在)
echo "停止现有进程..."
pm2 delete write-server 2>/dev/null || true
# 启动应用
echo "启动 Write Server..."
pm2 start npm --name "write-server" -- run start
# 等待应用启动
echo "等待应用启动..."
sleep 3
# 检查应用状态
if pm2 list | grep -q "write-server.*online"; then
echo ""
echo "==================================="
echo " 启动成功!"
echo "==================================="
echo ""
echo "服务地址: http://localhost:${PORT:-8016}"
echo ""
echo "管理命令:"
echo " 查看状态: pm2 status"
echo " 查看日志: pm2 logs write-server"
echo " 重启服务: pm2 restart write-server"
echo " 停止服务: pm2 stop write-server"
echo ""
else
echo ""
echo "==================================="
echo " 启动失败!"
echo "==================================="
echo ""
echo "请查看日志:"
echo " pm2 logs write-server"
echo ""
exit 1
fi