[Feature]新增初始化环境变量,自动重启错误网卡

This commit is contained in:
Zhanpeng Yang 2024-10-11 13:24:56 +08:00
parent 76d7bb336b
commit 7272901f33
2 changed files with 147 additions and 2 deletions

67
.env Normal file
View File

@ -0,0 +1,67 @@
#################################
# 数据收集相关配置
################################
#光谱相机设备型号索引
SPECTRUM_deviceTypeIndex=1
#光谱相机帧率
SPECTRUM_FrameRate=4.0
#光谱相机曝光时间
SPECTRUM_ExposureTime=10.0
#光谱相机空间像素组合设置为0空间维度为10241为5122为2563为128
SPECTRUM_BinningSpatial=1
#光谱相机光谱像素组合设置为0光谱维度为4481为2242为1123为56
SPECTRUM_BinningSpectral=1
#是否开启像素组合1为开启0为不开启
SPECTRUM_BinningAverage=1
#循环缓存区大小
SPECTRUM_RingBufferSize=2
#原始光谱数据保存路径
RAWDATA_Folder=C:/tmp/
# 每个原始光谱数据bin文件最大多少Byte, 10737418240 是10G( 10*1024*1024*1024)10485760是10M
RAWDATA_MaxSize=10737418240
#################################
# 后台服务相关配置
################################
#设备ID
NEXT_PUBLIC_DEVICE_ID=DOJHBG
#设备名字备注
NEXT_PUBLIC_DEVICE_NAME=办公室测试设备
#设备ID
ON_DEVICE_SERVER_PORT=22110
#推理服务的API
MODEL_INFERENCE_API=http://sems-model-inference:22111/post
#将炉次数据回传的API
# FURNACE_UPLOAD_API=https://3.u1227383.nyat.app:25889/api/upload
FURNACE_UPLOAD_API=http://10.8.8.8:22114/api/upload
# VIDEO_
# spectral_camera_configs:
# deviceTypeIndex: 1
# FrameRate: 4.0
# ExposureTime: 10.0
# BinningSpatial: 1
# BinningSpectral: 1
# BinningAverage: true
# RingBufferSize: 2
# visible_light_camera_configs:
# enable: false
# video_capture_index: 0
# save_configs:
# save_dir: C:/tmp/
# max_file_size: 10737418240 # 1073741824 # 10*1024*1024*1024 = 10GB 10737418240 10485760(10M)

View File

@ -3,7 +3,48 @@
$UPDATE_SOURCE = "https://1.u1227383.nyat.app:23587/api/v1/repos/zhanpeng" $UPDATE_SOURCE = "https://1.u1227383.nyat.app:23587/api/v1/repos/zhanpeng"
$TOCKEN = "e9aaae4b5f7756d0a2977764dbcbdfeb68bb2e13" $TOCKEN = "e9aaae4b5f7756d0a2977764dbcbdfeb68bb2e13"
$PRODUCTION_FOLDER = "C:\SEMS-production" $PRODUCTION_FOLDER = "C:\SEMS-production"
$RAWDATA_FOLDER = "C:\tmp" # $RAWDATA_FOLDER = "C:\tmp"
# try{
# $errorNetAdapter = Get-PnpDevice -Status ERROR -Class Net
# $errorNetAdapter | Disable-PnpDevice -Confirm:$false
# $errorNetAdapter | Enable-PnpDevice -Confirm:$false
# }catch{
# }
try {
$errorDevices = Get-CimInstance -Query "SELECT * FROM Win32_PnPEntity WHERE PNPClass = 'Net' AND Status = 'Error'"
if ( $null -eq $errorDevices -or $errorDevices.Count -eq 0) {
Write-Host "没有找到状态为ERROR的网络设备。"
}
else {
Write-Host "以下网络设备状态为ERROR 正在重启:"
$errorDevices | ForEach-Object {
Write-Host $_.DeviceID
}
$errorNetAdapter | Disable-PnpDevice -Confirm:$false
$errorNetAdapter | Enable-PnpDevice -Confirm:$false
}
}
catch [Microsoft.Management.Infrastructure.CimException] {
if ($_.Exception.Message -like '*No matching Win32_PnPEntity objects found*') {
Write-Host "没有找到状态为ERROR的网络设备。"
}
else {
Write-Host "执行命令时发生错误: $_"
}
}
catch {
Write-Host "执行命令时发生未知错误: $_"
}
if (Test-Path -Path $PRODUCTION_FOLDER -PathType Container) { if (Test-Path -Path $PRODUCTION_FOLDER -PathType Container) {
@ -205,6 +246,41 @@ else {
function Set-PermanentEnvFromDotEnv {
param (
[string]$envFilePath = ".env",
[System.EnvironmentVariableTarget]$scope = [System.EnvironmentVariableTarget]::User
)
if (-Not (Test-Path $envFilePath)) {
Write-Error "File '$envFilePath' not found."
return
}
Get-Content $envFilePath | ForEach-Object {
$line = $_.Trim()
if ($line -and -not $line.StartsWith("#")) {
$parts = $line -split "=", 2
if ($parts.Length -eq 2) {
$key = $parts[0].Trim()
$value = $parts[1].Trim()
[System.Environment]::SetEnvironmentVariable($key, $value, $scope)
# ${ENV}:$key = $value
Set-Item -Path "ENV:$key" -Value $value
}
}
}
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Output "[初始化]环境变量 $scriptDir\.env"
Set-PermanentEnvFromDotEnv -envFilePath "$scriptDir\.env" -scope User
$folders = Get-ChildItem -Path $PRODUCTION_FOLDER -Directory $folders = Get-ChildItem -Path $PRODUCTION_FOLDER -Directory
$folderDataCollection = $folders | Where-Object { $_.Name -like "*SEMS-data-collection*" } $folderDataCollection = $folders | Where-Object { $_.Name -like "*SEMS-data-collection*" }
@ -251,10 +327,12 @@ else {
} }
Write-Output "[状态]数据集路径 $env:RAWDATA_Folder"
if ($container -eq "true") { if ($container -eq "true") {
Write-Output "[状态]容器 'sems-on-device-server' 正在运行" Write-Output "[状态]容器 'sems-on-device-server' 正在运行"
} }
else { else {
Write-Output "[状态]容器 'sems-on-device-server' 不在运行,正在运行" Write-Output "[状态]容器 'sems-on-device-server' 不在运行,正在运行"
docker run --rm -d -p "22110:22110" -v "$($folderOnDeviceServer.FullName):/app" -v "${RAWDATA_FOLDER}:/data" --env-file "C:\SEMS-production\configs\.env" --name sems-on-device-server --link sems-model-inference sems-on-device-server:latest docker run --rm -d -p "22110:22110" -v "$($folderOnDeviceServer.FullName):/app" -v "$ENV:RAWDATA_Folder:/data" --env-file "C:\SEMS-production\configs\.env" --name sems-on-device-server --link sems-model-inference sems-on-device-server:latest
} }