Vulture/VNode/_software_lib/nanomq-0.22.10/start.ps1

79 lines
3.1 KiB
PowerShell

<#
___________________________________________
| J26/03/2025 - Jérémy CHOMAZ - 1.0
| Création du script
|
___________________________________________
|
Ce script à pour but d'ouvrir le broker MQTT avec la bonne congiguration
#>
# Fonction pour extraire les valeurs des sections
Function Get-ConfigSection {
param (
[string]$sectionName,
[string]$configContent
)
$sectionPattern = "$sectionName\s*{\s*([^}]*)\s*}"
if ($configContent -match $sectionPattern) {
$sectionContent = $matches[1]
$sectionProperties = @{}
foreach ($line in $sectionContent -split "`n") {
if ($line -match "(\w+)\s*=\s*(.*)") {
$propertyName = $matches[1]
$propertyValue = $matches[2]
$sectionProperties[$propertyName] = $propertyValue
}
}
return $sectionProperties
} else {
return @{}
}
}
Write-Output "Démarrage du service NanoMQ"
Start-Process -FilePath "$($PSscriptRoot)\bin\nanomq.exe" -ArgumentList "start --conf $($PSscriptRoot)\bin\nanomq.conf" -NoNewWindow
Start-Sleep -Seconds 1
If (Get-Process -Name "Nanomq"){
Write-Output "Broker MQTT lancé avec succès."
$configContent = Get-Content -Path "$($PSscriptRoot)\bin\nanomq.conf" -Raw
Write-Output "Voici le fichier de configuration utilisé ($($PSscriptRoot)\bin\nanomq.conf) :"
# Fonction pour extraire les valeurs des sections
# Extraire les sections du fichier de configuration
$mqttSection = Get-ConfigSection -sectionName "mqtt" -configContent $configContent
$listenersTcpSection = Get-ConfigSection -sectionName "listeners.tcp" -configContent $configContent
$listenersWsSection = Get-ConfigSection -sectionName "listeners.ws" -configContent $configContent
$httpServerSection = Get-ConfigSection -sectionName "http_server" -configContent $configContent
$logSection = Get-ConfigSection -sectionName "log" -configContent $configContent
$authSection = Get-ConfigSection -sectionName "auth" -configContent $configContent
# Fonction pour afficher les propriétés d'une section
function Show-SectionProperties {
param (
[hashtable]$section,
[string]$sectionName
)
Write-Output "Propriétés de la section $sectionName :"
foreach ($property in $section.GetEnumerator()) {
Write-Output "Name : $($property.Name)"
Write-Output "Value : $($property.Value)"
Write-Output "------"
}
}
# Afficher les propriétés des sections extraites
Show-SectionProperties -section $mqttSection -sectionName "mqtt"
Show-SectionProperties -section $listenersTcpSection -sectionName "listeners.tcp"
Show-SectionProperties -section $listenersWsSection -sectionName "listeners.ws"
Show-SectionProperties -section $httpServerSection -sectionName "http_server"
Show-SectionProperties -section $logSection -sectionName "log"
Show-SectionProperties -section $authSection -sectionName "auth"
} Else {
Write-Output "Le lancement du service a échoué, veuillez réessayer."
}