Обновить Install_act_runnerx64.ps1
This commit is contained in:
@@ -1,91 +1,94 @@
|
||||
# ================================================================= #
|
||||
# SMART INSTALLER: ACT_RUNNER + NSSM + SYSTEM LABELS (STRICT MODE)
|
||||
# ================================================================= #
|
||||
$workDir = "C:\act_runner"
|
||||
$exeUrl = "https://git.dadehard.ru/kalugin66/act_runner/raw/branch/main/act_runner-0.4.0-windows-amd64.exe"
|
||||
$nssmUrl = "https://git.dadehard.ru/kalugin66/act_runner/raw/branch/main/nssm.exe"
|
||||
$instanceUrl = "https://git.dadehard.ru/"
|
||||
$token = "UzVNobPFBJe8ZoQXwu5ZamfgqCpTJZGR3LDVnX7N"
|
||||
$serviceName = "act_runner"
|
||||
|
||||
# 1. Сбор системной информации (Строгая инициализация)
|
||||
$pcName = [System.Net.Dns]::GetHostName()
|
||||
$arch = if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" }
|
||||
$memRaw = (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory
|
||||
$memGB = [math]::Round($memRaw / 1GB)
|
||||
$memLabel = "$($memGB)GB_RAM"
|
||||
$fullLabels = "windows-latest:host,windows-amd64:host,self-hosted:host,$pcName:host,$arch:host,$memLabel:host"
|
||||
|
||||
Write-Host "--- Данные системы: ПК=$pcName, Архитектура=$arch, ОЗУ=$memLabel ---" -ForegroundColor Magenta
|
||||
|
||||
# 2. Подготовка окружения
|
||||
if (-not (Test-Path $workDir)) { New-Item -ItemType Directory -Path $workDir | Out-Null }
|
||||
Set-Location $workDir
|
||||
|
||||
# 3. Очистка старых процессов
|
||||
Write-Host "--- Шаг 1: Очистка ---" -ForegroundColor Cyan
|
||||
Stop-Service $serviceName -Force -ErrorAction SilentlyContinue
|
||||
Stop-Process -Name "act_runner" -Force -ErrorAction SilentlyContinue
|
||||
sc.exe delete $serviceName | Out-Null
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
# 4. Загрузка компонентов
|
||||
Write-Host "--- Шаг 2: Загрузка EXE ---" -ForegroundColor Cyan
|
||||
if (-not (Test-Path "act_runner.exe")) { Invoke-WebRequest -Uri $exeUrl -OutFile "act_runner.exe" }
|
||||
if (-not (Test-Path "nssm.exe")) { Invoke-WebRequest -Uri $nssmUrl -OutFile "nssm.exe" }
|
||||
Unblock-File -Path "$workDir\act_runner.exe"
|
||||
Unblock-File -Path "$workDir\nssm.exe"
|
||||
|
||||
# 5. Генерация config.yaml (Метод строгого форматирования)
|
||||
Write-Host "--- Шаг 3: Формирование конфига ---" -ForegroundColor Cyan
|
||||
$template = @"
|
||||
log:
|
||||
level: info
|
||||
runner:
|
||||
file: .runner
|
||||
capacity: 1
|
||||
labels:
|
||||
- "windows-latest:host"
|
||||
- "windows-amd64:host"
|
||||
- "self-hosted:host"
|
||||
- "{0}:host"
|
||||
- "{1}:host"
|
||||
- "{2}:host"
|
||||
container:
|
||||
force_pull: false
|
||||
host:
|
||||
workdir: ""
|
||||
"@
|
||||
|
||||
# Принудительная подстановка переменных в шаблон
|
||||
$configText = $template -f $pcName, $arch, $memLabel
|
||||
|
||||
# Запись в файл (UTF8 без BOM)
|
||||
[System.IO.File]::WriteAllText("$workDir\config.yaml", $configText)
|
||||
|
||||
# 6. Проверка и регистрация
|
||||
Write-Host "--- Шаг 4: Авторизация ---" -ForegroundColor Cyan
|
||||
if (-not (Test-Path ".runner")) {
|
||||
Write-Host "Регистрация нового раннера..." -ForegroundColor Yellow
|
||||
.\act_runner.exe register --instance $instanceUrl --token $token --no-interactive --name "$pcName" --labels "$fullLabels"
|
||||
}
|
||||
|
||||
# 7. Установка службы через NSSM
|
||||
Write-Host "--- Шаг 5: Установка службы ---" -ForegroundColor Cyan
|
||||
$exePath = "$workDir\act_runner.exe"
|
||||
$args = "daemon --config `"$workDir\config.yaml`""
|
||||
|
||||
& ".\nssm.exe" install $serviceName $exePath $args
|
||||
& ".\nssm.exe" set $serviceName AppDirectory $workDir
|
||||
& ".\nssm.exe" set $serviceName Start SERVICE_AUTO_START
|
||||
& ".\nssm.exe" set $serviceName ObjectName LocalSystem
|
||||
|
||||
# 8. Запуск
|
||||
Write-Host "--- Шаг 6: Запуск ---" -ForegroundColor Cyan
|
||||
Start-Service $serviceName
|
||||
|
||||
if ((Get-Service $serviceName).Status -eq "Running") {
|
||||
Write-Host "===============================================" -ForegroundColor Green
|
||||
Write-Host "ГОТОВО! Проверьте метки в интерфейсе Gitea." -ForegroundColor Green
|
||||
Write-Host "===============================================" -ForegroundColor Green
|
||||
# ================================================================= #
|
||||
# SMART INSTALLER: ACT_RUNNER + NSSM + SYSTEM LABELS (STRICT MODE)
|
||||
# ================================================================= #
|
||||
$workDir = "C:\act_runner"
|
||||
$exeUrl = "https://git.dadehard.ru/kalugin66/act_runner/raw/branch/main/act_runner-0.4.0-windows-amd64.exe"
|
||||
$nssmUrl = "https://git.dadehard.ru/kalugin66/act_runner/raw/branch/main/nssm.exe"
|
||||
$instanceUrl = "https://git.dadehard.ru/"
|
||||
$token = "UzVNobPFBJe8ZoQXwu5ZamfgqCpTJZGR3LDVnX7N"
|
||||
$serviceName = "act_runner"
|
||||
|
||||
# 1. Сбор системной информации (С вашей меткой School25)
|
||||
$defaultLabel = "School25" # Ваша основная метка
|
||||
$pcName = [System.Net.Dns]::GetHostName()
|
||||
$arch = if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" }
|
||||
$memRaw = (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory
|
||||
$memGB = [math]::Round($memRaw / 1GB)
|
||||
$memLabel = "$($memGB)GB_RAM"
|
||||
|
||||
# Формируем полный список для регистрации в Gitea
|
||||
$fullLabels = "$defaultLabel:host,windows-amd64:host,self-hosted:host,$pcName:host,$arch:host,$memLabel:host"
|
||||
|
||||
Write-Host "--- Данные системы: ПК=$pcName, ОЗУ=$memLabel, Метка=$defaultLabel ---" -ForegroundColor Magenta
|
||||
|
||||
# 2. Подготовка окружения
|
||||
if (-not (Test-Path $workDir)) { New-Item -ItemType Directory -Path $workDir | Out-Null }
|
||||
Set-Location $workDir
|
||||
|
||||
# 3. Очистка старых процессов
|
||||
Write-Host "--- Шаг 1: Очистка ---" -ForegroundColor Cyan
|
||||
Stop-Service $serviceName -Force -ErrorAction SilentlyContinue
|
||||
Stop-Process -Name "act_runner" -Force -ErrorAction SilentlyContinue
|
||||
sc.exe delete $serviceName | Out-Null
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
# 4. Загрузка компонентов
|
||||
Write-Host "--- Шаг 2: Загрузка EXE ---" -ForegroundColor Cyan
|
||||
if (-not (Test-Path "act_runner.exe")) { Invoke-WebRequest -Uri $exeUrl -OutFile "act_runner.exe" }
|
||||
if (-not (Test-Path "nssm.exe")) { Invoke-WebRequest -Uri $nssmUrl -OutFile "nssm.exe" }
|
||||
Unblock-File -Path "$workDir\act_runner.exe"
|
||||
Unblock-File -Path "$workDir\nssm.exe"
|
||||
|
||||
# 5. Генерация config.yaml (Используем {0} для School25)
|
||||
Write-Host "--- Шаг 3: Формирование конфига ---" -ForegroundColor Cyan
|
||||
$template = @"
|
||||
log:
|
||||
level: info
|
||||
runner:
|
||||
file: .runner
|
||||
capacity: 1
|
||||
labels:
|
||||
- "{0}:host"
|
||||
- "windows-amd64:host"
|
||||
- "self-hosted:host"
|
||||
- "{1}:host"
|
||||
- "{2}:host"
|
||||
- "{3}:host"
|
||||
container:
|
||||
force_pull: false
|
||||
host:
|
||||
workdir: ""
|
||||
"@
|
||||
|
||||
# Принудительная подстановка: 0-Школа, 1-Имя ПК, 2-Архитектура, 3-Память
|
||||
$configText = $template -f $defaultLabel, $pcName, $arch, $memLabel
|
||||
|
||||
# Запись в файл (UTF8 без BOM)
|
||||
[System.IO.File]::WriteAllText("$workDir\config.yaml", $configText)
|
||||
|
||||
# 6. Проверка и регистрация
|
||||
Write-Host "--- Шаг 4: Авторизация ---" -ForegroundColor Cyan
|
||||
if (-not (Test-Path ".runner")) {
|
||||
Write-Host "Регистрация нового раннера..." -ForegroundColor Yellow
|
||||
.\act_runner.exe register --instance $instanceUrl --token $token --no-interactive --name "$pcName" --labels "$fullLabels"
|
||||
}
|
||||
|
||||
# 7. Установка службы через NSSM
|
||||
Write-Host "--- Шаг 5: Установка службы ---" -ForegroundColor Cyan
|
||||
$exePath = "$workDir\act_runner.exe"
|
||||
$args = "daemon --config `"$workDir\config.yaml`""
|
||||
|
||||
& ".\nssm.exe" install $serviceName $exePath $args
|
||||
& ".\nssm.exe" set $serviceName AppDirectory $workDir
|
||||
& ".\nssm.exe" set $serviceName Start SERVICE_AUTO_START
|
||||
& ".\nssm.exe" set $serviceName ObjectName LocalSystem
|
||||
|
||||
# 8. Запуск
|
||||
Write-Host "--- Шаг 6: Запуск ---" -ForegroundColor Cyan
|
||||
Start-Service $serviceName
|
||||
|
||||
if ((Get-Service $serviceName).Status -eq "Running") {
|
||||
Write-Host "===============================================" -ForegroundColor Green
|
||||
Write-Host "ГОТОВО! Раннер активен с меткой $defaultLabel" -ForegroundColor Green
|
||||
Write-Host "===============================================" -ForegroundColor Green
|
||||
}
|
||||
Reference in New Issue
Block a user