Skip to content

Commit 7ac6339

Browse files
committed
provisiond: only emtpy reservation cache at boot
1 parent 2e3fd8c commit 7ac6339

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pkg/provision/local_store.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sync/atomic"
1111

1212
"github.com/pkg/errors"
13+
"github.com/rs/zerolog/log"
1314
"github.com/threefoldtech/zos/pkg"
1415
"github.com/threefoldtech/zos/pkg/versioned"
1516
)
@@ -78,12 +79,29 @@ type FSStore struct {
7879

7980
// NewFSStore creates a in memory reservation store
8081
func NewFSStore(root string) (*FSStore, error) {
81-
if err := os.RemoveAll(root); err != nil {
82+
if err := os.MkdirAll("/var/run/modules", 0770); err != nil {
8283
return nil, err
8384
}
84-
if err := os.MkdirAll(root, 0770); err != nil {
85-
return nil, err
85+
86+
_, err := os.OpenFile("/var/run/modules/provisiond", os.O_RDONLY|os.O_CREATE|os.O_TRUNC|os.O_EXCL, 0666)
87+
// if we managed to create the file, this means the node
88+
// has just booted and this is the first time provisiond starts since boot
89+
// so we empty the reservation cache
90+
91+
// if the file is already present, this mean this is just a restart/update of provisiond
92+
// so we need to keep the reservation cache as it is
93+
if err == nil {
94+
log.Info().Msg("first boot, empty reservation cache")
95+
if err := os.RemoveAll(root); err != nil {
96+
return nil, err
97+
}
98+
if err := os.MkdirAll(root, 0770); err != nil {
99+
return nil, err
100+
}
101+
} else {
102+
log.Info().Msg("restart detected, keep reservation cache intact")
86103
}
104+
87105
return &FSStore{
88106
root: root,
89107
}, nil

0 commit comments

Comments
 (0)