物联网程序
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
version_code: 0
|
version_code: 27
|
||||||
pid: 0
|
pid: 29412
|
||||||
need_update: false
|
need_update: false
|
||||||
control_state: CONNECTED
|
control_state: CONTROL_LOST
|
||||||
last_alive_at: 1767926721
|
last_alive_at: 1771987569
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
version_code: 26
|
version_code: 27
|
||||||
pid: 26612
|
pid: 24516
|
||||||
need_update: false
|
need_update: false
|
||||||
control_state: CONNECTED
|
control_state: CONNECTED
|
||||||
last_alive_at: 1769564518
|
last_alive_at: 1771987537
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -117,19 +117,30 @@ func (b *BusinessService) handleShutdown() string {
|
|||||||
return "程序已退出"
|
return "程序已退出"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重启程序
|
||||||
// 重启程序
|
// 重启程序
|
||||||
func (b *BusinessService) handleRestart() string {
|
func (b *BusinessService) handleRestart() string {
|
||||||
log.Println("正在拉取镜像:", config.DOCKER_IMAGE)
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if err := b.dockerManager.PullImage(ctx, config.DOCKER_IMAGE); err != nil {
|
|
||||||
log.Fatalf("镜像拉取失败:%v", err)
|
// 先停止并移除旧容器
|
||||||
|
if err := b.dockerManager.StopAndRemoveContainer(ctx); err != nil {
|
||||||
|
log.Println("警告:移除容器失败,可能容器不存在:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := b.dockerManager.RunContainer(ctx)
|
// 拉取最新镜像
|
||||||
if err != nil {
|
log.Println("正在拉取镜像:", config.DOCKER_IMAGE)
|
||||||
log.Fatal(err)
|
if err := b.dockerManager.PullImage(ctx, config.DOCKER_IMAGE); err != nil {
|
||||||
|
log.Println("镜像拉取失败:", err)
|
||||||
|
return "程序重启失败,拉取镜像失败"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 启动新容器
|
||||||
|
if err := b.dockerManager.RunContainer(ctx); err != nil {
|
||||||
|
log.Println("容器启动失败:", err)
|
||||||
|
return "程序重启失败,容器启动失败"
|
||||||
|
}
|
||||||
|
|
||||||
return "程序已重启"
|
return "程序已重启"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import (
|
|||||||
// 常量
|
// 常量
|
||||||
const (
|
const (
|
||||||
// 版本号
|
// 版本号
|
||||||
APP_VERSION = 26
|
APP_VERSION = 29
|
||||||
|
|
||||||
//BASE_URL = "https://ai.ronsunny.cn:8090"
|
BASE_URL = "https://ai.ronsunny.cn:8090"
|
||||||
BASE_URL = "http://127.0.0.1:13011"
|
//BASE_URL = "http://127.0.0.1:13011"
|
||||||
LOG_FILE_DIC = "./logs"
|
LOG_FILE_DIC = "./logs"
|
||||||
LOG_CHECK_INTERVAL_HOURS = 10 // 文件轮询检查间隔(秒)
|
LOG_CHECK_INTERVAL_HOURS = 10 // 文件轮询检查间隔(秒)
|
||||||
MQTT_BROKER = "tls://ai.ronsunny.cn:8093"
|
MQTT_BROKER = "tls://ai.ronsunny.cn:8093"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"sentinel/pkg/config"
|
"sentinel/pkg/config"
|
||||||
|
"sentinel/pkg/device"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"sentinel/pkg/log"
|
"sentinel/pkg/log"
|
||||||
@@ -70,13 +71,23 @@ func (d *DockerManager) RunContainer(ctx context.Context) error {
|
|||||||
if err := d.StopAndRemoveContainer(ctx); err != nil {
|
if err := d.StopAndRemoveContainer(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建容器
|
// 创建容器
|
||||||
log.Println("正在启动名为<", config.DOCKER_CONTAINER_NAME, ">的容器")
|
log.Println("正在启动名为<", config.DOCKER_CONTAINER_NAME, ">的容器")
|
||||||
resp, err := d.cli.ContainerCreate(
|
resp, err := d.cli.ContainerCreate(
|
||||||
ctx,
|
ctx,
|
||||||
&container.Config{
|
&container.Config{
|
||||||
Image: config.DOCKER_IMAGE,
|
Image: config.DOCKER_IMAGE,
|
||||||
|
Env: []string{
|
||||||
|
"DEVICE_ID=" + device.GetDeviceID(),
|
||||||
|
"LD_LIBRARY_PATH=/opt/nvidia/deepstream/deepstream/lib" +
|
||||||
|
":/opt/nvidia/deepstream/deepstream/lib/triton" +
|
||||||
|
":/opt/nvidia/deepstream/deepstream/lib/rivermax" +
|
||||||
|
":/opt/nvidia/vpi3/lib/aarch64-linux-gnu" +
|
||||||
|
":/usr/lib/aarch64-linux-gnu" +
|
||||||
|
":/usr/lib/aarch64-linux-gnu/nvidia" +
|
||||||
|
":/usr/local/cuda-12.6/lib64",
|
||||||
|
"GST_PLUGIN_PATH=/opt/nvidia/deepstream/deepstream/lib/gst-plugins",
|
||||||
|
},
|
||||||
Healthcheck: &container.HealthConfig{
|
Healthcheck: &container.HealthConfig{
|
||||||
Test: []string{"CMD-SHELL", "echo ok"},
|
Test: []string{"CMD-SHELL", "echo ok"},
|
||||||
Interval: 5 * time.Second,
|
Interval: 5 * time.Second,
|
||||||
@@ -85,11 +96,19 @@ func (d *DockerManager) RunContainer(ctx context.Context) error {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
&container.HostConfig{
|
&container.HostConfig{
|
||||||
Binds: config.DOCKER_CONTAINER_BINDS,
|
Runtime: "nvidia",
|
||||||
NetworkMode: "host", // <-- 使用宿主机网络
|
Privileged: true,
|
||||||
|
Binds: []string{
|
||||||
|
"/usr/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu:ro",
|
||||||
|
"/opt/nvidia/deepstream/deepstream/lib:/opt/nvidia/deepstream/deepstream/lib:ro",
|
||||||
|
"/opt/nvidia/vpi3/lib/aarch64-linux-gnu/:/opt/nvidia/vpi3/lib/aarch64-linux-gnu/:ro",
|
||||||
|
"/usr/local/cuda-12.6/lib64/:/usr/local/cuda-12.6/lib64/:ro",
|
||||||
|
"/tmp/argus_socket:/tmp/argus_socket",
|
||||||
},
|
},
|
||||||
nil, // NetworkConfig
|
NetworkMode: "host",
|
||||||
nil, // Platform
|
},
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
config.DOCKER_CONTAINER_NAME,
|
config.DOCKER_CONTAINER_NAME,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user