Exemple #1
0
func tailFile(ctx context.Context, file string, dest *os.File) {
	defer wg.Done()
	t, err := tail.TailFile(file, tail.Config{
		Follow: true,
		ReOpen: true,
		//Poll:   true,
		Logger: tail.DiscardingLogger,
	})
	if err != nil {
		log.Fatalf("unable to tail %s: %s", "foo", err)
	}

	// main loop
	for {
		select {
		// if the channel is done, then exit the loop
		case <-ctx.Done():
			t.Stop()
			tail.Cleanup()
			return
		// get the next log line and echo it out
		case line := <-t.Lines:
			fmt.Fprintln(dest, line.Text)
		}
	}
}
Exemple #2
0
func main() {
	output := make(chan string)
	defer func() {
		close(output)
		tail.Cleanup()
	}()

	for i, arg := range os.Args {
		go func(fileNumber int, filename string, outputChan chan string) {
			t, _ := tail.TailFile(filename, tail.Config{
				Follow: true, LimitRate: 15, MaxLineSize: 120,
			})
			for line := range t.Lines {
				message := line.Text
				output <- embolden(pad(filename, 15)+" => ") + colourize(strconv.Itoa(fileNumber+30), message)
			}
		}(i, arg, output)
	}

	for line := range output {
		fmt.Println(line)
	}
}
Exemple #3
0
func main() {
	log.Formatter = new(logger.StdOutFormatter)

	logLevel := getopt("LOG", "info")
	if level, err := logrus.ParseLevel(logLevel); err == nil {
		log.Level = level
	}

	log.Debug("reading environment variables...")
	host := getopt("HOST", "127.0.0.1")

	etcdPort := getopt("ETCD_PORT", "4001")

	etcdPath := getopt("ETCD_PATH", "/deis/router")

	hostEtcdPath := getopt("HOST_ETCD_PATH", "/deis/router/hosts/"+host)

	externalPort := getopt("EXTERNAL_PORT", "80")

	client := etcd.NewClient([]string{"http://" + host + ":" + etcdPort})

	// wait until etcd has discarded potentially stale values
	time.Sleep(timeout + 1)

	log.Debug("creating required defaults in etcd...")
	mkdirEtcd(client, "/deis/config")
	mkdirEtcd(client, "/deis/controller")
	mkdirEtcd(client, "/deis/services")
	mkdirEtcd(client, "/deis/domains")
	mkdirEtcd(client, "/deis/builder")
	mkdirEtcd(client, "/deis/certs")
	mkdirEtcd(client, "/deis/router/hosts")
	mkdirEtcd(client, "/deis/router/hsts")

	setDefaultEtcd(client, etcdPath+"/gzip", "on")

	log.Info("Starting Nginx...")

	go tailFile(nginxAccessLog)
	go tailFile(nginxErrorLog)

	nginxChan := make(chan bool)
	go launchNginx(nginxChan)
	<-nginxChan

	// FIXME: have to launch cron first so generate-certs will generate the files nginx requires
	go launchCron()

	waitForInitialConfd(host+":"+etcdPort, timeout)

	go launchConfd(host + ":" + etcdPort)

	go publishService(client, hostEtcdPath, host, externalPort, uint64(ttl.Seconds()))

	log.Info("deis-router running...")

	exitChan := make(chan os.Signal, 2)
	signal.Notify(exitChan, syscall.SIGTERM, syscall.SIGINT)
	<-exitChan
	tail.Cleanup()
}
Exemple #4
0
func cleanOnExit(exitChan chan os.Signal) {
	for _ = range exitChan {
		tail.Cleanup()
	}
}
Exemple #5
0
func cleanup() {
	log.Info("cleanup: closing open inotify watches")
	tail.Cleanup()
}
Exemple #6
0
// CleanupTailer cleans the global state. Should be called before existing
// the process.
func CleanupTailer() {
	tail.Cleanup()
}