From 3c6f45c724e9db84d9a255466b011c60ac57c7e9 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 29 May 2020 09:21:09 +0200 Subject: [PATCH] [Ingest Manager] Fix install service script for windows (#18814) [Ingest Manager] Fix install service script for windows (#18814) --- dev-tools/packaging/packages.yml | 2 +- .../install-service-elastic-agent.ps1.tmpl | 20 +++++++++++++++++++ x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 dev-tools/packaging/templates/windows/install-service-elastic-agent.ps1.tmpl diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index 6a7ce53c075..283273178bc 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -144,7 +144,7 @@ shared: files: <<: *agent_binary_files install-service-{{.BeatName}}.ps1: - template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/windows/install-service.ps1.tmpl' + template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/windows/install-service-elastic-agent.ps1.tmpl' mode: 0755 uninstall-service-{{.BeatName}}.ps1: template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/windows/uninstall-service.ps1.tmpl' diff --git a/dev-tools/packaging/templates/windows/install-service-elastic-agent.ps1.tmpl b/dev-tools/packaging/templates/windows/install-service-elastic-agent.ps1.tmpl new file mode 100644 index 00000000000..58fd5b63b9f --- /dev/null +++ b/dev-tools/packaging/templates/windows/install-service-elastic-agent.ps1.tmpl @@ -0,0 +1,20 @@ +# Delete and stop the service if it already exists. +if (Get-Service {{.BeatName}} -ErrorAction SilentlyContinue) { + $service = Get-WmiObject -Class Win32_Service -Filter "name='{{.BeatName}}'" + $service.StopService() + Start-Sleep -s 1 + $service.delete() +} + +$workdir = Split-Path $MyInvocation.MyCommand.Path + +# Create the new service. +New-Service -name {{.BeatName}} ` + -displayName {{.BeatName | title}} ` + -binaryPathName "`"$workdir\{{.BeatName}}.exe`" --path.home `"$workdir`" --path.data `"$workdir\data`" run" + +# Attempt to set the service to delayed start using sc config. +Try { + Start-Process -FilePath sc.exe -ArgumentList 'config {{.BeatName}} start= delayed-auto' +} +Catch { Write-Host -f red "An error occured setting the service to delayed start." } diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 6f5abac1174..da1995ced79 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -42,6 +42,7 @@ - Avoid watching monitor logs {pull}18723[18723] - Correctly report platform and family. {issue}18665[18665] - Guard against empty stream.datasource and namespace {pull}18769[18769] +- Fix install service script for windows {pull}18814[18814] ==== New features