From 228468a11241eec5a9286cd1c440cc40f5d4780b Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Thu, 7 Aug 2014 03:05:48 +0700 Subject: [PATCH 1/3] Bumped version number to 0.1.3 --- daemon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon.go b/daemon.go index 8681ffc..c0bcf8c 100644 --- a/daemon.go +++ b/daemon.go @@ -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, From a2b20e30d447a7916ca69ed4b7104db22e7aa561 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Thu, 7 Aug 2014 03:15:16 +0700 Subject: [PATCH 2/3] move helper methods outside --- daemon.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/daemon.go b/daemon.go index c0bcf8c..5eb8a70 100644 --- a/daemon.go +++ b/daemon.go @@ -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 { @@ -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 -} From 2c8360ade6620edf4bedec1294d30c0b098c637b Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Thu, 7 Aug 2014 03:16:07 +0700 Subject: [PATCH 3/3] add helper --- helper.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 helper.go diff --git a/helper.go b/helper.go new file mode 100644 index 0000000..74c6862 --- /dev/null +++ b/helper.go @@ -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 +}