-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount.go
40 lines (36 loc) · 961 Bytes
/
mount.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
package main
import (
"bytes"
"os"
"os/exec"
"strconv"
"strings"
)
func nfsIsMounted() bool {
var out bytes.Buffer
cmd := exec.Command("mount")
cmd.Stdout = &out
if err := cmd.Run(); err == nil {
if !strings.Contains(out.String(), "localhost:"+Config.RemoteMountDirectory+" on") {
return false // Mount point disappeared
}
return true
} else {
panic("Couldn't run mount command: " + err.Error())
}
}
func mountNfs() {
os.Mkdir(Config.LocalVolumeName, 0777)
cmd := exec.Command("mount", "-o", "port="+strconv.Itoa(Config.LocalNfsdPort)+",mountport="+strconv.Itoa(Config.LocalMountdPort)+",vers=4,noowners,rw,nosuid", "localhost:"+Config.RemoteMountDirectory, Config.LocalVolumeName)
err := cmd.Run()
if err != nil {
panic("Unable to mount nfs: " + err.Error())
}
}
func unmountNfs() {
cmd := exec.Command("umount", Config.LocalVolumeName)
err := cmd.Run()
if err != nil {
panic("Unable to unmount nfs: " + err.Error())
}
}