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
4285889b52
commit
3b4eae6fc9
2 changed files with 44 additions and 19 deletions
|
|
@ -1,37 +1,37 @@
|
|||
function Get-IcingaFrameworkServiceBinary()
|
||||
{
|
||||
param(
|
||||
[string]$DownloadUrl,
|
||||
[string]$InstallDir
|
||||
[string]$FrameworkServiceUrl,
|
||||
[string]$ServiceDirectory
|
||||
);
|
||||
|
||||
$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) {
|
||||
$LatestRelease = (Invoke-WebRequest -Uri 'https://github.com/LordHepipud/icinga-windows-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
|
||||
$DownloadUrl = $LatestRelease.Replace('/tag/', '/download/');
|
||||
$Tag = $DownloadUrl.Split('/')[-1];
|
||||
$DownloadUrl = [string]::Format('{0}/icinga-service-{1}.zip', $DownloadUrl, $Tag);
|
||||
$LatestRelease = (Invoke-WebRequest -Uri 'https://github.com/LordHepipud/icinga-windows-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
|
||||
$FrameworkServiceUrl = $LatestRelease.Replace('/tag/', '/download/');
|
||||
$Tag = $FrameworkServiceUrl.Split('/')[-1];
|
||||
$FrameworkServiceUrl = [string]::Format('{0}/icinga-service-{1}.zip', $FrameworkServiceUrl, $Tag);
|
||||
} 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)) {
|
||||
$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;
|
||||
if ([string]::IsNullOrEmpty($ServiceDirectory)) {
|
||||
$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) {
|
||||
New-Item -Path $InstallDir -Force -ItemType Directory | Out-Null;
|
||||
if ((Test-Path $ServiceDirectory) -eq $FALSE) {
|
||||
New-Item -Path $ServiceDirectory -Force -ItemType Directory | Out-Null;
|
||||
}
|
||||
|
||||
$ZipArchive = Join-Path -Path $InstallDir -ChildPath ($DownloadUrl.Split('/')[-1]);
|
||||
$ServiceBin = Join-Path -Path $InstallDir -ChildPath 'icinga-service.exe';
|
||||
$ZipArchive = Join-Path -Path $ServiceDirectory -ChildPath ($FrameworkServiceUrl.Split('/')[-1]);
|
||||
$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';
|
||||
}
|
||||
|
||||
|
|
@ -39,5 +39,9 @@ function Get-IcingaFrameworkServiceBinary()
|
|||
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]$Reconfigure,
|
||||
[string]$ServiceUser,
|
||||
[securestring]$ServicePass = $null
|
||||
[securestring]$ServicePass = $null,
|
||||
$InstallFrameworkService = $null,
|
||||
$FrameworkServiceUrl = $null,
|
||||
$ServiceDirectory = $null,
|
||||
$ServiceBin = $null
|
||||
);
|
||||
|
||||
[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) {
|
||||
$InstallerArguments += "-RunInstaller";
|
||||
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\var";
|
||||
Set-IcingaAcl (Get-IcingaCacheDir);
|
||||
Install-IcingaFrameworkService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null;
|
||||
Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon';
|
||||
Install-IcingaAgentBaseFeatures;
|
||||
Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $CAEndpoint -Port $CAPort -CACert $CAFile -Ticket $Ticket | Out-Null;
|
||||
Write-IcingaAgentApiConfig -Port $CAPort;
|
||||
Write-IcingaAgentZonesConfig -Endpoints $Endpoints -EndpointConnections $EndpointConnections -ParentZone $ParentZone -GlobalZones $GlobalZoneConfig -Hostname $Hostname;
|
||||
Test-IcingaAgent;
|
||||
Restart-Service icinga2;
|
||||
Restart-IcingaService 'icingapowershell';
|
||||
Restart-IcingaService 'icinga2';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue