125 lines
5.2 KiB
PowerShell
125 lines
5.2 KiB
PowerShell
# ============================================================
|
|
# Omika - Installation du service Windows OmikaWorker (deploiement 2/6)
|
|
# ============================================================
|
|
# CIBLE : Windows Server 2025 (SRV-OMIKA), PowerShell ADMINISTRATEUR.
|
|
# NE PAS executer depuis le poste de developpement.
|
|
#
|
|
# CE QUE CE SCRIPT FAIT :
|
|
# 1. Cree les dossiers propres au Worker (journalisation, spool local).
|
|
# 2. Pose les ACL NTFS minimales (avec CONTROLE du code retour d'icacls).
|
|
# 3. Valide le compte de service (existence + droit de connexion).
|
|
# 4. Cree le service Windows OmikaWorker (idempotent, StartupType Manual).
|
|
# 5. Verifie ce qui a ete reellement cree (binaire, compte, etat).
|
|
#
|
|
# CE QU'IL NE FAIT PAS :
|
|
# - AUCUN demarrage de service.
|
|
# - AUCUN secret ecrit (variables d'environnement = action manuelle).
|
|
# - AUCUNE modification HFSQL / PostgreSQL / firewall.
|
|
# - AUCUNE copie de binaires.
|
|
#
|
|
# PREREQUIS MANUELS :
|
|
# - Compte local dedie + droit « Ouvrir une session en tant que service ».
|
|
# - Publication copiee dans <InstallRoot>\Apps\OmikaWorker (Omika.Worker.exe).
|
|
#
|
|
# NOTE SPOOL LOCAL :
|
|
# Le dossier Data\Worker\Diagnostics\Jsonl n'est utilise QUE si ce Worker doit
|
|
# forwarder ses propres diagnostics (cas serveur SEPARE de l'API, cf.
|
|
# docs\T15-RUNBOOK-DEPLOIEMENT-PRODUCTION.md §7.3). Sur un serveur unique,
|
|
# seul Omika.Api forwarde : ne pas activer DiagnosticsForwarding ici, sinon
|
|
# les evenements partiront DEUX FOIS (un par service).
|
|
#
|
|
# IDEMPOTENT - prend en charge -WhatIf.
|
|
#
|
|
# EXEMPLES :
|
|
# .\Install-OmikaWorker.ps1
|
|
# .\Install-OmikaWorker.ps1 -WhatIf
|
|
# .\Install-OmikaWorker.ps1 -Desinstaller
|
|
# ============================================================
|
|
|
|
[CmdletBinding(SupportsShouldProcess = $true)]
|
|
param(
|
|
[string]$InstallRoot = 'C:\Omika',
|
|
[string]$ServiceName = 'OmikaWorker',
|
|
[string]$Account = '.\svc_omika_worker',
|
|
|
|
[ValidateSet('Manual', 'Automatic', 'Disabled')]
|
|
[string]$StartupType = 'Manual',
|
|
|
|
[switch]$Desinstaller
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
Import-Module (Join-Path $PSScriptRoot 'Omika.Deploy.Common.psm1') -Force
|
|
|
|
# Le module a son propre etat de session : $WhatIfPreference ne s'y propage pas.
|
|
$Simulation = [bool]$WhatIfPreference
|
|
|
|
# --- Definition du service ---------------------------------------------------
|
|
$NomAffiche = 'Omika Worker'
|
|
$DossierApps = 'OmikaWorker'
|
|
$Executable = 'Omika.Worker.exe'
|
|
$Description = 'Omika - Worker de synchronisation metier (HFSQL) : traitement de la file de synchronisation et des reprises.'
|
|
|
|
$DossiersModifier = @(
|
|
'Logs\Worker',
|
|
'Data\Worker\Diagnostics\Jsonl'
|
|
)
|
|
|
|
try {
|
|
Assert-OmikaAdmin
|
|
$chemins = Get-OmikaPaths -InstallRoot $InstallRoot
|
|
$cheminExe = Join-Path (Join-Path $chemins.Apps $DossierApps) $Executable
|
|
|
|
# --- Rollback ------------------------------------------------------------
|
|
if ($Desinstaller) {
|
|
Write-OmikaStep "Desinstallation du service $ServiceName"
|
|
Remove-OmikaService -Name $ServiceName -WhatIf:$Simulation | Out-Null
|
|
Write-OmikaServiceSummary -Name $ServiceName -Supprime
|
|
exit 0
|
|
}
|
|
|
|
# --- 1. Dossiers ---------------------------------------------------------
|
|
Write-OmikaStep 'Dossiers du service'
|
|
foreach ($relatif in $DossiersModifier) {
|
|
New-OmikaDirectory -Path (Join-Path $InstallRoot $relatif) -WhatIf:$Simulation | Out-Null
|
|
}
|
|
|
|
# --- 2. ACL --------------------------------------------------------------
|
|
Write-OmikaStep 'ACL NTFS minimales'
|
|
foreach ($relatif in $DossiersModifier) {
|
|
Grant-OmikaAcl -Path (Join-Path $InstallRoot $relatif) -Account $Account -Right 'M' `
|
|
-RequireExisting -WhatIf:$Simulation | Out-Null
|
|
}
|
|
|
|
# --- 3. Compte de service ------------------------------------------------
|
|
Write-OmikaStep 'Compte de service'
|
|
Assert-OmikaServiceAccount -Account $Account | Out-Null
|
|
|
|
# --- 4. Service Windows --------------------------------------------------
|
|
Write-OmikaStep "Creation du service Windows ($StartupType)"
|
|
Install-OmikaService -Name $ServiceName -DisplayName $NomAffiche `
|
|
-ExePath $cheminExe -Account $Account -Description $Description `
|
|
-StartupType $StartupType -WhatIf:$Simulation | Out-Null
|
|
|
|
# --- 5. Recapitulatif ----------------------------------------------------
|
|
Write-OmikaServiceSummary -Name $ServiceName -ExePath $cheminExe -Account $Account -Rappels @(
|
|
'Injecter les secrets en variables MACHINE (aucun secret dans ce script) :'
|
|
' Hfsql / SyncConnection (secrets HFSQL existants)'
|
|
' DiagnosticDeployment__ClientCode / __ServerInstanceId'
|
|
' ASPNETCORE_ENVIRONMENT=Production'
|
|
'UNIQUEMENT si ce Worker est sur un serveur DIFFERENT de l''API (multi-serveur) :'
|
|
' DiagnosticsForwarding__Enabled=true'
|
|
' DiagnosticsForwarding__Endpoint=https://<central>/api/v1/diagnostics/batches'
|
|
' DiagnosticsForwarding__ApiKey=<cle du client Worker>'
|
|
' Observability__Remote__Directory=<dossier LOCAL au Worker>'
|
|
'Sur un serveur unique : laisser DiagnosticsForwarding desactive (sinon double envoi).'
|
|
)
|
|
|
|
exit 0
|
|
}
|
|
catch {
|
|
Write-OmikaFail $_.Exception.Message
|
|
exit 1
|
|
}
|