forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreboot_checker.go
53 lines (43 loc) · 1.14 KB
/
reboot_checker.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
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"
)
type RebootChecker struct {
settings boshsettings.Service
fs boshsys.FileSystem
dirProvider boshdir.Provider
}
func NewRebootChecker(
settings boshsettings.Service,
fs boshsys.FileSystem,
dirProvider boshdir.Provider,
) *RebootChecker {
return &RebootChecker{
settings: settings,
fs: fs,
dirProvider: dirProvider,
}
}
func (r *RebootChecker) CanReboot() (bool, error) {
if !r.tmpFsFeatureEnabled() {
return true, nil
}
path := filepath.Join(r.dirProvider.BoshDir(), "bootonce")
return checkAndMark(r.fs, path)
}
func (r *RebootChecker) tmpFsFeatureEnabled() bool {
settings := r.settings.GetSettings()
return settings.Env.Bosh.JobDir.TmpFs
}
func checkAndMark(fs boshsys.FileSystem, path string) (bool, error) {
if fs.FileExists(path) {
return false, nil
}
return true, touch(fs, path)
}
func touch(fs boshsys.FileSystem, path string) error {
return fs.WriteFile(path, nil)
}