func NewDaemon(cfg *apitypes.HyperConfig) (*Daemon, error) { var tempdir = path.Join(utils.HYPER_ROOT, "run") os.Setenv("TMPDIR", tempdir) if err := os.MkdirAll(tempdir, 0755); err != nil && !os.IsExist(err) { return nil, err } var realRoot = path.Join(utils.HYPER_ROOT, "lib") // Create the root directory if it doesn't exists if err := os.MkdirAll(realRoot, 0755); err != nil && !os.IsExist(err) { return nil, err } var ( db_file = fmt.Sprintf("%s/hyper.db", realRoot) ) db, err := daemondb.NewDaemonDB(db_file) if err != nil { return nil, err } daemon := &Daemon{ ID: fmt.Sprintf("%d", os.Getpid()), db: db, PodList: pod.NewPodList(), Host: cfg.Host, } daemon.Daemon, err = docker.NewDaemon(dockerCfg, registryCfg) if err != nil { return nil, err } // Get the docker daemon info sysinfo, err := daemon.Daemon.SystemInfo() if err != nil { return nil, err } stor, err := StorageFactory(sysinfo, daemon.db) if err != nil { return nil, err } daemon.Storage = stor daemon.Storage.Init() err = daemon.initRunV(cfg) if err != nil { return nil, err } err = daemon.initNetworks(cfg) if err != nil { return nil, err } daemon.initDefaultLog(cfg) return daemon, nil }
func NewDaemonFromDirectory(cfg *goconfig.ConfigFile) (*Daemon, error) { kernel, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Kernel") initrd, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Initrd") glog.V(0).Infof("The config: kernel=%s, initrd=%s", kernel, initrd) vboxImage, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Vbox") glog.V(0).Infof("The config: vbox image=%s", vboxImage) biface, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bridge") bridgeip, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "BridgeIP") glog.V(0).Infof("The config: bridge=%s, ip=%s", biface, bridgeip) bios, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bios") cbfs, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Cbfs") glog.V(0).Infof("The config: bios=%s, cbfs=%s", bios, cbfs) host, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Host") var tempdir = path.Join(utils.HYPER_ROOT, "run") os.Setenv("TMPDIR", tempdir) if err := os.MkdirAll(tempdir, 0755); err != nil && !os.IsExist(err) { return nil, err } var realRoot = path.Join(utils.HYPER_ROOT, "lib") // Create the root directory if it doesn't exists if err := os.MkdirAll(realRoot, 0755); err != nil && !os.IsExist(err) { return nil, err } var ( db_file = fmt.Sprintf("%s/hyper.db", realRoot) ) db, err := daemondb.NewDaemonDB(db_file) if err != nil { return nil, err } daemon := &Daemon{ ID: fmt.Sprintf("%d", os.Getpid()), db: db, Kernel: kernel, Initrd: initrd, Bios: bios, Cbfs: cbfs, VboxImage: vboxImage, PodList: NewPodList(), VmList: NewVmList(), Host: host, BridgeIP: bridgeip, BridgeIface: biface, } daemon.Daemon, err = docker.NewDaemon(dockerCfg, registryCfg) if err != nil { return nil, err } // Get the docker daemon info sysinfo, err := daemon.Daemon.SystemInfo() if err != nil { return nil, err } stor, err := StorageFactory(sysinfo) if err != nil { return nil, err } daemon.Storage = stor daemon.Storage.Init() return daemon, nil }