Skip to content

Commit 3bf6e76

Browse files
committed
Merge branch 'release/0.8.4'
2 parents 7879db8 + 8bcf07b commit 3bf6e76

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

daemon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
/*
6-
Package daemon 0.8.3 for use with Go (golang) services.
6+
Package daemon 0.8.4 for use with Go (golang) services.
77
88
Package daemon provides primitives for daemonization of golang services.
99
This package is not provide implementation of user daemon,
@@ -99,7 +99,7 @@ Example:
9999
stdlog.Println("Stoping listening on ", listener.Addr())
100100
listener.Close()
101101
if killSignal == os.Interrupt {
102-
return "Daemon was interruped by system signal", nil
102+
return "Daemon was interrupted by system signal", nil
103103
}
104104
return "Daemon was killed", nil
105105
}

daemon_freebsd.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ package daemon
55
import "C"
66

77
import (
8-
"unsafe"
9-
"fmt"
108
"bytes"
11-
"path/filepath"
9+
"fmt"
10+
"io/ioutil"
1211
"os"
1312
"os/exec"
13+
"path/filepath"
1414
"regexp"
1515
"strings"
1616
"text/template"
17-
"io/ioutil"
17+
"unsafe"
1818
)
1919

20-
2120
// systemVRecord - standard record (struct) for linux systemV version of daemon package
2221
type bsdRecord struct {
2322
name string
@@ -52,19 +51,18 @@ func (bsd *bsdRecord) isEnabled() (bool, error) {
5251
r, _ := regexp.Compile(`.*` + bsd.name + `_enable="YES".*`)
5352
v := string(r.Find(rcData))
5453
var chrFound, sharpFound bool
55-
for _, c := range(v){
56-
if c == '#' && !chrFound{
54+
for _, c := range v {
55+
if c == '#' && !chrFound {
5756
sharpFound = true
5857
break
59-
}else if !sharpFound && c != ' '{
58+
} else if !sharpFound && c != ' ' {
6059
chrFound = true
6160
break
6261
}
6362
}
6463
return chrFound, nil
6564
}
6665

67-
6866
func (bsd *bsdRecord) getCmd(cmd string) string {
6967
if ok, err := bsd.isEnabled(); !ok || err != nil {
7068
fmt.Println("Service is not enabled, using one" + cmd + " instead")
@@ -73,7 +71,6 @@ func (bsd *bsdRecord) getCmd(cmd string) string {
7371
return cmd
7472
}
7573

76-
7774
// Get the daemon properly
7875
func newDaemon(name, description string, dependencies []string) (Daemon, error) {
7976
return &bsdRecord{name, description, dependencies}, nil
@@ -111,7 +108,6 @@ func execPath() (string, error) {
111108
return filepath.Clean(exePathString), nil
112109
}
113110

114-
115111
// Check service is running
116112
func (bsd *bsdRecord) checkRunning() (string, bool) {
117113
output, err := exec.Command("service", bsd.name, bsd.getCmd("status")).Output()
@@ -194,7 +190,6 @@ func (bsd *bsdRecord) Remove() (string, error) {
194190
return removeAction + success, nil
195191
}
196192

197-
198193
// Start the service
199194
func (bsd *bsdRecord) Start() (string, error) {
200195
startAction := "Starting " + bsd.description + ":"
@@ -280,4 +275,3 @@ start_cmd="/usr/sbin/daemon -p $pidfile -f $command {{.Args}}"
280275
load_rc_config $name
281276
run_rc_command "$1"
282277
`
283-

example/myservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (service *Service) Manage() (string, error) {
8585
stdlog.Println("Stoping listening on ", listener.Addr())
8686
listener.Close()
8787
if killSignal == os.Interrupt {
88-
return "Daemon was interruped by system signal", nil
88+
return "Daemon was interrupted by system signal", nil
8989
}
9090
return "Daemon was killed", nil
9191
}

helper.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ const (
1919
)
2020

2121
var (
22+
// ErrUnsupportedSystem appears if try to use service on system which is not supported by this release
2223
ErrUnsupportedSystem = errors.New("Unsupported system")
23-
ErrRootPriveleges = errors.New("You must have root user privileges. Possibly using 'sudo' command should help")
24-
ErrAlreadyInstalled = errors.New("Service has already been installed")
25-
ErrNotInstalled = errors.New("Service is not installed")
26-
ErrAlreadyStopped = errors.New("Service has already been stopped")
27-
ErrAlreadyRunning = errors.New("Service is already running")
24+
25+
// ErrRootPriveleges appears if run installation or deleting the service without root priveleges
26+
ErrRootPriveleges = errors.New("You must have root user privileges. Possibly using 'sudo' command should help")
27+
28+
// ErrAlreadyInstalled appears if service already installed on the system
29+
ErrAlreadyInstalled = errors.New("Service has already been installed")
30+
31+
// ErrNotInstalled appears if try to delete service which was not been installed
32+
ErrNotInstalled = errors.New("Service is not installed")
33+
34+
// ErrAlreadyStopped appears if try to start already running service
35+
ErrAlreadyRunning = errors.New("Service is already running")
36+
37+
// ErrAlreadyStopped appears if try to stop already stopped service
38+
ErrAlreadyStopped = errors.New("Service has already been stopped")
2839
)
2940

3041
// Lookup path for executable file

0 commit comments

Comments
 (0)