pause.go 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package nsinit
  2. import (
  3. "log"
  4. "github.com/codegangsta/cli"
  5. "github.com/docker/libcontainer/cgroups"
  6. "github.com/docker/libcontainer/cgroups/fs"
  7. "github.com/docker/libcontainer/cgroups/systemd"
  8. )
  9. var pauseCommand = cli.Command{
  10. Name: "pause",
  11. Usage: "pause the container's processes",
  12. Action: pauseAction,
  13. }
  14. var unpauseCommand = cli.Command{
  15. Name: "unpause",
  16. Usage: "unpause the container's processes",
  17. Action: unpauseAction,
  18. }
  19. func pauseAction(context *cli.Context) {
  20. if err := toggle(cgroups.Frozen); err != nil {
  21. log.Fatal(err)
  22. }
  23. }
  24. func unpauseAction(context *cli.Context) {
  25. if err := toggle(cgroups.Thawed); err != nil {
  26. log.Fatal(err)
  27. }
  28. }
  29. func toggle(state cgroups.FreezerState) error {
  30. container, err := loadContainer()
  31. if err != nil {
  32. return err
  33. }
  34. if systemd.UseSystemd() {
  35. err = systemd.Freeze(container.Cgroups, state)
  36. } else {
  37. err = fs.Freeze(container.Cgroups, state)
  38. }
  39. return err
  40. }