From c440186ce37ee1f6e0c711619b030f0e2bd536b0 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Wed, 22 Jul 2026 11:14:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=AB=AF=E9=83=A8=E7=BD=B2=E8=B7=AF=E5=BE=84=EF=BC=8C=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=AF=A6=E6=83=85=E9=A1=B5=E6=94=AF=E6=8C=81=E6=97=A0?= =?UTF-8?q?=E6=A0=87=E5=87=86=E9=85=8D=E7=BD=AE=E6=97=B6=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=AE=9E=E9=99=85=E6=A8=A1=E5=9E=8B/?= =?UTF-8?q?=E4=BA=BA=E8=84=B8=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 所有路径统一为 /opt/safesightd/{bin,config,data} - 新增 safesightd.json.example 使用绝对路径,不含 dev 私货 - package.sh 打包时使用示例配置,README 给出完整命令 - safesightd.service 精简冗余配置 - device.html: 无标准配置时仍展示设备上的模型/资源状态 - deployment.md: 路径对齐,补全配置字段 --- docs/deployment.md | 27 +++++++++++++++++---------- internal/web/ui/templates/device.html | 16 +++++++++++++++- safesightd.json.example | 12 ++++++++++++ scripts/deploy/safesightd.service | 15 --------------- scripts/package.sh | 18 +++++++++++++----- 5 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 safesightd.json.example diff --git a/docs/deployment.md b/docs/deployment.md index 25164a1..2a7b188 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -2,14 +2,14 @@ ## 打包 -在开发机上: +在开发机上(需 Git Bash 或 Linux/WSL): ```bash cd safesight-control bash scripts/package.sh ``` -生成 `safesight-control-*.tar.gz`,包含 ARM64 和 AMD64 两个二进制。 +生成 `safesight-control-*.tar.gz`,包含 ARM64 和 AMD64 两个二进制、service 文件、配置示例。 --- @@ -24,11 +24,14 @@ scp safesight-control-*.tar.gz orangepi@10.0.0.81:/tmp/ # 在设备上 cd /tmp && tar -xzf safesight-control-*.tar.gz cd safesight-control-* -sudo cp safesightd-linux-arm64 /usr/local/bin/safesightd -sudo chmod +x /usr/local/bin/safesightd -# 创建配置 -sudo mkdir -p /opt/safesightd/config +# 安装二进制 +sudo mkdir -p /opt/safesightd/bin +sudo cp safesightd-linux-arm64 /opt/safesightd/bin/safesightd +sudo chmod +x /opt/safesightd/bin/safesightd + +# 创建数据和配置目录 +sudo mkdir -p /opt/safesightd/config /opt/safesightd/data sudo cp safesightd.json.example /opt/safesightd/config/safesightd.json sudo vi /opt/safesightd/config/safesightd.json # 修改 agent_token @@ -41,8 +44,8 @@ sudo systemctl enable --now safesightd ### 部署到独立 Linux 服务器(AMD64) ```bash -# 同上,使用 safesightd-linux-amd64 -sudo cp safesightd-linux-amd64 /usr/local/bin/safesightd +# 同上,二进制改为 safesightd-linux-amd64 +sudo cp safesightd-linux-amd64 /opt/safesightd/bin/safesightd ``` 其余步骤相同。 @@ -57,10 +60,14 @@ sudo cp safesightd-linux-amd64 /usr/local/bin/safesightd { "listen": "0.0.0.0:18080", "discovery_port": 35688, + "discovery_timeout_ms": 1200, + "offline_after_ms": 10000, "agent_token": "4fe2d69fda23d0d5d04a1486d4920e68", "concurrency": 5, "data_dir": "/opt/safesightd/data", - "offline_after_ms": 10000 + "db_path": "/opt/safesightd/data/app.db", + "log_dir": "/opt/safesightd/data/logs", + "alarm_retention_days": 30 } ``` @@ -70,7 +77,7 @@ sudo cp safesightd-linux-amd64 /usr/local/bin/safesightd ```bash systemctl status safesightd -curl http://localhost:18080/health +curl http://localhost:18080/api/devices ``` 浏览器打开 `http://:18080` diff --git a/internal/web/ui/templates/device.html b/internal/web/ui/templates/device.html index 7cbcefe..9c17de5 100644 --- a/internal/web/ui/templates/device.html +++ b/internal/web/ui/templates/device.html @@ -178,6 +178,13 @@ {{if eq $status "ok"}}一致{{else if eq $status "mismatch"}}不一致{{else}}缺失{{end}} {{end}} + {{else if .DeviceModelStatuses}} +
+ {{range $m := .DeviceModelStatuses}} +
{{$m.Name}} + {{$m.SHA256}}
+ {{end}} +
{{end}} {{if .StandardResources}} @@ -189,9 +196,16 @@ {{if eq $status "ok"}}一致{{else if eq $status "mismatch"}}不一致{{else}}缺失{{end}} {{end}} + {{else if .DeviceResourceStatuses}} +
+ {{range $r := .DeviceResourceStatuses}} +
{{$r.Name}} ({{resourceTypeLabel $r.ResourceType}}) + {{$r.SHA256}}
+ {{end}} +
{{end}} - {{if not (or .StandardModels .StandardResources)}} + {{if not (or .StandardModels .StandardResources .DeviceModelStatuses .DeviceResourceStatuses)}}
模型入口通过模型管理页上传到设备
人脸库通过资源管理与基础配置维护
diff --git a/safesightd.json.example b/safesightd.json.example new file mode 100644 index 0000000..58c78af --- /dev/null +++ b/safesightd.json.example @@ -0,0 +1,12 @@ +{ + "listen": "0.0.0.0:18080", + "discovery_port": 35688, + "discovery_timeout_ms": 1200, + "offline_after_ms": 10000, + "agent_token": "4fe2d69fda23d0d5d04a1486d4920e68", + "concurrency": 5, + "data_dir": "/opt/safesightd/data", + "db_path": "/opt/safesightd/data/app.db", + "log_dir": "/opt/safesightd/data/logs", + "alarm_retention_days": 30 +} diff --git a/scripts/deploy/safesightd.service b/scripts/deploy/safesightd.service index d01cda9..ae9fb1d 100644 --- a/scripts/deploy/safesightd.service +++ b/scripts/deploy/safesightd.service @@ -1,6 +1,5 @@ [Unit] Description=SafeSight Control Service -Documentation=https://github.com/your-org/SafeSight Control After=network.target network-online.target Wants=network-online.target @@ -10,22 +9,8 @@ User=root Group=root WorkingDirectory=/opt/safesightd ExecStart=/opt/safesightd/bin/safesightd /opt/safesightd/config/safesightd.json -ExecReload=/bin/kill -HUP $MAINPID -KillMode=process -KillSignal=SIGTERM Restart=on-failure RestartSec=5 -StartLimitInterval=60s -StartLimitBurst=3 - -# 资源限制(根据需要调整) -# LimitNOFILE=65535 -# LimitNPROC=4096 - -# 安全设置 -NoNewPrivileges=false -ProtectSystem=false -ProtectHome=false [Install] WantedBy=multi-user.target diff --git a/scripts/package.sh b/scripts/package.sh index e63d529..ffb6db7 100644 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -22,16 +22,24 @@ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o "$BUILD_DIR/s echo "[2/2] 打包..." cp scripts/deploy/safesightd "$BUILD_DIR/" cp scripts/deploy/safesightd.service "$BUILD_DIR/" -cp safesightd.json "$BUILD_DIR/safesightd.json.example" 2>/dev/null || true +cp safesightd.json.example "$BUILD_DIR/safesightd.json.example" 2>/dev/null || true cat > "$BUILD_DIR/README.txt" << 'EOF' SafeSight Control 离线部署包 ============================= -部署: - sudo ./safesightd install /opt/safesightd - sudo vi /opt/safesightd/config/safesightd.json # 修改 token - sudo systemctl start safesightd +ARM64 设备部署: + sudo cp safesightd-linux-arm64 /opt/safesightd/bin/safesightd + sudo chmod +x /opt/safesightd/bin/safesightd + sudo mkdir -p /opt/safesightd/config /opt/safesightd/data + sudo cp safesightd.json.example /opt/safesightd/config/safesightd.json + sudo vi /opt/safesightd/config/safesightd.json # 修改 agent_token + sudo cp safesightd.service /etc/systemd/system/ + sudo systemctl daemon-reload + sudo systemctl enable --now safesightd + +AMD64 设备部署: + 同上,二进制改为 safesightd-linux-amd64 打开 http://:18080 EOF