shutdown.go 807 B

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