forked from flanksource/canary-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-service.ps1
45 lines (37 loc) · 1.78 KB
/
install-service.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
param (
[string]$configfile = "$pwd\canary-checker.yaml",
[int]$httpPort = 8080,
[int]$metricsPort = 8081,
[string]$name = "local",
[switch]$uninstall = $false,
[string]$pushServers
)
Write-Host "Checking current priviledges"
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
exit
}
Write-Host "Installing nssm for use"
if (!(Test-Path ".\nssm-2.24\win64\nssm.exe"))
{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri https://nssm.cc/release/nssm-2.24.zip -OutFile nssm-2.24.zip
expand-archive -path '.\nssm-2.24.zip' -destinationpath '.'
}
if (!(Test-Path ".\canary-checker.exe") ) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri https://github.com/flanksource/canary-checker/releases/latest/download/canary-checker.exe -OutFile canary-checker.exe
}
$path="$pwd\canary-checker.exe"
if ($uninstall) {
.\nssm-2.24\win64\nssm.exe stop canary-checker
.\nssm-2.24\win64\nssm.exe remove canary-checker confirm
} else {
.\nssm-2.24\win64\nssm.exe install canary-checker "$path"
.\nssm-2.24\win64\nssm.exe set canary-checker AppParameters "serve --configfile $configfile --httpPort $httpPort --metricsPort $metricsPort --name $name --push-servers=$pushServers"
.\nssm-2.24\win64\nssm.exe set canary-checker DisplayName "Canary Checker Server"
.\nssm-2.24\win64\nssm.exe set canary-checker Description "Starts the Canary Checker Server"
.\nssm-2.24\win64\nssm.exe start canary-checker
}