Exemplo n.º 1
0
func unmountAllVols() {
	for _, v := range VolData.Volumes {
		if v.mntCount > 0 {
			if err := revelo.Unmount(v.MntDir); err != nil {
				log.Errorf("Cannot unmount vol: %v, error: %v", v.DvName, err)
			} else {
				log.Errorf("Unmounted vol: %v", v.DvName)
			}
		}
	}
}
Exemplo n.º 2
0
func handleSignals(mntDir string) {
	sigConn := make(chan os.Signal, 10)
	signal.Notify(sigConn, os.Interrupt)
	signal.Notify(sigConn, syscall.SIGTERM)
	signal.Notify(sigConn, syscall.SIGUSR1)
	signal.Notify(sigConn, syscall.SIGUSR2)
	go func() {
		for {
			sig := <-sigConn
			if sig == syscall.SIGUSR1 {
				old := log.GetLevel()
				new := old + 1
				if new > log.DebugLevel {
					new = log.DebugLevel
				}
				if new != old {
					log.SetLevel(new)
					log.WithFields(log.Fields{"old": old, "new": new}).Error("Increased logging")
				}
			} else if sig == syscall.SIGUSR2 {
				old := log.GetLevel()
				new := old - 1
				if new < log.FatalLevel {
					new = log.FatalLevel
				}
				if new != old {
					log.WithFields(log.Fields{"old": old, "new": new}).Error("Decreased logging")
					log.SetLevel(new)
				}
			} else {
				log.Error("Interrupted... exiting")
				log.Infof("Unmounting %s ... ", mntDir)
				revelo.Unmount(mntDir)
				os.Exit(1)
			}
		}
	}()
}
Exemplo n.º 3
0
func UnmountHandler(req *DockerRequest) *DockerResponse {
	log.WithFields(log.Fields{"Req": req}).Debug("dv: UNmount Handler")

	VolData.lock.RLock()
	v, ok := VolData.Volumes[req.Name]
	VolData.lock.RUnlock()

	if !ok {
		log.WithFields(log.Fields{"Volume": v}).Error("dv: UNmount: Volume not found")
		return &DockerResponse{Err: " Volume " + req.Name + " not found"}
	}

	if v.mntCount <= 0 {
		log.WithFields(log.Fields{"Volume": v}).Error("dv: UNmount: Volume not mounted")
		return &DockerResponse{Err: " Volume " + v.DvName + " not mounted"}
	}

	v.mntCount--

	VolData.lock.Lock()
	VolData.Volumes[req.Name] = v
	VolData.lock.Unlock()

	if v.mntCount == 0 {
		err := revelo.Unmount(v.MntDir)
		if err != nil {
			log.WithFields(log.Fields{"Volume": v, "Error": err}).Error("dv: UNmount: Cannot mount")
			return &DockerResponse{Err: " Volume " + v.DvName + " cannot UNmount"}
		}
	}

	log.Infof("UNMounted volume %v", v)
	listAllVols()

	return &DockerResponse{Err: ""}
}