Beispiel #1
0
func runUnlock(args []string) (exit int) {
	elc, err := lock.NewEtcdLockClient(nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error initializing etcd client:", err)
		return 1
	}

	var mID string

	if len(args) == 0 {
		mID = machineid.MachineID("/")
		if mID == "" {
			fmt.Fprintln(os.Stderr, "Cannot read machine-id")
			return 1
		}
	} else {
		mID = args[0]
	}

	l := lock.New(mID, elc)

	err = l.Unlock()
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error unlocking:", err)
		return 1
	}

	return 0
}
Beispiel #2
0
func runSetMax(args []string) (exit int) {
	if len(args) != 1 {
		fmt.Fprintln(os.Stderr, "New maximum value must be set.")
		return 1
	}

	elc, err := lock.NewEtcdLockClient(nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error initializing etcd client:", err)
		return 1
	}
	l := lock.New("hi", elc)
	max, err := strconv.Atoi(args[0])
	if err != nil {
		fmt.Fprintln(os.Stderr, "Invalid maximum value:", args[0])
		return 1
	}

	sem, old, err := l.SetMax(max)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error setting value:", err)
	}

	fmt.Println("Old-Max:", old)
	fmt.Println("Max:", sem.Max)

	return
}
Beispiel #3
0
func runStatus(args []string) (exit int) {
	elc, err := lock.NewEtcdLockClient(nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error initializing etcd client:", err)
		return 1
	}
	l := lock.New("", elc)

	sem, err := l.Get()
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error setting value:", err)
	}

	fmt.Println("Available:", sem.Semaphore)
	fmt.Println("Max:", sem.Semaphore)

	if len(sem.Holders) > 0 {
		fmt.Fprintln(out, "")
		printHolders(sem)
	}

	return
}