Skip to content

Commit

Permalink
Merge branch 'release/0.8.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Mar 10, 2017
2 parents 7879db8 + 8bcf07b commit 3bf6e76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

/*
Package daemon 0.8.3 for use with Go (golang) services.
Package daemon 0.8.4 for use with Go (golang) services.
Package daemon provides primitives for daemonization of golang services.
This package is not provide implementation of user daemon,
Expand Down Expand Up @@ -99,7 +99,7 @@ Example:
stdlog.Println("Stoping listening on ", listener.Addr())
listener.Close()
if killSignal == os.Interrupt {
return "Daemon was interruped by system signal", nil
return "Daemon was interrupted by system signal", nil
}
return "Daemon was killed", nil
}
Expand Down
20 changes: 7 additions & 13 deletions daemon_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ package daemon
import "C"

import (
"unsafe"
"fmt"
"bytes"
"path/filepath"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"text/template"
"io/ioutil"
"unsafe"
)


// systemVRecord - standard record (struct) for linux systemV version of daemon package
type bsdRecord struct {
name string
Expand Down Expand Up @@ -52,19 +51,18 @@ func (bsd *bsdRecord) isEnabled() (bool, error) {
r, _ := regexp.Compile(`.*` + bsd.name + `_enable="YES".*`)
v := string(r.Find(rcData))
var chrFound, sharpFound bool
for _, c := range(v){
if c == '#' && !chrFound{
for _, c := range v {
if c == '#' && !chrFound {
sharpFound = true
break
}else if !sharpFound && c != ' '{
} else if !sharpFound && c != ' ' {
chrFound = true
break
}
}
return chrFound, nil
}


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


// Get the daemon properly
func newDaemon(name, description string, dependencies []string) (Daemon, error) {
return &bsdRecord{name, description, dependencies}, nil
Expand Down Expand Up @@ -111,7 +108,6 @@ func execPath() (string, error) {
return filepath.Clean(exePathString), nil
}


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


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

2 changes: 1 addition & 1 deletion example/myservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (service *Service) Manage() (string, error) {
stdlog.Println("Stoping listening on ", listener.Addr())
listener.Close()
if killSignal == os.Interrupt {
return "Daemon was interruped by system signal", nil
return "Daemon was interrupted by system signal", nil
}
return "Daemon was killed", nil
}
Expand Down
21 changes: 16 additions & 5 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@ const (
)

var (
// ErrUnsupportedSystem appears if try to use service on system which is not supported by this release
ErrUnsupportedSystem = errors.New("Unsupported system")
ErrRootPriveleges = errors.New("You must have root user privileges. Possibly using 'sudo' command should help")
ErrAlreadyInstalled = errors.New("Service has already been installed")
ErrNotInstalled = errors.New("Service is not installed")
ErrAlreadyStopped = errors.New("Service has already been stopped")
ErrAlreadyRunning = errors.New("Service is already running")

// ErrRootPriveleges appears if run installation or deleting the service without root priveleges
ErrRootPriveleges = errors.New("You must have root user privileges. Possibly using 'sudo' command should help")

// ErrAlreadyInstalled appears if service already installed on the system
ErrAlreadyInstalled = errors.New("Service has already been installed")

// ErrNotInstalled appears if try to delete service which was not been installed
ErrNotInstalled = errors.New("Service is not installed")

// ErrAlreadyStopped appears if try to start already running service
ErrAlreadyRunning = errors.New("Service is already running")

// ErrAlreadyStopped appears if try to stop already stopped service
ErrAlreadyStopped = errors.New("Service has already been stopped")
)

// Lookup path for executable file
Expand Down

0 comments on commit 3bf6e76

Please sign in to comment.