-
Notifications
You must be signed in to change notification settings - Fork 264
/
running_info.go
65 lines (55 loc) · 1.41 KB
/
running_info.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
53
54
55
56
57
58
59
60
61
62
63
64
65
package db
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/steampipe/constants"
"github.com/turbot/steampipe/utils"
)
// RunningDBInstanceInfo :: contains data about the running process
// and it's credentials
type RunningDBInstanceInfo struct {
Pid int
Port int
Listen []string
ListenType StartListenType
Invoker Invoker
Password string
User string
Database string
}
func (r *RunningDBInstanceInfo) Save() error {
return saveRunningInstanceInfo(r)
}
func saveRunningInstanceInfo(info *RunningDBInstanceInfo) error {
if content, err := json.Marshal(info); err != nil {
return err
} else {
return ioutil.WriteFile(runningInfoFilePath(), content, 0644)
}
}
func loadRunningInstanceInfo() (*RunningDBInstanceInfo, error) {
utils.LogTime("db.loadRunningInstanceInfo start")
defer utils.LogTime("db.loadRunningInstanceInfo end")
if !helpers.FileExists(runningInfoFilePath()) {
return nil, nil
}
fileContent, err := ioutil.ReadFile(runningInfoFilePath())
if err != nil {
return nil, err
}
var info = new(RunningDBInstanceInfo)
err = json.Unmarshal(fileContent, info)
if err != nil {
return nil, err
}
return info, nil
}
func removeRunningInstanceInfo() error {
return os.Remove(runningInfoFilePath())
}
func runningInfoFilePath() string {
return filepath.Join(constants.InternalDir(), "steampipe.json")
}