コード例 #1
0
ファイル: main.go プロジェクト: gao-feng/docker-plugin
func main() {
	var (
		justVersion bool
		address     string
		nameserver  string
		debug       bool
	)

	flag.BoolVar(&justVersion, "version", false, "print version and exit")
	flag.BoolVar(&debug, "debug", false, "output debugging info to stderr")
	flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen")
	flag.StringVar(&nameserver, "nameserver", "", "nameserver to provide to containers")

	flag.Parse()

	if justVersion {
		fmt.Printf("weave plugin %s\n", version)
		os.Exit(0)
	}

	if debug {
		SetLogLevel("debug")
	}

	var d skel.Driver
	d, err := driver.New(version, nameserver)
	if err != nil {
		Log.Fatalf("unable to create driver: %s", err)
	}

	var listener net.Listener

	listener, err = net.Listen("unix", address)
	if err != nil {
		Log.Fatal(err)
	}
	defer listener.Close()

	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, os.Interrupt, os.Kill, syscall.SIGTERM)

	endChan := make(chan error, 1)
	go func() {
		endChan <- skel.Listen(listener, d)
	}()

	select {
	case sig := <-sigChan:
		Log.Debugf("Caught signal %s; shutting down", sig)
	case err := <-endChan:
		if err != nil {
			Log.Errorf("Error from listener: ", err)
			listener.Close()
			os.Exit(1)
		}
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: wynandvw/docker-plugin
func main() {
	var (
		justVersion bool
		address     string
		nameserver  string
		debug       bool
	)

	flag.BoolVar(&justVersion, "version", false, "print version and exit")
	flag.BoolVar(&debug, "debug", false, "output debugging info to stderr")
	flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen")
	flag.StringVar(&nameserver, "nameserver", "", "nameserver to provide to containers")

	flag.Parse()

	if justVersion {
		fmt.Printf("weave plugin %s\n", version)
		os.Exit(0)
	}

	if debug {
		SetLogLevel("debug")
	}

	var d driver.Driver
	d, err := driver.New(version)
	if err != nil {
		Log.Fatalf("unable to create driver: %s", err)
	}

	if nameserver != "" {
		if err := d.SetNameserver(nameserver); err != nil {
			Log.Fatalf("could not set nameserver: %s", err)
		}
	}

	if err := d.Listen(address); err != nil {
		Log.Fatal(err)
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: n054/docker-plugin
func main() {
	var (
		justVersion bool
		address     string
		nameserver  string
		logLevel    string
	)

	flag.BoolVar(&justVersion, "version", false, "print version and exit")
	flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
	flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen")
	flag.StringVar(&nameserver, "nameserver", "", "nameserver to provide to containers")

	flag.Parse()

	if justVersion {
		fmt.Printf("weave plugin %s\n", version)
		os.Exit(0)
	}

	SetLogLevel(logLevel)

	Log.Println("Weave plugin", version, "Command line options:", os.Args)

	var d skel.Driver
	d, err := driver.New(version, nameserver)
	if err != nil {
		Log.Fatalf("unable to create driver: %s", err)
	}

	var listener net.Listener

	// remove socket from last invocation
	if err := os.Remove(address); err != nil && !os.IsNotExist(err) {
		Log.Fatal(err)
	}
	listener, err = net.Listen("unix", address)
	if err != nil {
		Log.Fatal(err)
	}
	defer listener.Close()

	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, os.Interrupt, os.Kill, syscall.SIGTERM)

	endChan := make(chan error, 1)
	go func() {
		endChan <- skel.Listen(listener, d)
	}()

	select {
	case sig := <-sigChan:
		Log.Debugf("Caught signal %s; shutting down", sig)
	case err := <-endChan:
		if err != nil {
			Log.Errorf("Error from listener: ", err)
			listener.Close()
			os.Exit(1)
		}
	}
}