Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/codemodify/systemkit-service

go 1.13
go 1.14

require (
github.com/codemodify/SystemKit v1.7.4
github.com/codemodify/systemkit-helpers v1.7.7
github.com/codemodify/systemkit-logging v1.7.6
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
github.com/codemodify/SystemKit v1.7.4 h1:glqH7m+qxEQoUXWuLXhzHHLgV9sYYUPM1rRWVz66tRg=
github.com/codemodify/SystemKit v1.7.4/go.mod h1:KKn3HcCBZURVS8AbQanXxsyUbHsGhnIinVpAkSPVzXk=
github.com/codemodify/systemkit-cryptography v1.0.0/go.mod h1:xpC1R/KccPhPrmY9Vs5lcOrESMlAZfJ/xrbqrfuFve0=
github.com/codemodify/systemkit-helpers v1.7.7 h1:ITFCHhS6hSxqNhqcqwVfpzKG9JOEcX3E+4AO7uo1yXI=
github.com/codemodify/systemkit-helpers v1.7.7/go.mod h1:5jkrQySFtJYZnUnudYeuAYzbunPsAcDlQmW/kMa6rT0=
github.com/codemodify/systemkit-logging v1.7.6 h1:B43qtBemRL85bwQPsdwtspOENYB1OgHPEnZIfhB/88I=
github.com/codemodify/systemkit-logging v1.7.6/go.mod h1:CgHyiLfps+2ALdwXfTKTShMO2shacV0+jKhjQCtnz1s=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidmz/go-pageant v1.0.1 h1:kzCt64aTc557QYvy5VBSN1pVWO/tNAcqzwlpUsZ8IEE=
github.com/davidmz/go-pageant v1.0.1/go.mod h1:WWOKE/93DhgsPq15jaipH4fVY+MLKKWH4Yku5Ei92rE=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.11.0 h1:4Zv0OGbpkg4yNuUtH0s8rvoYxRCNyT29NVUo6pgPmxI=
github.com/pkg/sftp v1.11.0/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/sfreiberg/simplessh v0.0.0-20180301191542-495cbb862a9c h1:7Q+2oF0uBoLEV+j13E3/xUkPkI7f+sFNPZOPo2jmrWk=
github.com/sfreiberg/simplessh v0.0.0-20180301191542-495cbb862a9c/go.mod h1:sB7d6wQapoRM+qx5MgQYB6JVHtel4YHRr0NXXCkXiwQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200208060501-ecb85df21340/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
79 changes: 73 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# ![](https://fonts.gstatic.com/s/i/materialicons/bookmarks/v4/24px.svg) Service
[![GoDoc](https://godoc.org/github.com/codemodify/SystemKit?status.svg)](https://godoc.org/github.com/codemodify/SystemKit)
[![0-License](https://img.shields.io/badge/license-0--license-brightgreen)](https://github.com/codemodify/TheFreeLicense)
[![Go Report Card](https://goreportcard.com/badge/github.com/codemodify/SystemKit)](https://goreportcard.com/report/github.com/codemodify/SystemKit)
[![Test Status](https://github.com/danawoodman/systemservice/workflows/Test/badge.svg)](https://github.com/danawoodman/systemservice/actions)
![code size](https://img.shields.io/github/languages/code-size/codemodify/SystemKit?style=flat-square)
[![](https://img.shields.io/github/v/release/codemodify/systemkit-service?style=flat-square)](https://github.com/codemodify/systemkit-service/releases/latest)
![](https://img.shields.io/github/languages/code-size/codemodify/systemkit-service?style=flat-square)
![](https://img.shields.io/github/last-commit/codemodify/systemkit-service?style=flat-square)
[![](https://img.shields.io/badge/license-0--license-brightgreen?style=flat-square)](https://github.com/codemodify/TheFreeLicense)

![](https://img.shields.io/github/workflow/status/codemodify/systemkit-service/qa?style=flat-square)
![](https://img.shields.io/github/issues/codemodify/systemkit-service?style=flat-square)
[![](https://goreportcard.com/badge/github.com/codemodify/systemkit-service?style=flat-square)](https://goreportcard.com/report/github.com/codemodify/systemkit-service)

[![](https://img.shields.io/badge/godoc-reference-brightgreen?style=flat-square)](https://godoc.org/github.com/codemodify/systemkit-service)
![](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)
![](https://img.shields.io/gitter/room/codemodify/systemkit-service?style=flat-square)

![](https://img.shields.io/github/contributors/codemodify/systemkit-service?style=flat-square)
![](https://img.shields.io/github/stars/codemodify/systemkit-service?style=flat-square)
![](https://img.shields.io/github/watchers/codemodify/systemkit-service?style=flat-square)
![](https://img.shields.io/github/forks/codemodify/systemkit-service?style=flat-square)


#### Robust Cross platform Create/Start/Stop/Delete system or user service

Expand All @@ -12,4 +25,58 @@
# ![](https://fonts.gstatic.com/s/i/materialicons/bookmarks/v4/24px.svg) Install
```go
go get github.com/codemodify/systemkit-service
```
```

# ![](https://fonts.gstatic.com/s/i/materialicons/bookmarks/v4/24px.svg) API

  |  
--- | ---
service := Service.New() | Create a new system service
service.Install(false) | Install a new system service
service.Install(true) | Install a new system service and start
service.Start() | Start system service
service.Restart() | Restart system service
service.Status() | System service status
service.Stop() | Stop system service
service.Uninstall() | Uninstall system service


# ![](https://fonts.gstatic.com/s/i/materialicons/bookmarks/v4/24px.svg) Usage
```go
package main

import (
"fmt"

"https://github.com/codemodify/systemkit-service/"
)

func main() {

// Create service definition

usr, _ := user.Current()
service := Service.New(Service.Command{
Name: "MY_SERVICE",
DisplayLabel: "My Service",
Description: "This service is a test service",
DocumentationURL: "",
Executable: usr.HomeDir + "/Downloads/service.sh"),
Args: []string{""},
WorkingDirectory: usr.HomeDir,
})

// Instal and start

err := service.Install(true)
if err != nil {
fmt.Println(err.Error())
}
}

// Done
```

---

> `IMPORTANT NOTE:`<br>If this is executed as `SUDO` then a system service will be created instead of user service
29 changes: 29 additions & 0 deletions samples/MacOSX/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// +build darwin

package main

import (
"fmt"
"os/user"

"github.com/codemodify/SystemKit/Service"
)

func main() {
usr, _ := user.Current()

service := Service.New(Service.Command{
Name: "MY_SERVICE",
DisplayLabel: "My Service",
Description: "This service is a test service",
DocumentationURL: "",
Executable: usr.HomeDir + "/Downloads/service.sh",
Args: []string{""},
WorkingDirectory: usr.HomeDir,
})

err := service.Install(true)
if err != nil {
fmt.Println(err.Error())
}
}
74 changes: 74 additions & 0 deletions samples/MacOSX/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ![](https://fonts.gstatic.com/s/i/materialicons/label_important/v4/24px.svg) Service
[![GoDoc](https://godoc.org/github.com/codemodify/SystemKit?status.svg)](https://godoc.org/github.com/codemodify/SystemKit)
[![0-License](https://img.shields.io/badge/license-0--license-brightgreen)](https://github.com/codemodify/TheFreeLicense)
[![Go Report Card](https://goreportcard.com/badge/github.com/codemodify/SystemKit)](https://goreportcard.com/report/github.com/codemodify/SystemKit)
[![Test Status](https://github.com/danawoodman/systemservice/workflows/Test/badge.svg)](https://github.com/danawoodman/systemservice/actions)
![code size](https://img.shields.io/github/languages/code-size/codemodify/SystemKit?style=flat-square)

# Cross platform <h3> `CREATE/START/STOP/UNINSTALL` SYSTEM / USER SERVICE
## How to use?

# ![](https://fonts.gstatic.com/s/i/materialicons/label_important/v4/24px.svg) MacOS ![](https://img.icons8.com/ios-filled/30/000000/mac-os.png)
- Download a sample service definiton from here and save/extract to your `~/Downloads` folder:

> `https://github.com/codemodify/systemkit-service/samples/service.sh`

```go
package main

import (
"fmt"

"https://github.com/codemodify/systemkit-service/"
)

func main() {

// Create service definition

usr, _ := user.Current()
service := Service.New(Service.Command{
Name: "MY_SERVICE",
DisplayLabel: "My Service",
Description: "This service is a test service",
DocumentationURL: "",
Executable: usr.HomeDir + "/Downloads/service.sh"),
Args: []string{""},
WorkingDirectory: usr.HomeDir,
})

// Instal and start

err := service.Install(true)
if err != nil {
fmt.Println(err.Error())
}
}

// Done
```

---
#### `INSTALL WITHOUT START `
```go
err := service.Install(false)
if err != nil {
fmt.Println(err.Error())

```
---
#### `STOP SERVICE `
```go
err := service.Stop
if err != nil {
fmt.Println(err.Error())
```
#### `UNINSTALL SERVICE `
```go
err := service.Uninstall
if err != nil {
fmt.Println(err.Error())
```
---
#### `IMPORTANT NOTE`
### If this is executed as `SUDO` then a system service will be created instead of user service
6 changes: 6 additions & 0 deletions samples/MacOSX/service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
NEXT_WAIT_TIME=0
until say 'done' && [ $NEXT_WAIT_TIME -eq 4 ]; do
$(( NEXT_WAIT_TIME++ ))
sleep 5s
done
2 changes: 1 addition & 1 deletion system-service_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (thisRef MacOSService) Install(start bool) error {

// Start -
func (thisRef MacOSService) Start() error {
// 1.

output, _ := runLaunchCtlCommand("load", "-w", thisRef.FilePath())
if strings.Contains(output, "No such file or directory") {
return ErrServiceDoesNotExist
Expand Down
24 changes: 0 additions & 24 deletions tests-as-root/main.go

This file was deleted.

14 changes: 0 additions & 14 deletions tests/helpers_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,3 @@ func createRandomService() service.SystemService {
RunAsUser: "user",
})
}

func CreateRemoteitService() service.SystemService {
return service.New(service.Command{
Name: "it.remote.cli",
DisplayLabel: "it.remote.cli",
Description: "it.remote.cli",
DocumentationURL: "",
Executable: "/Users/nicolae/Downloads/remoteit_mac-osx_x86_64",
Args: []string{"watch", "-v", "-c", "/etc/remoteit/config.json"},
WorkingDirectory: "",
StdOutPath: "null",
RunAsUser: "user",
})
}
2 changes: 1 addition & 1 deletion tests/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func Test_install(t *testing.T) {
service := CreateRemoteitService()
service := createService()

err := service.Install(false)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func Test_restart(t *testing.T) {
service := CreateRemoteitService()
service := createService()

err := service.Restart()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func Test_start(t *testing.T) {
service := CreateRemoteitService()
service := createService()

err := service.Start()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func Test_status(t *testing.T) {
service := CreateRemoteitService()
service := createService()

serviceStatus := service.Status()
if serviceStatus.Error != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func Test_stop(t *testing.T) {
systemService := CreateRemoteitService()
systemService := createService()

err := systemService.Stop()
if helpersErrors.Is(err, service.ErrServiceDoesNotExist) {
Expand Down
2 changes: 1 addition & 1 deletion tests/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func Test_uninstall(t *testing.T) {
service := CreateRemoteitService()
service := createService()

err := service.Uninstall()
if err != nil {
Expand Down