Files
yunhaifinance/temp-clone/backend/start-server.sh
T

50 lines
1.2 KiB
Bash

#!/bin/bash
echo "=== 启动客户管理API服务器 ==="
echo
# 检查Node.js是否安装
if ! command -v node &> /dev/null; then
echo "错误: Node.js未安装"
exit 1
fi
# 检查npm是否安装
if ! command -v npm &> /dev/null; then
echo "错误: npm未安装"
exit 1
fi
# 检查依赖是否安装
if [ ! -d "node_modules" ]; then
echo "依赖未安装,正在安装..."
npm install
fi
# 检查PostgreSQL服务
echo "检查PostgreSQL服务..."
if ! systemctl is-active --quiet postgresql 2>/dev/null; then
echo "警告: PostgreSQL服务未运行"
echo "请手动启动: sudo systemctl start postgresql"
echo "或使用默认配置继续(如果数据库在其他地方运行)"
read -p "是否继续?(y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# 检查数据库
echo "检查数据库..."
if ! sudo -u postgres psql -lqt | cut -d \| -f 1 | grep -qw company_finance_db; then
echo "数据库不存在,正在初始化..."
sudo -u postgres psql -f init-db.sql
fi
# 启动服务器
echo "启动服务器..."
echo "服务器将在 http://localhost:3000 运行"
echo "按 Ctrl+C 停止服务器"
echo
npm start