MCPcopy
hub / github.com/puma/puma-dev / lookupApp

Method lookupApp

dev/app.go:455–554  ·  view source on GitHub ↗

Find an app by domain name. If the app is not running, launch it.

(name string)

Source from the content-addressed store, hash-verified

453
454// Find an app by domain name. If the app is not running, launch it.
455func (a *AppPool) lookupApp(name string) (*App, error) {
456 a.lock.Lock()
457 defer a.lock.Unlock()
458
459 if a.apps == nil {
460 a.apps = make(map[string]*App)
461 }
462
463 app, ok := a.apps[name]
464 if ok {
465 return app, nil
466 }
467
468 path := filepath.Join(a.Dir, name)
469
470 a.Events.Add("app_lookup", "path", path)
471
472 stat, err := os.Stat(path)
473 destPath, _ := os.Readlink(path)
474
475 if err != nil {
476 if !os.IsNotExist(err) {
477 return nil, err
478 }
479
480 // Check there might be a link there but it's not valid
481 _, err := os.Lstat(path)
482 if err == nil {
483 fmt.Printf("! Bad symlink detected '%s'. Destination '%s' doesn't exist\n", path, destPath)
484 a.Events.Add("bad_symlink", "path", path, "dest", destPath)
485 }
486
487 // If possible, also try expanding - to / to allow for apps in subdirs
488 possible := strings.Replace(name, "-", "/", -1)
489 if possible == name {
490 return nil, ErrUnknownApp
491 }
492
493 path = filepath.Join(a.Dir, possible)
494
495 a.Events.Add("app_lookup", "path", path)
496
497 stat, err = os.Stat(path)
498 destPath, _ = os.Readlink(path)
499
500 if err != nil {
501 if !os.IsNotExist(err) {
502 return nil, err
503 }
504
505 // Check there might be a link there but it's not valid
506 _, err := os.Lstat(path)
507 if err == nil {
508 fmt.Printf("! Bad symlink detected '%s'. Destination '%s' doesn't exist\n", path, destPath)
509 a.Events.Add("bad_symlink", "path", path, "dest", destPath)
510 }
511
512 return nil, ErrUnknownApp

Callers 1

FindAppByDomainNameMethod · 0.95

Calls 3

LaunchAppMethod · 0.95
readProxyMethod · 0.95
AddMethod · 0.80

Tested by

no test coverage detected