main.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/docker/docker/docker"
  6. "github.com/docker/docker/pkg/reexec"
  7. "github.com/rancher/os/cmd/cloudinitexecute"
  8. "github.com/rancher/os/cmd/cloudinitsave"
  9. "github.com/rancher/os/cmd/control"
  10. "github.com/rancher/os/cmd/network"
  11. "github.com/rancher/os/cmd/power"
  12. "github.com/rancher/os/cmd/respawn"
  13. "github.com/rancher/os/cmd/sysinit"
  14. "github.com/rancher/os/cmd/wait"
  15. "github.com/rancher/os/dfs"
  16. osInit "github.com/rancher/os/init"
  17. )
  18. var entrypoints = map[string]func(){
  19. "autologin": control.AutologinMain,
  20. "cloud-init-execute": cloudinitexecute.Main,
  21. "cloud-init-save": cloudinitsave.Main,
  22. "console": control.ConsoleInitMain,
  23. "console.sh": control.ConsoleInitMain,
  24. "docker": docker.Main,
  25. "dockerlaunch": dfs.Main,
  26. "init": osInit.MainInit,
  27. "netconf": network.Main,
  28. "recovery": control.AutologinMain,
  29. "ros-bootstrap": control.BootstrapMain,
  30. "ros-sysinit": sysinit.Main,
  31. "wait-for-docker": wait.Main,
  32. "respawn": respawn.Main,
  33. // Power commands
  34. "halt": power.Shutdown,
  35. "poweroff": power.Shutdown,
  36. "reboot": power.Shutdown,
  37. "shutdown": power.Shutdown,
  38. }
  39. func main() {
  40. if 0 == 1 {
  41. // TODO: move this into a "dev/debug +build"
  42. fmt.Fprintf(os.Stderr, "ros main(%s) ppid:%d - print to stdio\n", os.Args[0], os.Getppid())
  43. filename := "/dev/kmsg"
  44. f, err := os.OpenFile(filename, os.O_WRONLY, 0644)
  45. if err == nil {
  46. fmt.Fprintf(f, "ros main(%s) ppid:%d - print to %s\n", os.Args[0], os.Getppid(), filename)
  47. }
  48. f.Close()
  49. }
  50. for name, f := range entrypoints {
  51. reexec.Register(name, f)
  52. }
  53. if !reexec.Init() {
  54. control.Main()
  55. }
  56. }