From d3a2a423bd238066f989cd87527c17c84d39739e Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Wed, 17 Feb 2021 16:27:52 +0100 Subject: [PATCH] Add a service installation script using NSSM --- Install-UsingNSSM.ps1 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Install-UsingNSSM.ps1 diff --git a/Install-UsingNSSM.ps1 b/Install-UsingNSSM.ps1 new file mode 100644 index 0000000..32e1b08 --- /dev/null +++ b/Install-UsingNSSM.ps1 @@ -0,0 +1,30 @@ +$ServiceName = "citrix_collector" +# $ServiceName = "grafana" +$NSSMExecutable = "C:\Tools\NSSM\nssm-2.24-101-g897c7ad\win64\nssm.exe" + +$PSExecutable = (Get-Command Powershell).Source +$BaseDir = $PSScriptRoot + +try { + $Service = Get-Service -Name $ServiceName -ErrorAction Stop +} +catch { + Write-Host "Service $ServiceName not found, installing..." +} + +if ($null -ne $Service) { + Write-Host "Service $ServiceName is already installed! Doing nothing." + exit +} + + +# required arguments, including the path to the script +$Arguments = "-ExecutionPolicy Bypass -NoProfile -File `"$BaseDir\citrix_collector.ps1`"" + +# install the service +& $NSSMExecutable install $ServiceName $PSExecutable $Arguments + +# set a log file for stdout and stderr +& $NSSMExecutable set $ServiceName AppStdout $BaseDir\citrix_collector.log +& $NSSMExecutable set $ServiceName AppStderr $BaseDir\citrix_collector.log +& $NSSMExecutable set $ServiceName AppTimestampLog 1 -- GitLab