2015-02-09 04:38:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2015-02-17 21:31:20 +00:00
|
|
|
"strings"
|
2015-02-09 04:38:37 +00:00
|
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2015-02-17 21:31:20 +00:00
|
|
|
"github.com/rancherio/os/cmd/control"
|
|
|
|
"github.com/rancherio/os/cmd/systemdocker"
|
2015-02-09 04:38:37 +00:00
|
|
|
osInit "github.com/rancherio/os/init"
|
2015-02-12 23:22:48 +00:00
|
|
|
"github.com/rancherio/os/power"
|
2015-02-14 16:34:31 +00:00
|
|
|
"github.com/rancherio/os/respawn"
|
2015-02-09 04:38:37 +00:00
|
|
|
"github.com/rancherio/os/sysinit"
|
2015-02-17 23:27:13 +00:00
|
|
|
"github.com/rancherio/os/util"
|
2015-02-09 04:38:37 +00:00
|
|
|
)
|
|
|
|
|
2015-02-17 21:31:20 +00:00
|
|
|
func registerCmd(cmd string, mainFunc func()) {
|
|
|
|
log.Debugf("Registering main %s", cmd)
|
|
|
|
reexec.Register(cmd, mainFunc)
|
|
|
|
|
|
|
|
parts := strings.Split(cmd, "/")
|
|
|
|
if len(parts) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
last := parts[len(parts)-1]
|
|
|
|
|
|
|
|
log.Debugf("Registering main %s", last)
|
|
|
|
reexec.Register(last, mainFunc)
|
|
|
|
|
|
|
|
log.Debugf("Registering main %s", "./"+last)
|
|
|
|
reexec.Register("./"+last, mainFunc)
|
|
|
|
}
|
|
|
|
|
2015-02-09 04:38:37 +00:00
|
|
|
func main() {
|
2015-02-17 21:31:20 +00:00
|
|
|
registerCmd("/init", osInit.MainInit)
|
|
|
|
registerCmd("/sbin/init-sys", sysinit.SysInit)
|
|
|
|
registerCmd("/usr/bin/system-docker", systemdocker.Main)
|
|
|
|
registerCmd("/sbin/poweroff", power.PowerOff)
|
|
|
|
registerCmd("/sbin/reboot", power.Reboot)
|
|
|
|
registerCmd("/sbin/halt", power.Halt)
|
|
|
|
registerCmd("/usr/bin/respawn", respawn.Main)
|
|
|
|
registerCmd("/usr/sbin/rancherctl", control.Main)
|
2015-02-17 23:27:13 +00:00
|
|
|
registerCmd("/sbin/tlsconf", util.TLSConf)
|
|
|
|
|
2015-02-09 04:38:37 +00:00
|
|
|
if !reexec.Init() {
|
|
|
|
log.Fatalf("Failed to find an entry point for %s", os.Args[0])
|
|
|
|
}
|
|
|
|
}
|