func startServer(name string, sockBase string, port int, routes []*Route) error { var ( listener net.Listener err error ) router := mux.NewRouter() router.NotFoundHandler = http.HandlerFunc(notFound) for _, v := range routes { router.Methods(v.verb).Path(v.path).HandlerFunc(v.fn) } socket := path.Join(sockBase, name+".sock") os.Remove(socket) os.MkdirAll(path.Dir(socket), 0755) dlog.Printf("Starting REST service on %+v", socket) listener, err = net.Listen("unix", socket) if err != nil { dlog.Warnln("Cannot listen on UNIX socket: ", err) return err } go http.Serve(listener, router) if port != 0 { go http.ListenAndServe(fmt.Sprintf(":%v", port), router) } return nil }
func (c *ClusterManager) initCluster(db *Database, self *api.Node, exist bool) error { err := error(nil) // Alert all listeners that we are initializing a new cluster. for e := c.listeners.Front(); e != nil; e = e.Next() { err = e.Value.(ClusterListener).ClusterInit(self, db) if err != nil { self.Status = api.Status_STATUS_ERROR dlog.Printf("Failed to initialize %s", e.Value.(ClusterListener).String()) goto done } } err = c.joinCluster(db, self, exist) if err != nil { dlog.Printf("Failed to join new cluster") goto done } done: return err }
// Mount volume at specified path // Errors ErrEnoEnt, ErrVolDetached may be returned. func (d *driver) Mount(volumeID string, mountpath string) error { v, err := d.GetVol(volumeID) if err != nil { dlog.Println(err) return err } syscall.Unmount(mountpath, 0) if err := syscall.Mount(filepath.Join(config.VolumeBase, string(volumeID)), mountpath, string(v.Spec.Format), syscall.MS_BIND, ""); err != nil { dlog.Printf("Cannot mount %s at %s because %+v", filepath.Join(config.VolumeBase, string(volumeID)), mountpath, err) return err } v.AttachPath = mountpath // TODO(pedge): why ignoring error? err = d.UpdateVol(v) return nil }
func (d *driver) Mount(volumeID string, mountpath string) error { v, err := d.GetVol(volumeID) if err != nil { dlog.Println(err) return err } srcPath := path.Join(":", d.nfsPath, volumeID) mountExists, err := d.mounter.Exists(srcPath, mountpath) if !mountExists { d.mounter.Unmount(path.Join(nfsMountPath, volumeID), mountpath) if err := d.mounter.Mount(0, path.Join(nfsMountPath, volumeID), mountpath, string(v.Spec.Format), syscall.MS_BIND, ""); err != nil { dlog.Printf("Cannot mount %s at %s because %+v", path.Join(nfsMountPath, volumeID), mountpath, err) return err } } v.AttachPath = mountpath return d.UpdateVol(v) }
func (d *driver) Shutdown() { dlog.Printf("%s Shutting down", Name) syscall.Unmount(BuseMountPath, 0) }
func Init(params volume.DriverParams) (volume.VolumeDriver, error) { path, ok := params["path"] if !ok { return nil, errors.New("No NFS path provided") } server, ok := params["server"] if !ok { dlog.Printf("No NFS server provided, will attempt to bind mount %s", path) } else { dlog.Printf("NFS driver initializing with %s:%s ", server, path) } // Create a mount manager for this NFS server. Blank sever is OK. mounter, err := mount.New(mount.NFSMount, server) if err != nil { dlog.Warnf("Failed to create mount manager for server: %v (%v)", server, err) return nil, err } inst := &driver{ IoNotSupported: &volume.IoNotSupported{}, DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()), nfsServer: server, nfsPath: path, mounter: mounter, } if err := os.MkdirAll(nfsMountPath, 0744); err != nil { return nil, err } src := inst.nfsPath if server != "" { src = ":" + inst.nfsPath } // If src is already mounted at dest, leave it be. mountExists, err := mounter.Exists(src, nfsMountPath) if !mountExists { // Mount the nfs server locally on a unique path. syscall.Unmount(nfsMountPath, 0) if server != "" { err = syscall.Mount(src, nfsMountPath, "nfs", 0, "nolock,addr="+inst.nfsServer) } else { err = syscall.Mount(src, nfsMountPath, "", syscall.MS_BIND, "") } if err != nil { dlog.Printf("Unable to mount %s:%s at %s (%+v)", inst.nfsServer, inst.nfsPath, nfsMountPath, err) return nil, err } } volumeInfo, err := inst.DefaultEnumerator.Enumerate(&api.VolumeLocator{}, nil) if err == nil { for _, info := range volumeInfo { if info.Status == api.VolumeStatus_VOLUME_STATUS_NONE { info.Status = api.VolumeStatus_VOLUME_STATUS_UP inst.UpdateVol(info) } } } else { dlog.Println("Could not enumerate Volumes, ", err) } dlog.Println("NFS initialized and driver mounted at: ", nfsMountPath) return inst, nil }
func (c *ClusterManager) AddEventListener(listener ClusterListener) error { dlog.Printf("Adding cluster event listener: %s", listener.String()) c.listeners.PushBack(listener) return nil }
func (d *Driver) Shutdown() { dlog.Printf("%s Shutting down", Name) }