main.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "os"
  4. "strings"
  5. log "github.com/Sirupsen/logrus"
  6. "github.com/docker/docker/pkg/reexec"
  7. "github.com/rancherio/os/cmd/cloudinit"
  8. "github.com/rancherio/os/cmd/control"
  9. "github.com/rancherio/os/cmd/network"
  10. "github.com/rancherio/os/cmd/power"
  11. "github.com/rancherio/os/cmd/respawn"
  12. "github.com/rancherio/os/cmd/sysinit"
  13. "github.com/rancherio/os/cmd/systemdocker"
  14. "github.com/rancherio/os/cmd/wait"
  15. osInit "github.com/rancherio/os/init"
  16. )
  17. func registerCmd(cmd string, mainFunc func()) {
  18. log.Debugf("Registering main %s", cmd)
  19. reexec.Register(cmd, mainFunc)
  20. parts := strings.Split(cmd, "/")
  21. if len(parts) == 0 {
  22. return
  23. }
  24. last := parts[len(parts)-1]
  25. log.Debugf("Registering main %s", last)
  26. reexec.Register(last, mainFunc)
  27. log.Debugf("Registering main %s", "./"+last)
  28. reexec.Register("./"+last, mainFunc)
  29. }
  30. func main() {
  31. registerCmd("/init", osInit.MainInit)
  32. registerCmd(osInit.SYSINIT, sysinit.Main)
  33. registerCmd("/usr/bin/system-docker", systemdocker.Main)
  34. registerCmd("/sbin/poweroff", power.PowerOff)
  35. registerCmd("/sbin/reboot", power.Reboot)
  36. registerCmd("/sbin/halt", power.Halt)
  37. registerCmd("/sbin/shutdown", power.Main)
  38. registerCmd("/usr/bin/respawn", respawn.Main)
  39. registerCmd("/usr/sbin/rancherctl", control.Main) // deprecated, use `ros` instead
  40. registerCmd("/usr/sbin/ros", control.Main)
  41. registerCmd("/usr/bin/cloud-init", cloudinit.Main)
  42. registerCmd("/usr/sbin/netconf", network.Main)
  43. registerCmd("/usr/sbin/wait-for-docker", wait.Main)
  44. if !reexec.Init() {
  45. log.Fatalf("Failed to find an entry point for %s", os.Args[0])
  46. }
  47. }