func (r RouteTableManagerEC2) checkRemoteHealthCheck(contextLogger *log.Entry, route *ec2.Route, rs ManageRoutesSpec) bool { contextLogger = contextLogger.WithFields(log.Fields{ "remote_healthcheck": rs.RemoteHealthcheckName, "current_eni": *(route.NetworkInterfaceId), }) contextLogger.Info("Has remote healthcheck ") if ip, ok := eniToIP[*route.NetworkInterfaceId]; ok { contextLogger = contextLogger.WithFields(log.Fields{"current_ip": ip}) if hc, ok := rs.remotehealthchecks[ip]; ok { contextLogger = contextLogger.WithFields(log.Fields{ "healthcheck_healthy": hc.IsHealthy(), "healthcheck_ready": hc.CanPassYet(), }) contextLogger.Info("Has remote healthcheck instance") if hc.CanPassYet() { if hc.IsHealthy() { contextLogger.Debug("Not replacing route, as current route is healthy") return false } else { contextLogger.Debug("Replacing route as remote healthcheck is unhealthy") } } else { contextLogger.Debug("Not replacing route as remote healthcheck cannot pass yet") return false } } else { contextLogger.Error("Cannot find healthcheck") return false } } else { contextLogger.Error("Cannot find ip for ENI") return false } return true }
func (k *Kickass) search(s Searcher, log *logrus.Entry) ([]polochon.Torrent, error) { users := s.users() result := []polochon.Torrent{} log = log.WithFields(logrus.Fields{ "search_category": s.category(), "search_string": s.searchStr(), }) if err := s.validate(); err != nil { log.Error(err) return nil, err } for _, u := range users { torrents, err := k.searchUser(s, log, u) if err != nil { return nil, err } result = append(result, torrents...) } return polochon.FilterTorrents(result), nil }
// Start statrs a sub app in its own goroutine func (a *App) subAppStart(app subapp.App, log *logrus.Entry) { log.Debugf("starting sub app %q", app.Name()) a.wg.Add(1) go func() { defer a.wg.Done() if err := app.Run(log); err != nil { // Check the error type, if it comes from a panic recovery // reload the app switch e := err.(type) { case *errors.Error: errors.LogErrors(log.WithField("app", app.Name()), e) // Notify the safeguard of the error a.safeguard.Event() // Write to the reload channel in a goroutine to prevent deadlocks go func() { a.reload <- app }() // Only log the error default: log.Error(err) go a.Stop(log) } } }() log.Debugf("sub app %q started", app.Name()) }
func (fs *FsNotify) eventHandler(ctx polochon.FsNotifierCtx, log *logrus.Entry) { // Notify the waitgroup ctx.Wg.Add(1) defer ctx.Wg.Done() // Close the watcher when done defer fs.watcher.Close() for { select { case <-ctx.Done: log.Debug("fsnotify is done watching") return case ev := <-fs.watcher.Events: if ev.Op != fsnotify.Create && ev.Op != fsnotify.Chmod { continue } // Wait for the delay time before sending an event. // Transmission creates the folder and move the files afterwards. // We need to wait for the file to be moved in before sending the // event. Delay is the estimated time to wait. go func() { time.Sleep(DELAY) ctx.Event <- ev.Name }() case err := <-fs.watcher.Errors: log.Error(err) } } }
func (d *Downloader) downloadMissingMovies(wl *polochon.Wishlist, log *logrus.Entry) { log = log.WithField("function", "download_movies") for _, wantedMovie := range wl.Movies { ok, err := d.library.HasMovie(wantedMovie.ImdbID) if err != nil { log.Error(err) continue } if ok { log.Debugf("movie %q already in the video store", wantedMovie.ImdbID) continue } m := polochon.NewMovie(d.config.Movie) m.ImdbID = wantedMovie.ImdbID log = log.WithField("imdb_id", m.ImdbID) if err := m.GetDetails(log); err != nil { errors.LogErrors(log, err) if errors.IsFatal(err) { continue } } log = log.WithField("title", m.Title) if err := m.GetTorrents(log); err != nil && err != polochon.ErrMovieTorrentNotFound { errors.LogErrors(log, err) if errors.IsFatal(err) { continue } } // Keep the torrent URL var torrentURL string quality_loop: for _, q := range wantedMovie.Qualities { for _, t := range m.Torrents { if t.Quality == q { torrentURL = t.URL break quality_loop } } } if torrentURL == "" { log.Debug("no torrent found") continue } if err := d.config.Downloader.Client.Download(torrentURL, log); err != nil { log.Error(err) continue } } }
func handleApiEvents(logContext *logrus.Entry, client string, events []*omaha.Event) error { for _, event := range events { evType, err := strconv.Atoi(event.Type) if err != nil { return err } evResult, err := strconv.Atoi(event.Result) if err != nil { return err } err = db.LogEvent(client, evType, evResult) if err != nil { logContext.Error(err) } switch evType { case eventTypeDownload: logContext.Info("Client is downloading new version.") case eventTypeArrive: logContext.Info("Client finished download.") case eventTypeApply: switch evResult { case eventResultOK: logContext.Info("Client applied package.") case eventResultError: logContext.Info("Client errored during update.") case eventResultDone: logContext.Info("Client upgraded to current version.") } case eventTypeSuccess: logContext.Info("Install success. Update completion prevented by instance.") default: logContext.Warn("Unknown event type %v.", evType) } } return nil }
func (d *Downloader) downloadMissingShows(wl *polochon.Wishlist, log *logrus.Entry) { log = log.WithField("function", "download_shows") for _, wishedShow := range wl.Shows { s := polochon.NewShow(d.config.Show) s.ImdbID = wishedShow.ImdbID log = log.WithField("imdb_id", s.ImdbID) if err := s.GetDetails(log); err != nil { errors.LogErrors(log, err) if errors.IsFatal(err) { continue } } calendar, err := s.GetCalendar(log) if err != nil { errors.LogErrors(log, err) if errors.IsFatal(err) { continue } } for _, calEpisode := range calendar.Episodes { // Check if the episode should be downloaded if calEpisode.IsOlder(wishedShow) { continue } // Check if the episode has already been downloaded ok, err := d.library.HasShowEpisode(wishedShow.ImdbID, calEpisode.Season, calEpisode.Episode) if err != nil { log.Error(err) continue } if ok { continue } // Setup the episode e := polochon.NewShowEpisode(d.config.Show) e.ShowImdbID = wishedShow.ImdbID e.ShowTitle = s.Title e.Season = calEpisode.Season e.Episode = calEpisode.Episode log = log.WithFields(logrus.Fields{ "show_imdb_id": e.ShowImdbID, "show_title": e.ShowTitle, "season": e.Season, "episode": e.Episode, }) if err := e.GetTorrents(log); err != nil && err != polochon.ErrShowEpisodeTorrentNotFound { errors.LogErrors(log, err) if errors.IsFatal(err) { continue } } // Keep the torrent URL var torrentURL string quality_loop: for _, q := range wishedShow.Qualities { for _, t := range e.Torrents { if t.Quality == q { torrentURL = t.URL break quality_loop } } } if torrentURL == "" { log.Debug("no torrent found") continue } if err := d.config.Downloader.Client.Download(torrentURL, log); err != nil { log.Error(err) continue } } } }
func buildImage( log *logrus.Entry, inputFile, outputFile string, fromImage, novnc bool, boot, cdrom string, size int, ) error { // Find absolute outputFile outputFile, err := filepath.Abs(outputFile) if err != nil { log.Error("Failed to resolve output file, error: ", err) return err } // Create temp folder for the image tempFolder, err := ioutil.TempDir("", "taskcluster-worker-build-image-") if err != nil { log.Error("Failed to create temporary folder, error: ", err) return err } defer os.RemoveAll(tempFolder) var img *image.MutableImage if !fromImage { // Read machine definition machine, err2 := vm.LoadMachine(inputFile) if err2 != nil { log.Error("Failed to load machine file from ", inputFile, " error: ", err2) return err2 } // Construct MutableImage log.Info("Creating MutableImage") img, err2 = image.NewMutableImage(tempFolder, int(size), machine) if err2 != nil { log.Error("Failed to create image, error: ", err2) return err2 } } else { img, err = image.NewMutableImageFromFile(inputFile, tempFolder) if err != nil { log.Error("Failed to load image, error: ", err) return err } } // Create temp folder for sockets socketFolder, err := ioutil.TempDir("", "taskcluster-worker-sockets-") if err != nil { log.Error("Failed to create temporary folder, error: ", err) return err } defer os.RemoveAll(socketFolder) // Setup a user-space network log.Info("Creating user-space network") net, err := network.NewUserNetwork(tempFolder) if err != nil { log.Error("Failed to create user-space network, error: ", err) return err } // Setup logService so that logs can be posted to meta-service at: // http://169.254.169.254/v1/log net.SetHandler(&logService{Destination: os.Stdout}) // Create virtual machine log.Info("Creating virtual machine") vm, err := vm.NewVirtualMachine(img.Machine().Options(), img, net, socketFolder, boot, cdrom, log.WithField("component", "vm")) if err != nil { log.Error("Failed to recreated virtual-machine, error: ", err) return err } // Start the virtual machine log.Info("Starting virtual machine") vm.Start() // Open VNC display if !novnc { go qemurun.StartVNCViewer(vm.VNCSocket(), vm.Done) } // Wait for interrupt to gracefully kill everything interrupted := make(chan os.Signal, 1) signal.Notify(interrupted, os.Interrupt) // Wait for virtual machine to be done, or we get interrupted select { case <-interrupted: vm.Kill() err = errors.New("SIGINT received, aborting virtual machine") case <-vm.Done: err = vm.Error } <-vm.Done signal.Stop(interrupted) defer img.Dispose() if err != nil { if e, ok := err.(*exec.ExitError); ok { log.Error("QEMU error: ", string(e.Stderr)) } log.Info("Error running virtual machine: ", err) return err } // Package up the finished image log.Info("Package virtual machine image") err = img.Package(outputFile) if err != nil { log.Error("Failed to package finished image, error: ", err) return err } return nil }