func main() { log.SetPrefix("") log.SetFlags(0) flag.StringVar(&shuttleAddr, "addr", "127.0.0.1:9090", "shuttle admin address") flag.Usage = usage flag.Parse() if flag.NArg() < 1 { usage() } client = shuttle.NewClient(shuttleAddr) switch flag.Args()[0] { case "version": fmt.Println(buildVersion) return case "config": config(flag.Args()[1:]) case "update", "add": update(flag.Args()[1:]) case "remove": remove(flag.Args()[1:]) default: usage() } }
func Register(serviceRuntime *runtime.ServiceRuntime, configStore *config.Store, env, pool, hostIP, shuttleAddr string) { if shuttleAddr != "" { client = shuttle.NewClient(shuttleAddr) } RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, false) containerEvents := make(chan runtime.ContainerEvent) err := serviceRuntime.RegisterEvents(env, pool, hostIP, containerEvents) if err != nil { log.Printf("ERROR: Unable to register docker event listener: %s", err) } for { select { case ce := <-containerEvents: switch ce.Status { case "start": reg, err := configStore.RegisterService(env, pool, hostIP, ce.Container) if err != nil { log.Errorf("ERROR: Unable to register container: %s", err) continue } log.Printf("Registered %s running as %s for %s%s", strings.TrimPrefix(reg.ContainerName, "/"), reg.ContainerID[0:12], reg.Name, locationAt(reg)) registerShuttle(configStore, env, shuttleAddr) case "die", "stop": reg, err := configStore.UnRegisterService(env, pool, hostIP, ce.Container) if err != nil { log.Errorf("ERROR: Unable to unregister container: %s", err) continue } if reg != nil { log.Printf("Unregistered %s running as %s for %s%s", strings.TrimPrefix(reg.ContainerName, "/"), reg.ContainerID[0:12], reg.Name, locationAt(reg)) } RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, true) pruneShuttleBackends(configStore, env, shuttleAddr) } case <-time.After(10 * time.Second): RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, true) pruneShuttleBackends(configStore, env, shuttleAddr) } } }