func main() { flag.Parse() go common.RegisterTailCleanup() apptail.LoadConfig() fstorage := storage.NewFileStorage(*stateFile_path) tracker := storage.NewTracker(fstorage, *debug) tracker.LoadTailers() interval := time.Duration(int64(apptail.GetConfig().PersistPositionIntervalSeconds)) go tracker.StartSubmissionTimer(interval * time.Second) major, minor, patch := gozmq.Version() log.Infof("Starting apptail (zeromq %d.%d.%d)", major, minor, patch) log.Infof("Config: %+v\n", apptail.GetConfig()) uid := getUID() natsclient := server.NewNatsClient(3) mux := &sync.Mutex{} n := 0 started_instances := StartedInstance{} natsclient.Subscribe("logyard."+uid+".newinstance", func(instance *apptail.Instance) { n++ if started_instances.checkInstanceAndUpdate(n, instance.DockerId, mux) { go func() { instance.Tail(tracker) started_instances.delete(instance.DockerId, mux) }() } }) natsclient.Publish("logyard."+uid+".start", []byte("{}")) log.Infof("Waiting for app instances ...") go docker.DockerListener.Listen() // clean up the cache after restart docker.DockerListener.TrackerCleanUp(tracker) server.MarkRunning("apptail") apptail_event.MonitorCloudEvents() }
func main() { go common.RegisterTailCleanup() major, minor, patch := gozmq.Version() log.Infof("Starting systail (zeromq %d.%d.%d)", major, minor, patch) systail.LoadConfig() nodeid, err := server.LocalIP() if err != nil { common.Fatal("Failed to determine IP addr: %v", err) } log.Info("Host IP: ", nodeid) tailers := []*tail.Tail{} logFiles := systail.GetConfig().LogFiles fmt.Printf("%+v\n", logFiles) if len(logFiles) == 0 { common.Fatal("No log files exist in configuration.") } for name, logfile := range logFiles { t, err := tailLogFile(name, logfile, nodeid) if err != nil { common.Fatal("%v", err) } tailers = append(tailers, t) } server.MarkRunning("systail") for _, tail := range tailers { err := tail.Wait() if err != nil { log.Errorf("Cannot tail [%s]: %s", tail.Filename, err) } } // we don't expect any of the tailers to exit with or without // error. log.Error("No file left to tail; exiting.") os.Exit(1) }