shutdown.go 817 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package power
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/codegangsta/cli"
  6. "github.com/rancher/os/config"
  7. "github.com/rancher/os/log"
  8. )
  9. func Main() {
  10. log.InitLogger()
  11. app := cli.NewApp()
  12. app.Name = os.Args[0]
  13. app.Usage = fmt.Sprintf("%s RancherOS\nbuilt: %s", app.Name, config.BuildDate)
  14. app.Version = config.Version
  15. app.Author = "Rancher Labs, Inc."
  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. }