func (s *dockerSuite) SetUpTest(c *C) { c.Assert(exec.Command("sh", "-c", "set -e; for i in $(rbd ls); do rbd snap purge $i; rbd rm $i; done").Run(), IsNil) exec.Command("/bin/sh", "-c", "etcdctl rm --recursive /volplugin").Run() client, err := config.NewClient("/volplugin", []string{"http://127.0.0.1:2379"}) if err != nil { c.Fatal(err) } s.client = client global := config.NewGlobalConfig() s.api = api.NewAPI(NewVolplugin(), "mon0", client, &global) s.server = httptest.NewServer(s.api.Router(s.api)) }
// Daemon starts the volplugin service. func (dc *DaemonConfig) Daemon() error { global, err := dc.Client.GetGlobal() if err != nil { logrus.Errorf("Error fetching global configuration: %v", err) logrus.Infof("No global configuration. Proceeding with defaults...") global = config.NewGlobalConfig() } dc.Global = global errored.AlwaysDebug = dc.Global.Debug errored.AlwaysTrace = dc.Global.Debug if dc.Global.Debug { logrus.SetLevel(logrus.DebugLevel) } go info.HandleDebugSignal() activity := make(chan *watch.Watch) dc.Client.WatchGlobal(activity) go func() { for { dc.Global = (<-activity).Config.(*config.Global) logrus.Debugf("Received global %#v", dc.Global) errored.AlwaysDebug = dc.Global.Debug errored.AlwaysTrace = dc.Global.Debug if dc.Global.Debug { logrus.SetLevel(logrus.DebugLevel) } } }() dc.API = api.NewAPI(docker.NewVolplugin(), dc.Hostname, dc.Client, &dc.Global) if err := dc.updateMounts(); err != nil { return err } go dc.pollRuntime() driverPath := path.Join(basePath, fmt.Sprintf("%s.sock", dc.PluginName)) if err := os.Remove(driverPath); err != nil && !os.IsNotExist(err) { return err } if err := os.MkdirAll(basePath, 0700); err != nil { return err } l, err := net.ListenUnix("unix", &net.UnixAddr{Name: driverPath, Net: "unix"}) if err != nil { return err } srv := http.Server{Handler: dc.API.Router(dc.API)} srv.SetKeepAlivesEnabled(false) if err := srv.Serve(l); err != nil { logrus.Fatalf("Fatal error serving volplugin: %v", err) } l.Close() return os.Remove(driverPath) }