@@ -10,6 +10,7 @@ import (
10
10
"sync/atomic"
11
11
12
12
"github.com/pkg/errors"
13
+ "github.com/rs/zerolog/log"
13
14
"github.com/threefoldtech/zos/pkg"
14
15
"github.com/threefoldtech/zos/pkg/versioned"
15
16
)
@@ -78,12 +79,29 @@ type FSStore struct {
78
79
79
80
// NewFSStore creates a in memory reservation store
80
81
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 {
82
83
return nil , err
83
84
}
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" )
86
103
}
104
+
87
105
return & FSStore {
88
106
root : root ,
89
107
}, nil
0 commit comments