-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_freeze.go
62 lines (56 loc) · 1.16 KB
/
node_freeze.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
package object
import (
"os"
"path/filepath"
"time"
"github.com/opensvc/om3/util/file"
"github.com/rs/zerolog/log"
)
// lockName is the path of the file to use as an action lock.
func (t *Node) frozenFile() string {
return filepath.Join(t.VarDir(), "frozen")
}
// Frozen returns the unix timestamp of the last freeze.
func (t *Node) Frozen() time.Time {
p := t.frozenFile()
fi, err := os.Stat(p)
if err != nil {
return time.Time{}
}
return fi.ModTime()
}
// Freeze creates a persistant flag file that prevents orchestration
// of the object instance.
func (t *Node) Freeze() error {
p := t.frozenFile()
if file.Exists(p) {
return nil
}
d := filepath.Dir(p)
if !file.Exists(d) {
if err := os.MkdirAll(d, os.ModePerm); err != nil {
return err
}
}
f, err := os.Create(p)
if err != nil {
return err
}
f.Close()
log.Info().Msg("now frozen")
return nil
}
// Unfreeze removes the persistant flag file that prevents orchestration
// of the object instance.
func (t *Node) Unfreeze() error {
p := t.frozenFile()
if !file.Exists(p) {
return nil
}
err := os.Remove(p)
if err != nil {
return err
}
log.Info().Msg("now unfrozen")
return nil
}