shutdown.go 748 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package power
  2. import (
  3. "os"
  4. "github.com/codegangsta/cli"
  5. "github.com/rancherio/os/config"
  6. )
  7. func Main() {
  8. app := cli.NewApp()
  9. app.Name = os.Args[0]
  10. app.Usage = "Control and configure RancherOS"
  11. app.Version = config.VERSION
  12. app.Author = "Rancher Labs, Inc."
  13. app.Email = "[email protected]"
  14. app.EnableBashCompletion = true
  15. app.Action = shutdown
  16. app.Flags = []cli.Flag{
  17. cli.StringFlag{
  18. Name: "r, R",
  19. Usage: "reboot after shutdown",
  20. },
  21. cli.StringFlag{
  22. Name: "h",
  23. Usage: "halt the system",
  24. },
  25. }
  26. app.HideHelp = true
  27. app.Run(os.Args)
  28. }
  29. func shutdown(c *cli.Context) {
  30. common("")
  31. reboot := c.String("r")
  32. poweroff := c.String("h")
  33. if reboot == "now" {
  34. Reboot()
  35. } else if poweroff == "now" {
  36. PowerOff()
  37. }
  38. }