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