-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplesk.go
47 lines (36 loc) · 1005 Bytes
/
plesk.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
38
39
40
41
42
43
44
45
46
47
package plesk
import (
"log"
"os/exec"
"syscall"
)
type Plesk struct {
Config map[string]string
Log *log.Logger
}
func New(log *log.Logger) (plesk Plesk, err error) {
plesk = Plesk{
Log: log,
}
plesk.Config, err = plesk.getSettings()
return
}
func execute(log *log.Logger, command string, args ...string) (output string, outputBytes []byte, code int, err error) {
log.Printf("%s %s", command, args)
cmd := exec.Command(command, args...)
var waitStatus syscall.WaitStatus
if outputBytes, err = cmd.CombinedOutput(); err != nil {
// Did the command fail because of an unsuccessful exit code
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus = exitError.Sys().(syscall.WaitStatus)
code = waitStatus.ExitStatus()
}
} else {
// Command was successful
waitStatus = cmd.ProcessState.Sys().(syscall.WaitStatus)
code = waitStatus.ExitStatus()
}
output = string(outputBytes)
log.Println("output: ", output, "err: ", err, "code: ", code)
return
}