main.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. "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. "halt": power.Halt,
  30. "init": osInit.MainInit,
  31. "netconf": network.Main,
  32. "poweroff": power.Off,
  33. "reboot": power.Reboot,
  34. "respawn": respawn.Main,
  35. "ros-sysinit": sysinit.Main,
  36. "shutdown": power.Main,
  37. "system-docker": systemdocker.Main,
  38. "wait-for-docker": wait.Main,
  39. "cni-glue": glue.Main,
  40. "bridge": bridge.Main,
  41. "host-local": hostlocal.Main,
  42. }
  43. func main() {
  44. if 0 == 1 {
  45. // TODO: move this into a "dev/debug +build"
  46. fmt.Fprintf(os.Stderr, "ros main(%s) ppid:%d - print to stdio\n", os.Args[0], os.Getppid())
  47. filename := "/dev/kmsg"
  48. f, err := os.OpenFile(filename, os.O_WRONLY, 0644)
  49. if err == nil {
  50. fmt.Fprintf(f, "ros main(%s) ppid:%d - print to %s\n", os.Args[0], os.Getppid(), filename)
  51. }
  52. f.Close()
  53. }
  54. for name, f := range entrypoints {
  55. reexec.Register(name, f)
  56. }
  57. if !reexec.Init() {
  58. control.Main()
  59. }
  60. }