main.go 1.5 KB

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