-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |