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