-
Notifications
You must be signed in to change notification settings - Fork 3
/
puppet_unix.go
37 lines (30 loc) · 866 Bytes
/
puppet_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// +build !windows
package main
import (
"os"
"os/exec"
)
const (
osRootName = "root"
osRootMessage = "If not run as root, it will run puppet via sudo automatically."
osPuppetLockFile = "/opt/puppetlabs/puppet/cache/state/agent_disabled.lock"
osPuppetBinPath = "/opt/puppetlabs/bin/puppet"
)
func isRoot() bool {
return os.Geteuid() == 0
}
// This is the normal way of execing, see the Windows one for the messed up way
func osMakeExec(osPuppetBinPath string, puppetArgs ...string) (*exec.Cmd, error) {
var cmd *exec.Cmd
if !isRoot() {
sudoArgs := append([]string{osPuppetBinPath}, puppetArgs...)
cmd = exec.Command("sudo", sudoArgs...)
} else {
cmd = exec.Command(osPuppetBinPath, puppetArgs...)
}
return cmd, nil
}
// There's nothing to clean up
func osCleanupExec(cmd *exec.Cmd) {
return
}