Exemplo n.º 1
0
func main() {
	mflag.Parse()

	if *flVersion {
		showVersion()
		return
	}

	if *flHelp {
		mflag.Usage()
		return
	}

	if *flDebug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	if len(*flRuntime) != 0 {
		if *flRuntime != opts.DEFAULTRUNTIME && *flRuntime != opts.RKTRUNTIME {
			fmt.Println("Invalid container runtime")
			return
		}
	}

	if len(flHosts) == 0 {
		defaultHost := fmt.Sprintf("unix://%s", opts.DEFAULTUNIXSOCKET)
		flHosts = append(flHosts, defaultHost)
	}

	_, ok := exec.LookPath("docker")
	if ok != nil {
		logrus.Fatal("Can't find docker")
	}

	if *flDaemon {
		mainDaemon()
		return
	}

	if len(flHosts) > 1 {
		fmt.Fprintf(os.Stderr, "Please specify only one -H")
		os.Exit(0)
	}

	// If no flag specified, print help info.
	mflag.Usage()
}
Exemplo n.º 2
0
func mainDaemon() {
	if mflag.NArg() != 0 {
		mflag.Usage()
		return
	}

	if len(*flDockerSock) == 0 {
		engine.DockerSock = opts.DEFAULTDOCKERSOCKET
	} else {
		engine.DockerSock = *flDockerSock
	}

	RuntimeType := engine.RuntimeDocker
	if len(*flRuntime) != 0 && *flRuntime == opts.RKTRUNTIME {
		RuntimeType = engine.RuntimeRkt
	}

	if len(*flGroup) > 0 {
		engine.SocketGroup = *flGroup
	}

	eng := engine.New(RuntimeType)

	//catch signals
	trap.SignalsHandler(trap.Shutdown)

	var srv *server.Server
	srv = server.New(eng, false)

	serverWait := make(chan error)
	go func() {
		if err := srv.CreateServer(eng, flHosts); err != nil {
			logrus.Errorf("Server error: %v", err)
			serverWait <- err
			return
		}
		serverWait <- nil
	}()
	err := <-serverWait
	if err != nil {
		logrus.Fatalf("Shutting down due to Server error: %v", err)
	}
	<-trap.CleanupDone
}