command_fs_lock_unlock.go 932 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package shell
  2. import (
  3. "io"
  4. )
  5. func init() {
  6. Commands = append(Commands, &commandUnlock{})
  7. Commands = append(Commands, &commandLock{})
  8. }
  9. // =========== Lock ==============
  10. type commandLock struct {
  11. }
  12. func (c *commandLock) Name() string {
  13. return "lock"
  14. }
  15. func (c *commandLock) Help() string {
  16. return `lock in order to exclusively manage the cluster
  17. This is a blocking operation if there is alread another lock.
  18. `
  19. }
  20. func (c *commandLock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  21. commandEnv.locker.RequestLock()
  22. return nil
  23. }
  24. // =========== Unlock ==============
  25. type commandUnlock struct {
  26. }
  27. func (c *commandUnlock) Name() string {
  28. return "unlock"
  29. }
  30. func (c *commandUnlock) Help() string {
  31. return `unlock the cluster-wide lock
  32. `
  33. }
  34. func (c *commandUnlock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  35. commandEnv.locker.ReleaseLock()
  36. return nil
  37. }