forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_manager.go
66 lines (53 loc) · 1.47 KB
/
start_manager.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
66
package bootonce
import (
"path/filepath"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
const BootonceFileName = "bootonce"
type StartManager struct {
settings boshsettings.Service
fs boshsys.FileSystem
dirProvider boshdir.Provider
}
func NewStartManager(
settings boshsettings.Service,
fs boshsys.FileSystem,
dirProvider boshdir.Provider,
) *StartManager {
return &StartManager{
settings: settings,
fs: fs,
dirProvider: dirProvider,
}
}
func (r *StartManager) CanStart() bool {
if !r.tmpFsFeatureEnabled() {
return true
}
return !r.fs.FileExists(r.persistentBootoncePath()) || r.fs.FileExists(r.tmpfsBootoncePath())
}
func (r *StartManager) RegisterStart() error {
if !r.tmpFsFeatureEnabled() {
return nil
}
err := r.fs.WriteFile(r.persistentBootoncePath(), nil)
if err != nil {
return err
}
return r.fs.WriteFile(r.tmpfsBootoncePath(), nil)
}
func (r *StartManager) tmpFsFeatureEnabled() bool {
settings := r.settings.GetSettings()
return settings.TmpFSEnabled()
}
func (r *StartManager) persistentBootoncePath() string {
return filepath.Join(r.dirProvider.BoshDir(), BootonceFileName)
}
func (r *StartManager) tmpfsBootoncePath() string {
return filepath.Join(r.dirProvider.CanRestartDir(), BootonceFileName)
}
func touch(fs boshsys.FileSystem, path string) error {
return fs.WriteFile(path, nil)
}