forked from getlantern/lantern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_install.ps1
More file actions
35 lines (27 loc) · 995 Bytes
/
service_install.ps1
File metadata and controls
35 lines (27 loc) · 995 Bytes
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
param(
[string]$Name = "LanternSvc",
[string]$Exe = "$PSScriptRoot\..\..\bin\windows-amd64\lanternsvc.exe",
[string]$Args = "--service",
[string]$DisplayName = "Lantern Service (dev)"
)
$ErrorActionPreference = "Stop"
$ExeFull = (Resolve-Path $Exe).Path
if (-not (Test-Path $ExeFull)) {
throw "Service binary not found at $ExeFull"
}
$svc = Get-Service -Name $Name -ErrorAction SilentlyContinue
if ($svc) {
if ($svc.Status -ne 'Stopped') { sc.exe stop $Name | Out-Null }
sc.exe delete $Name | Out-Null
Start-Sleep -Milliseconds 500
}
$binPath = "`"$ExeFull`" $Args"
sc.exe create $Name binPath= "$binPath" obj= LocalSystem start= demand DisplayName= "$DisplayName" | Out-Null
sc.exe failure $Name reset= 60 actions= restart/5000/restart/5000/""/5000 | Out-Null
sc.exe failureflag $Name 1 | Out-Null
sc.exe description $Name "Lantern dev service" | Out-Null
# Start service
sc.exe start $Name
Write-Host "`nService created and started."
sc.exe qc $Name
sc.exe query $Name