From 9125d3c14d5a959d122a8bc9a764aa45b0ce4dfe Mon Sep 17 00:00:00 2001 From: "carlo.maiorano" Date: Mon, 13 Nov 2017 16:06:31 +0100 Subject: [PATCH] added windows service installation and uninstallation scripts, updated readme --- .travis.yml | 2 ++ README.md | 18 +++++++++++++--- script/win-service-install.ps1 | 36 ++++++++++++++++++++++++++++++++ script/win-service-uninstall.ps1 | 2 ++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 script/win-service-install.ps1 create mode 100644 script/win-service-uninstall.ps1 diff --git a/.travis.yml b/.travis.yml index c22a4aa..e19467d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ script: - GOOS="linux" GOARCH=arm go build -v -o bin/arm/sleeponlan main.go before_deploy: +- cp script/win-service-install.ps1 bin/win/win-service-install.ps1 +- cp script/win-service-uninstall.ps1 bin/win/win-service-uninstall.ps1 - zip -r bin/sleeponlan-x86.zip bin/x86/ - zip -r bin/sleeponlan-win.zip bin/win/ - zip -r bin/sleeponlan-arm.zip bin/arm/ diff --git a/README.md b/README.md index 294ebba..105e7f1 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,25 @@ curl -X POST http://your-pc-ip:7740/poweroff #This will shutdown your pc ``` ## Installation -You can download binaries from [release](https://github.com/charliemaiors/sleep-on-lan/releases) or run: +You can download binaries from [release](https://github.com/charliemaiors/sleep-on-lan/releases), unzip it and run from a powershell or run: ```bash go get github.com/charliemaiors/sleep-on-lan/ ``` - and run: ```bash sudo $GOPATH/bin/sleeponlan -``` \ No newline at end of file +``` +## Service + +Sleep on lan could be installed also as a service in your os using this syntax: + +```bash +./sleeponlan install [--port ] +``` +on linux, currently on windows the service is installed but it will not start so there is a script inside the script folder (if you get the executable using ```go get```) or inside the windows binary archive from [releases](https://github.com/charliemaiors/sleep-on-lan/releases) page in order to install and run it. +In order to uninstall it you could run +```bash +./sleeponlan uninstall +``` +on linux systems, there is also a temporary (hopefully) uninstall script in windows binary archive or script folder. \ No newline at end of file diff --git a/script/win-service-install.ps1 b/script/win-service-install.ps1 new file mode 100644 index 0000000..c720ed2 --- /dev/null +++ b/script/win-service-install.ps1 @@ -0,0 +1,36 @@ +Write-Host "Checking if Chocolatey is installed" + +if ((Get-Command "choco" -ErrorAction SilentlyContinue) -eq $null) +{ + Write-Host "Unable to find Chocolatey (choco) in your PATH, please install it from https://chocolatey.org/" + exit +} + +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 "Check if nssm is installed" + +if ((Get-Command "nssm" -ErrorAction SilentlyContinue) -eq $null) +{ + choco install -y nssm +} + +if (Test-Path "$env:GOPATH\bin\sleeponlan.exe") +{ + $path="$env:GOPATH\bin\sleeponlan.exe" +} else { + $path = Read-Host 'Please insert the full path where sleeponlan.exe is installed' +} + +$port = Read-Host 'Please insert the port number where you want to map your service' +nssm install sleeponlan "$path" +nssm set sleeponlan AppParameters "--port $port" +nssm set sleeponlan DisplayName "Sleep on Lan service" +nssm set sleeponlan Description "Simple Sleep on Lan service" +nssm start sleeponlan diff --git a/script/win-service-uninstall.ps1 b/script/win-service-uninstall.ps1 new file mode 100644 index 0000000..a7a7313 --- /dev/null +++ b/script/win-service-uninstall.ps1 @@ -0,0 +1,2 @@ +nssm stop sleeponlan +nssm remove sleeponlan \ No newline at end of file