Files
AI_A4000/video_worker/scripts/edge_device_wsl.ps1

55 lines
1.7 KiB
PowerShell

param(
[ValidateSet("start", "stop", "restart", "status")]
[string]$Action = "start",
[string]$Distro = ""
)
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $Root
if (!(Get-Command wsl -ErrorAction SilentlyContinue)) {
throw "WSL command not found. Please install WSL first."
}
if ([string]::IsNullOrWhiteSpace($Distro)) {
$linuxPath = (wsl -- wslpath -a "$Root").Trim()
} else {
$linuxPath = (wsl -d $Distro -- wslpath -a "$Root").Trim()
}
if ([string]::IsNullOrWhiteSpace($linuxPath)) {
throw "Failed to resolve WSL path for project root: $Root"
}
switch ($Action) {
"start" { $targetScript = "scripts/start_edge_device_local.sh" }
"stop" { $targetScript = "scripts/stop_edge_device_local.sh" }
"restart" { $targetScript = "scripts/restart_edge_device_local.sh" }
"status" { $targetScript = "" }
}
if ($Action -eq "status") {
$bashCommand = @"
cd '$linuxPath' && \
if [ -f runtime/pids/worker.pid ] && kill -0 `$(cat runtime/pids/worker.pid) >/dev/null 2>&1; then
echo "[OK] worker running pid=`$(cat runtime/pids/worker.pid)"
else
echo "[INFO] worker not running"
fi && \
if [ -f runtime/pids/edge_client.pid ] && kill -0 `$(cat runtime/pids/edge_client.pid) >/dev/null 2>&1; then
echo "[OK] edge_client running pid=`$(cat runtime/pids/edge_client.pid)"
else
echo "[INFO] edge_client not running"
fi
"@
} else {
$bashCommand = "cd '$linuxPath' && chmod +x scripts/install_wsl_env.sh scripts/start_edge_device_local.sh scripts/stop_edge_device_local.sh scripts/restart_edge_device_local.sh && bash $targetScript"
}
if ([string]::IsNullOrWhiteSpace($Distro)) {
wsl -- bash -lc "$bashCommand"
} else {
wsl -d $Distro -- bash -lc "$bashCommand"
}