server: check for expected files

When the configuration is loaded, check that expected files are present
early. This can prevent getting into a partial state later.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-12-12 15:42:10 -05:00
parent 05b10c27ca
commit d5256cb214
Signed by: vbatts
GPG key ID: 10937E57733F1362
2 changed files with 32 additions and 0 deletions

View file

@ -163,6 +163,10 @@ func main() {
return err
}
if err := config.Check(); err != nil {
return err
}
cf := &logrus.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05.000000000Z07:00",
FullTimestamp: true,

View file

@ -2,7 +2,9 @@ package server
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"github.com/BurntSushi/toml"
)
@ -152,3 +154,29 @@ func (c *Config) ToFile(path string) error {
return ioutil.WriteFile(path, w.Bytes(), 0644)
}
// Check resolves that all paths and files are available as expected
func (c *Config) Check() error {
for _, file := range []string{
c.RootConfig.SandboxDir,
c.RootConfig.ContainerDir,
c.RuntimeConfig.Runtime,
c.RuntimeConfig.Conmon,
c.RuntimeConfig.SeccompProfile,
c.ImageConfig.Pause,
} {
if _, err := os.Stat(file); err != nil && os.IsNotExist(err) {
return checkError{Path: file}
}
}
return nil
}
type checkError struct {
Path string
}
func (ce checkError) Error() string {
return fmt.Sprintf("%q does not exist", ce.Path)
}