main.go 2.0 KB

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