-
Notifications
You must be signed in to change notification settings - Fork 1
/
plesk_linux.go
52 lines (41 loc) · 1.1 KB
/
plesk_linux.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
48
49
50
51
52
package plesk
import (
"fmt"
"io/ioutil"
"regexp"
"strings"
"path/filepath"
)
const (
psaConf = "/etc/psa/psa.conf"
)
func (self Plesk) getSettings() (settings map[string]string, err error) {
settings = make(map[string]string)
psaConfSettings, err := self.getSettingsFromPsaConf()
if err != nil {
return
}
for key, val := range psaConfSettings {
settings[key] = val
}
settings["ADMIN_BIN"] = filepath.Join(settings["PRODUCT_ROOT_D"], "admin", "bin")
settings["pmm-ras"] = filepath.Join(settings["ADMIN_BIN"], "pmm-ras")
return
}
func (self Plesk) getSettingsFromPsaConf() (settings map[string]string, err error) {
settings = make(map[string]string)
pattern := regexp.MustCompile("^([^#].+)\\s(.+)$")
input, err := ioutil.ReadFile(psaConf)
if err != nil {
return settings, fmt.Errorf("Can't open file %s", psaConf)
}
lines := strings.Split(string(input), "\n")
for _, line := range lines {
match := pattern.FindStringSubmatch(line)
if match != nil {
settings[strings.TrimSpace(match[1])] = strings.TrimSpace(match[2])
}
}
self.Log.Printf("%#v\n", settings)
return
}