示例#1
0
func init() {
	var err error

	rconfig.Parse(&config)
	config.expireWarning, err = time.ParseDuration(config.ExpireWarning)
	if err != nil {
		log.Fatalf("You need to specify a valid expire-warning: %s", err)
	}
}
示例#2
0
func main() {
	rconfig.Parse(cfg)

	r := mux.NewRouter()
	r.HandleFunc("/document/{ipfs_hash:Qm.+}", handleDocument)
	r.HandleFunc("/{ipfs_hash:Qm.+}", handleViewer)

	http.Handle("/", r)
	http.ListenAndServe(cfg.Listen, r)
}
示例#3
0
func init() {
	rconfig.Parse(&cfg)

	if cfg.User == "" || cfg.Pass == "" || cfg.BaseURL == "" {
		rconfig.Usage()
		os.Exit(1)
	}

	cookieJar, _ = cookiejar.New(nil)
	client = &http.Client{
		Jar: cookieJar,
	}
}
示例#4
0
func main() {
	rconfig.Parse(&cfg)

	// Transistion for deprecated --papertrail-endpoint parameter
	if cfg.SysLogEndpoint == "" && cfg.PapertrailEndpoint != "" {
		cfg.SysLogEndpoint = cfg.PapertrailEndpoint
	}

	logstream = make(chan *message, 5000)

	jsLineConverter, err = jsVM.Compile(cfg.LineConverter, nil)
	if err != nil {
		log.Fatalf("Unable to parse line converter script: %s", err)
	}

	log.Printf("Started dockerlogstream %s", version)

	// Connect to Docker socket
	client, err = docker.NewClient("unix://" + cfg.DockerAPI)
	if err != nil {
		log.Fatalf("Unable to connect to Docker daemon: %s", err)
	}

	if cfg.Testing {
		// Log to STDOUT instead of streaming
		ta := TestAdapter{}
		go ta.Stream(logstream)
	} else {
		// Create sending part of the logger
		sl, err := NewSyslogAdapter(cfg.SysLogEndpoint)
		if err != nil {
			log.Fatalf("Unable to create logging adapter: %s", err)
		}
		go sl.Stream(logstream)
	}

	fluentServer, err := net.Listen("tcp", cfg.ListenAddress)
	if err != nil {
		log.Fatalf("Unable to listen: %s", err)
	}

	for {
		conn, err := fluentServer.Accept()
		if err != nil {
			log.Fatalf("Unable to accept tcp connection: %s", err)
		}

		go handleFluentdForwardConnection(conn)
	}
}
示例#5
0
func init() {
	if err := rconfig.Parse(&config); err != nil {
		log.Printf("Unable to parse CLI parameters: %s\n", err)
		os.Exit(1)
	}

	if len(config.SealTokens) == 1 && config.SealTokens[0] == "" {
		if len(rconfig.Args()) <= 1 {
			log.Println("You must provide at least one token.")
			os.Exit(1)
		}
		config.SealTokens = rconfig.Args()[1:]
	}
}
示例#6
0
func init() {
	if err := rconfig.Parse(&config); err != nil {
		fmt.Printf("Unable to load config: %s\n", err)
		os.Exit(1)
	}

	if config.Version {
		fmt.Printf("locationmaps %s\n", version)
		os.Exit(0)
	}

	c, err := couch.NewClientURL(config.CouchDBConnection)
	if err != nil {
		fmt.Printf("Unable to connect to CouchDB: %s\n", err)
		os.Exit(1)
	}
	couchConn = c
}
示例#7
0
func loadConfig() *config {
	cfg := &config{}
	rconfig.Parse(cfg)
	return cfg
}
示例#8
0
// Load collects the configuration
func Load() *Config {
	cfg := &Config{}
	rconfig.Parse(cfg)

	return cfg
}
示例#9
0
文件: main.go 项目: Luzifer/envrun
func init() {
	rconfig.Parse(&cfg)
}
示例#10
0
func main() {
	rconfig.Parse(&cfg)

	// Transistion for deprecated --papertrail-endpoint parameter
	if cfg.SysLogEndpoint == "" && cfg.PapertrailEndpoint != "" {
		cfg.SysLogEndpoint = cfg.PapertrailEndpoint
	}

	logstream = make(chan *message, 5000)

	jsLineConverter, err = jsVM.Compile(cfg.LineConverter, nil)
	if err != nil {
		log.Fatalf("Unable to parse line converter script: %s", err)
	}

	log.Printf("Started dockerlogstream %s (%s)", ProjectVersion, ProjectBuild)

	// Connect to Docker socket
	client, err = docker.NewClient("unix://" + cfg.DockerAPI)
	if err != nil {
		log.Fatalf("Unable to connect to Docker daemon: %s", err)
	}

	if cfg.Testing {
		// Log to STDOUT instead of streaming
		ta := TestAdapter{}
		go ta.Stream(logstream)
	} else {
		// Create sending part of the logger
		sl, err := NewSyslogAdapter(cfg.SysLogEndpoint)
		if err != nil {
			log.Fatalf("Unable to create logging adapter: %s", err)
		}
		go sl.Stream(logstream)
	}

	for {
		containers, err := listContainers()
		if err != nil {
			log.Fatalf("Unable to list containers: %s", err)
		}

		touched := []string{}
		for _, container := range containers {
			touched = append(touched, container.ID)

			// If we don't have a channel for this container create it
			if _, ok := receiveChannels[container.ID]; !ok {
				log.Printf("INFO: Found container %s, attaching...", container.ID)
				receiveChannelsLock.Lock()
				receiveChannels[container.ID] = &bufferedLogMessageWriter{
					channel:   logstream,
					container: container,
					buffer:    []byte{},
				}
				receiveChannelsLock.Unlock()

				go func(containerID string) {
					receiveChannelsLock.RLock()
					stream := receiveChannels[containerID]
					receiveChannelsLock.RUnlock()

					err := client.AttachToContainer(docker.AttachToContainerOptions{
						Container:    containerID,
						OutputStream: stream,
						ErrorStream:  stream,
						Logs:         false,
						Stream:       true,
						Stdout:       true,
						Stderr:       true,
					})

					if err == nil {
						log.Printf("INFO: Attachment to container %s ended", containerID)
					} else {
						log.Printf("ERROR: Attachment for container %s ended with error: %s", containerID, err)
					}

					receiveChannelsLock.Lock()
					delete(receiveChannels, containerID)
					receiveChannelsLock.Unlock()
				}(container.ID)
			}

		}

		for k := range receiveChannels {
			if !inSlice(touched, k) {
				log.Printf("INFO: Missing container %s, removing logger...", k)
				receiveChannelsLock.Lock()
				delete(receiveChannels, k)
				receiveChannelsLock.Unlock()
			}
		}
		time.Sleep(time.Second)
	}
}
示例#11
0
func loadConfig() *configuration {
	c := &configuration{}
	rconfig.Parse(c)

	return c
}