mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Extend setup wizard with powershell framework service
This commit is contained in:
parent
f4d349e396
commit
80bd15e47f
2 changed files with 44 additions and 19 deletions
|
|
@ -1,37 +1,37 @@
|
||||||
function Get-IcingaFrameworkServiceBinary()
|
function Get-IcingaFrameworkServiceBinary()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[string]$DownloadUrl,
|
[string]$FrameworkServiceUrl,
|
||||||
[string]$InstallDir
|
[string]$ServiceDirectory
|
||||||
);
|
);
|
||||||
|
|
||||||
$ProgressPreference = "SilentlyContinue";
|
$ProgressPreference = "SilentlyContinue";
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($DownloadUrl)) {
|
if ([string]::IsNullOrEmpty($FrameworkServiceUrl)) {
|
||||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
|
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
|
||||||
$LatestRelease = (Invoke-WebRequest -Uri 'https://github.com/LordHepipud/icinga-windows-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
|
$LatestRelease = (Invoke-WebRequest -Uri 'https://github.com/LordHepipud/icinga-windows-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
|
||||||
$DownloadUrl = $LatestRelease.Replace('/tag/', '/download/');
|
$FrameworkServiceUrl = $LatestRelease.Replace('/tag/', '/download/');
|
||||||
$Tag = $DownloadUrl.Split('/')[-1];
|
$Tag = $FrameworkServiceUrl.Split('/')[-1];
|
||||||
$DownloadUrl = [string]::Format('{0}/icinga-service-{1}.zip', $DownloadUrl, $Tag);
|
$FrameworkServiceUrl = [string]::Format('{0}/icinga-service-{1}.zip', $FrameworkServiceUrl, $Tag);
|
||||||
} else {
|
} else {
|
||||||
$DownloadUrl = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the full path to your service binary repository' -Default 'v').answer;
|
$FrameworkServiceUrl = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the full path to your service binary repository' -Default 'v').answer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($InstallDir)) {
|
if ([string]::IsNullOrEmpty($ServiceDirectory)) {
|
||||||
$InstallDir = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the path you wish to install the service to' -Default 'v' -DefaultInput 'C:\Program Files\icinga-framework-service\').answer;
|
$ServiceDirectory = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the path you wish to install the service to' -Default 'v' -DefaultInput 'C:\Program Files\icinga-framework-service\').answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Test-Path $InstallDir) -eq $FALSE) {
|
if ((Test-Path $ServiceDirectory) -eq $FALSE) {
|
||||||
New-Item -Path $InstallDir -Force -ItemType Directory | Out-Null;
|
New-Item -Path $ServiceDirectory -Force -ItemType Directory | Out-Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ZipArchive = Join-Path -Path $InstallDir -ChildPath ($DownloadUrl.Split('/')[-1]);
|
$ZipArchive = Join-Path -Path $ServiceDirectory -ChildPath ($FrameworkServiceUrl.Split('/')[-1]);
|
||||||
$ServiceBin = Join-Path -Path $InstallDir -ChildPath 'icinga-service.exe';
|
$ServiceBin = Join-Path -Path $ServiceDirectory -ChildPath 'icinga-service.exe';
|
||||||
|
|
||||||
Invoke-WebRequest -Uri $DownloadUrl -UseBasicParsing -OutFile $ZipArchive;
|
Invoke-WebRequest -Uri $FrameworkServiceUrl -UseBasicParsing -OutFile $ZipArchive;
|
||||||
|
|
||||||
if ((Expand-IcingaZipArchive -Path $ZipArchive -Destination $InstallDir) -eq $FALSE) {
|
if ((Expand-IcingaZipArchive -Path $ZipArchive -Destination $ServiceDirectory) -eq $FALSE) {
|
||||||
throw 'Failed to expand the downloaded ZIP archive';
|
throw 'Failed to expand the downloaded ZIP archive';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,5 +39,9 @@ function Get-IcingaFrameworkServiceBinary()
|
||||||
throw 'The checksum of the downloaded file and the required MD5 hash are not matching';
|
throw 'The checksum of the downloaded file and the required MD5 hash are not matching';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ServiceBin;
|
return @{
|
||||||
|
'FrameworkServiceUrl' = $FrameworkServiceUrl;
|
||||||
|
'ServiceDirectory' = $ServiceDirectory;
|
||||||
|
'ServiceBin' = $ServiceBin;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,11 @@ function Start-IcingaAgentInstallWizard()
|
||||||
[switch]$RunInstaller,
|
[switch]$RunInstaller,
|
||||||
[switch]$Reconfigure,
|
[switch]$Reconfigure,
|
||||||
[string]$ServiceUser,
|
[string]$ServiceUser,
|
||||||
[securestring]$ServicePass = $null
|
[securestring]$ServicePass = $null,
|
||||||
|
$InstallFrameworkService = $null,
|
||||||
|
$FrameworkServiceUrl = $null,
|
||||||
|
$ServiceDirectory = $null,
|
||||||
|
$ServiceBin = $null
|
||||||
);
|
);
|
||||||
|
|
||||||
[array]$InstallerArguments = @();
|
[array]$InstallerArguments = @();
|
||||||
|
|
@ -249,6 +253,20 @@ function Start-IcingaAgentInstallWizard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($null -eq $InstallFrameworkService) {
|
||||||
|
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the PowerShell Framework as Service?' -Default 'y').result -eq 1) {
|
||||||
|
$result = Get-IcingaFrameworkServiceBinary;
|
||||||
|
$InstallerArguments += "-InstallFrameworkService 1";
|
||||||
|
$InstallerArguments += [string]::Format("-FrameworkServiceUrl '{0}'", $result.FrameworkServiceUrl);
|
||||||
|
$InstallerArguments += [string]::Format("-ServiceDirectory '{0}'", $result.ServiceDirectory);
|
||||||
|
$InstallerArguments += [string]::Format("-ServiceBin '{0}'", $result.ServiceBin);
|
||||||
|
$ServiceBin = $result.ServiceBin;
|
||||||
|
}
|
||||||
|
} elseif ($InstallFrameworkService -eq $TRUE) {
|
||||||
|
$result = Get-IcingaFrameworkServiceBinary -FrameworkServiceUrl $FrameworkServiceUrl -ServiceDirectory $ServiceDirectory;
|
||||||
|
$ServiceBin = $result.ServiceBin;
|
||||||
|
}
|
||||||
|
|
||||||
if ($InstallerArguments.Count -ne 0) {
|
if ($InstallerArguments.Count -ne 0) {
|
||||||
$InstallerArguments += "-RunInstaller";
|
$InstallerArguments += "-RunInstaller";
|
||||||
Write-Host 'The wizard is complete. These are the configured settings:';
|
Write-Host 'The wizard is complete. These are the configured settings:';
|
||||||
|
|
@ -276,12 +294,15 @@ function Start-IcingaAgentInstallWizard()
|
||||||
Set-IcingaAcl "$Env:ProgramData\icinga2\etc";
|
Set-IcingaAcl "$Env:ProgramData\icinga2\etc";
|
||||||
Set-IcingaAcl "$Env:ProgramData\icinga2\var";
|
Set-IcingaAcl "$Env:ProgramData\icinga2\var";
|
||||||
Set-IcingaAcl (Get-IcingaCacheDir);
|
Set-IcingaAcl (Get-IcingaCacheDir);
|
||||||
|
Install-IcingaFrameworkService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null;
|
||||||
|
Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon';
|
||||||
Install-IcingaAgentBaseFeatures;
|
Install-IcingaAgentBaseFeatures;
|
||||||
Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $CAEndpoint -Port $CAPort -CACert $CAFile -Ticket $Ticket | Out-Null;
|
Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $CAEndpoint -Port $CAPort -CACert $CAFile -Ticket $Ticket | Out-Null;
|
||||||
Write-IcingaAgentApiConfig -Port $CAPort;
|
Write-IcingaAgentApiConfig -Port $CAPort;
|
||||||
Write-IcingaAgentZonesConfig -Endpoints $Endpoints -EndpointConnections $EndpointConnections -ParentZone $ParentZone -GlobalZones $GlobalZoneConfig -Hostname $Hostname;
|
Write-IcingaAgentZonesConfig -Endpoints $Endpoints -EndpointConnections $EndpointConnections -ParentZone $ParentZone -GlobalZones $GlobalZoneConfig -Hostname $Hostname;
|
||||||
Test-IcingaAgent;
|
Test-IcingaAgent;
|
||||||
Restart-Service icinga2;
|
Restart-IcingaService 'icingapowershell';
|
||||||
|
Restart-IcingaService 'icinga2';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue