func poolCreate(c *cli.Context) { ensureEnvArg(c) ensurePoolArg(c) initStore(c) created, err := configStore.CreatePool(utils.GalaxyPool(c), utils.GalaxyEnv(c)) if err != nil { log.Fatalf("ERROR: Could not create pool: %s", err) return } if created { log.Printf("Pool %s created\n", utils.GalaxyPool(c)) } else { log.Printf("Pool %s already exists\n", utils.GalaxyPool(c)) } ec2host, err := runtime.EC2PublicHostname() if err != nil || ec2host == "" { log.Debug("not running from AWS, skipping pool creation") return } // now create the cloudformation stack // is this fails, the stack can be created separately with // stack:create_pool stackCreatePool(c) }
func NewConsulBackend() *ConsulBackend { client, err := consul.NewClient(consul.DefaultConfig()) if err != nil { // this shouldn't ever error with the default config panic(err) } node, err := client.Agent().NodeName() if err != nil { log.Fatal(err) } // find an existing galaxy session if one exists, or create a new one sessions, _, err := client.Session().Node(node, nil) if err != nil { log.Fatal(err) } var session *consul.SessionEntry for _, s := range sessions { if s.Name == "galaxy" { session = s break } } // we have a session, now make sure we can renew it so it doesn't expire // before we start running if session != nil { session, _, err = client.Session().Renew(session.ID, nil) if err != nil { log.Debug("error renewing galaxy session:", err) } } // no existing session, so create a new one if session == nil { session = &consul.SessionEntry{ Name: "galaxy", Behavior: "delete", TTL: "15s", } session.ID, _, err = client.Session().Create(session, nil) if err != nil { // we can't continue without a session for key TTLs log.Fatal(err) } } // keep our session alive in the background done := make(chan struct{}) go client.Session().RenewPeriodic("10s", session.ID, nil, done) return &ConsulBackend{ client: client, sessionID: session.ID, done: done, seen: &eventCache{ seen: make(map[string]uint64), }, } }