Пример #1
0
func main() {
	flag.Usage = usage
	flag.Parse()
	log.Println("start uploader")

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	ctx, err := newCtx(*serverAddr, flag.Args())

	if err != nil {
		log.Fatal(err)
	}

	ctx.search()
	err = ctx.upload()

	if err != nil {
		log.Fatal(err)
	}

	ctx.replace()
	ctx.WriteTo(os.Stdout)
}
Пример #2
0
func main() {
	flag.Parse()
	log.Println("start uploader")

	if flag.NArg() == 0 {
		log.Fatal("Expected file argument missing")
	}

	c, err := client.New(*serverAddr)

	if err != nil {
		log.Fatal(err)
	}

	res, _ := c.MultiUploader(flag.Args())
	var enc client.ResourceEncoder

	switch *outputType {
	case "json":
		enc = client.NewJSONEncoder(os.Stdout)
	default:
		os.Exit(0)
	}

	err = enc.Encode(res)

	if err != nil {
		log.Fatal(err)
	}
}
Пример #3
0
func main() {
	flag.Usage = usage
	flag.Parse()
	log.Println("start blobserver service …")

	if *version {
		fmt.Fprintln(os.Stdout, Version)
		return
	}

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	conf, err := config.ReadFile(*configFilename)

	if err != nil {
		log.Fatal(err)
	}

	if conf.Listen == "" && *laddr == "" {
		log.Fatal("Listen address required")
	} else if conf.Listen == "" {
		conf.Listen = *laddr
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	storage, err := blobserver.CreateStorage(conf)

	if err != nil {
		log.Fatalf("error instantiating storage for type %s: %v",
			conf.StorageType(), err)
	}

	log.Printf("Using `%s` storage", conf.StorageType())
	err = server.ListenAndServe(*laddr, storage)

	if err != nil {
		log.Errorln(err)
	}

	monitoring.MeasuringPointsPrintAll()
}
Пример #4
0
func TrapCloser(cl io.Closer, cleanups ...Cleanup) {
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGHUP)

	go func() {
		for {
			rawSig := <-c
			sig, ok := rawSig.(syscall.Signal)

			if !ok {
				log.Fatal("not a unix signal")
			}

			switch {
			case sig == syscall.SIGHUP:
				log.Print("SIGHUP: restart process")
				err := RestartProcess()

				if err != nil {
					log.Fatal("failed to restart: " + err.Error())
				}
			case sig == syscall.SIGINT || sig == syscall.SIGKILL || sig == syscall.SIGTERM:
				log.Print("shutting down")
				donec := make(chan bool)
				go func() {
					for _, cb := range cleanups {
						if err := cb(); err != nil {
							log.Error(err)
						}
					}

					if err := cl.Close(); err != nil {
						log.Fatalf("Error shutting down: %v", err)
					}

					donec <- true
				}()
				select {
				case <-donec:
					log.Printf("shutdown")
					os.Exit(0)
				case <-time.After(5 * time.Second):
					log.Fatal("Timeout shutting down. Exiting uncleanly.")
				}
			default:
				log.Fatal("Received another signal, should not happen.")
			}
		}
	}()
}
Пример #5
0
func main() {
	flag.Usage = usage
	flag.Parse()

	if *version {
		fmt.Fprintln(os.Stdout, Version)
		os.Exit(0)
	}

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	setupServer()
	listenAndServe(*laddr)
}
Пример #6
0
func main() {
	flag.Usage = usage
	flag.Parse()
	log.Println("start policy service …")

	if *version {
		fmt.Fprintln(os.Stdout, Version)
		return
	}

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	err := policy.ListenAndServe(*laddr)

	if err != nil {
		log.Errorln(err)
	}

	monitoring.MeasuringPointsPrintAll()
}
Пример #7
0
func main() {
	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	if _, err := toml.DecodeFile(*configFilename, &config); err != nil {
		log.Fatal(err)
	}

	if config.Laddr == "" {
		config.Laddr = *laddr
	}

	for k, v := range config.Regions {
		v.Codename = k
		store, err := kvstore.Open(v.RedisDSN)

		if err != nil {
			log.Fatal(err)
		}

		conn := store.Get()
		_, err = conn.Do("Ping")
		conn.Close()

		if err != nil {
			log.Fatalf("region %s: %v", k, err)
		}

		v.Backend = NewRedisBackend(store, v.Codename)
	}

	runServer()
}
Пример #8
0
func main() {
	flag.Usage = usage
	flag.Parse()

	if *version {
		fmt.Fprintln(os.Stdout, Version)
		return
	}

	if *help {
		flag.Usage()
		os.Exit(1)
	}

	if *laddr == "" {
		fmt.Fprintln(os.Stderr, "listen address required")
		os.Exit(1)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	var imgBackend backend.ImageBackend

	if *fsBaseDir != "" {
		imgBackend = backend.Dir(*fsBaseDir)
	} else if *awsAccessKeyId != "" && *awsSecretAccessKey != "" && *awsRegion != "" && *awsBucket != "" {
		imgBackend = backend.NewS3(*awsAccessKeyId, *awsSecretAccessKey, *awsRegion, *awsBucket)
	} else {
		log.Errorln("Expected either aws-* or fs-* arguments")
		os.Exit(1)
	}

	err := server.ListenAndServe(*laddr, imgBackend)

	if err != nil {
		log.Println(err)
	}
}