# 阳光体育部署文档

##　先决条件
1.dotnet 8
2.git 

## 运行项目
```sh
# 假设项目文件在 /disk/ 目录下（disk为空目录）
sudo mkdir /disk
sudo chmod 777 /disk

# 拉取代码
git clone git@192.168.1.33:mogu_server/sunnysports.git
# 进入到拉取代码文件中
cd /disk/sunnysports
# 安装git子模块
git submodule init
# 拉去子模块代码，拉完需要检测下子模块文件夹中是否有文件（子模块路径：/disk/sunnysports/SunnySports/XLib）
git submodule update
# 切换子模块分支(先切换到主目录，在切换分支，然后拉去代码)
cd /disk/sunnysports/SunnySports/XLib
git checkout main
git pull
# 切换主项目分支(和上面一样)
cd /disk/sunnysports
git checkout main
git pull
# 还原包
cd /disk/sunnysports/SunnySports
dotnet restore
# 编译项目
cd /disk/sunnysports/SunnySports
dotnet build
#编译api项目
cd /disk/sunnysports/SunnySports/1-api/SunnySports.Api
dotnet build
# 运行项目
cd /disk/sunnysports/SunnySports/1-api/SunnySports.Api
dotnet run
```

## 发布项目
```sh
# 假设项目文件在 /disk/ 目录下（disk文件夹中已经有sunnysports项目文件夹）
# 创建文件夹SunnySportsApi  DataGateway 
cd /disk/
mkdir sunnysportsapi
sudo chmod 777 sunnysportsapi
# 发布项目
cd /disk/sunnysports/SunnySports/1-api/SunnySports.Api
dotnet publish -c Release -o /disk/sunnysportsapi
# 运行项目
cd /disk/sunnysportsapi
./SunnySports.Api
```

## 发布项目
```sh
# 假设项目文件在 /disk/ 目录下（disk文件夹中已经有sunnysports项目文件夹）
# 创建文件夹SunnySportsApi  DataGateway 
cd /disk/
mkdir DataGateway
sudo chmod 777 DataGateway
# 发布项目 
cd /disk/sunnysports/SunnySports/2-service/DataGateway
dotnet publish -c Release -o /disk/DataGateway/
rsync -avz /disk/DataGateway/ root@192.144.132.25:/disk/ai_sports/DataGateway/
# 运行项目 /disk/DataGateway/NLog.config
cd /disk/sunnysportsapi
./SunnySports.Api
```


dotnet publish -c Release -o /disk/DataGateway

## 同步项目
```sh
# 安装文件同步工具
sudo apt-get install rsync
#同步文件
rsync -avz /disk/sunnysportsapi/ root@192.168.1.229:/disk/ai_sports/sunnysportsapi
rsync -avz /disk/sunnysportsapi/ root@192.144.132.25:/disk/ai_sports/sunnysportsapi
# http://192.144.132.25/
# ssh -p 22  root@192.144.132.25
# 192.168.1.229,服务器密码:Itvgame2020@!$#
```

sudo systemctl stop pray-api.service

rsync -avz /disk/PrayForBlessingsApi ubuntu@1.117.87.77:/disk/prayforblessingsapi
dbt@com@1234
## 创建linux 服务
```sh
# 你需要创建一个systemd服务单元文件。这个文件描述了如何启动、停止和重启你的程序。你可以在/etc/systemd/system/目录下创建一个新的.service文件，比如your_program.service
 cd /etc/systemd/system/
 # 创建文件
 sudo nano sunny-sports-api.service
 #粘贴内容
[Unit]
Description=sunny-sports-api
After=network.target
[Service]
# 运行 设置环境变量
#指定服务的工作目录
WorkingDirectory=/disk/ai_sports/sunnysportsapi
# run
ExecStart=/disk/ai_sports/sunnysportsapi/SunnySports.Api
SyslogIdentifier=SunnySportsApi
User=root
# 打开资源限制infinity 默认会到65535
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
# 自动检查重启，10秒后重启
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
 
#刷新服务 
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start sunny-sports-api.service
sudo systemctl start data-gateway.service
# 检测服务状态
sudo systemctl status sunny-sports-api.service
# 设置开机启动
sudo systemctl enable sunny-sports-api.service
sudo systemctl enable data-gateway.service
# 关闭服务
sudo systemctl stop sunny-sports-api.service
sudo systemctl stop data-gateway.service
# 关闭开机启动
sudo systemctl disable sunny-sports-api.service
# 重新启动服务
sudo systemctl restart sunny-sports-api.service
sudo systemctl restart data-gateway.service
# 发布
cd /disk/sunnysports/SunnySports/;make build-release-229
cd /disk/sunnysports/SunnySports/;make build-release-25

```
sudo systemctl restart data-gateway.service
## 更新项目
```sh
# 先将检测服务状态，如果服务启动，先停止服务
sudo systemctl status sunny-sports-api.service
# 停止服务
sudo systemctl stop sunny-sports-api.service
sudo systemctl stop sunny-sports-api.service
# 同步文件
rsync -avz /disk/sunnysportsapi/ root@192.168.1.229:/disk/ai_sports/sunnysportsapi
# 开启服务
sudo systemctl start sunny-sports-api.service
# 检测服务状态
sudo systemctl status sunny-sports-api.service

sudo systemctl restart sunny-sports-api.service
```


## 配置项
```sh
# 配置学生人脸存放地址
\\\\\\\\\\
"StudentConfig":{
    # 存放学生人脸的路径
    "StudentFacePath": "./StudentFace/",
}
```


## 接口乱码

```sh
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=


LANG=zh_CN.UTF-8
LANGUAGE=
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=

```




## make 发布命令
```sh
# 229服务器
数据网关  ssh root@192.168.1.229 "cd /disk/work/sj_git/sunnysports/;make build-data-loca"
api ssh root@192.168.1.229 "cd /disk/work/sj_git/sunnysports/;make build-api-loca"
前端 ssh root@192.168.1.229 "cd /disk/work/sj_git/systemadmin/;make build-test"

# 25服务器
数据网关 ssh root@192.168.1.229 "cd /disk/work/sj_git/sunnysports/;make build-data"
api  ssh root@192.168.1.229 "cd /disk/work/sj_git/sunnysports/;make build-api"
前端 ssh root@192.168.1.229 "cd /disk/work/sj_git/systemadmin/;make build"
ssh root@192.168.1.229 "cd /disk/work/sj_git/sunnysports/;make build-api-all"
ssh root@192.168.1.229 "cd /disk/work/sj_git/systemadmin/;make build-r"

D:\办公软件\HBuilderX\cli.exe cli publish --platform h5 --project SunnySportsStudent

````

