Skip to content

Commit

Permalink
Merge branch 'hotfix-0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Aug 6, 2014
2 parents 646d1f2 + 2c8360a commit 12ad944
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
36 changes: 1 addition & 35 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.1.2 for use with Go (golang) services.
Package daemon 0.1.3 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 @@ -143,19 +143,6 @@ Go daemon
*/
package daemon

import (
"os"
"os/exec"
"os/user"
)

// Service constants
const (
rootPrivileges = "You must have root user privileges. Possibly using 'sudo' command should help"
success = "\t\t\t\t\t[ \033[32mOK\033[0m ]" // Show colored "OK"
failed = "\t\t\t\t\t[\033[31mFAILED\033[0m]" // Show colored "FAILED"
)

// Daemon interface has standard set of a methods/commands
type Daemon interface {

Expand All @@ -182,24 +169,3 @@ type Daemon interface {
func New(name, description string) (Daemon, error) {
return newDaemon(name, description)
}

// Lookup path for executable file
func executablePath(name string) (string, error) {
if path, err := exec.LookPath(name); err == nil {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return execPath()
}
return path, nil
}
return execPath()
}

// Check root rights to use system service
func checkPrivileges() bool {

if user, err := user.Current(); err == nil && user.Gid == "0" {
return true
}
return false
}
35 changes: 35 additions & 0 deletions helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package daemon

import (
"os"
"os/exec"
"os/user"
)

// Service constants
const (
rootPrivileges = "You must have root user privileges. Possibly using 'sudo' command should help"
success = "\t\t\t\t\t[ \033[32mOK\033[0m ]" // Show colored "OK"
failed = "\t\t\t\t\t[\033[31mFAILED\033[0m]" // Show colored "FAILED"
)

// Lookup path for executable file
func executablePath(name string) (string, error) {
if path, err := exec.LookPath(name); err == nil {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return execPath()
}
return path, nil
}
return execPath()
}

// Check root rights to use system service
func checkPrivileges() bool {

if user, err := user.Current(); err == nil && user.Gid == "0" {
return true
}
return false
}

0 comments on commit 12ad944

Please sign in to comment.