main.go 1.9 KB

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