forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if the agent can safely be rebooted on startup
Since the jobs directory may be mounted on tmpfs, it may not be present after reboot. To stop the agent starting without starting its jobs we make sure to crash it on subsequent reboots. [#161569005](https://www.pivotaltracker.com/story/show/161569005) Signed-off-by: Joshua Aresty <[email protected]>
- Loading branch information
Christopher Brown
authored and
Joshua Aresty
committed
Nov 6, 2018
1 parent
719afe4
commit c6c9bef
Showing
7 changed files
with
353 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package bootonce_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestBootonce(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Bootonce Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} |
Oops, something went wrong.