func ChainConnectedToAService(chainName string, srv *definitions.ServiceDefinition) (*definitions.ServiceDefinition, error) { s, err := loaders.ChainsAsAService(chainName, false, srv.Operations.ContainerNumber) if err != nil { return nil, err } loaders.ConnectToAService(srv, chainName) // first make the service container linked to the chain loaders.ConnectToAService(s, srv.Name) // now make the chain container linked to the service container // XXX: we may have name collision here if we're not careful. util.OverWriteOperations(s.Operations, srv.Operations) return s, nil }
func StartChain(do *definitions.Do) error { logger.Infoln("Ensuring Key Server is Started.") //should it take a flag? keys server may be running another cNum // XXX: currently we don't use or need a key server. // plus this should be specified in a service def anyways keysService, err := loaders.LoadServiceDefinition("keys", false, 1) if err != nil { return err } err = perform.DockerRun(keysService.Service, keysService.Operations) if err != nil { return err } chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { logger.Infoln("Cannot start a chain I cannot find.") do.Result = "no file" return nil } if chain.Name == "" { logger.Infoln("Cannot start a chain without a name.") do.Result = "no name" return nil } chain.Service.Command = loaders.ErisChainStart if do.Run { chain.Service.Command = loaders.ErisChainStartApi } util.OverWriteOperations(chain.Operations, do.Operations) chain.Service.Environment = append(chain.Service.Environment, "CHAIN_ID="+chain.ChainID) logger.Infof("StartChainRaw to DockerRun =>\t%s\n", chain.Service.Name) logger.Debugf("\twith ChainID =>\t\t%v\n", chain.ChainID) logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment) logger.Debugf("\twith AllPortsPublshd =>\t%v\n", chain.Operations.PublishAllPorts) if err := perform.DockerRun(chain.Service, chain.Operations); err != nil { do.Result = "error" return err } return nil }
func StartService(do *definitions.Do) (err error) { var services []*definitions.ServiceDefinition cNum := do.Operations.ContainerNumber if err != nil { return err } do.Args = append(do.Args, do.ServicesSlice...) logger.Debugf("Building the Services Group =>\t%v\n", do.Args) for _, srv := range do.Args { // this forces CLI/Agent level overwrites of the Operations. // if this needs to get reversed, we should discuss on GH. s, e := BuildServicesGroup(srv, cNum) if e != nil { return e } services = append(services, s...) } for _, s := range services { //XXX does AutoMagic elim need for this? util.OverWriteOperations(s.Operations, do.Operations) } services, err = BuildChainGroup(do.ChainName, services) if err != nil { return err } // TODO: move this wg, ch logic into func StartGroup([]*definitions.ServiceDefinition) error {} wg, ch := new(sync.WaitGroup), make(chan error) StartGroup(ch, wg, services) go func() { wg.Wait() select { case ch <- nil: } }() if err := <-ch; err != nil { return err } return nil }
func StartService(do *definitions.Do) (err error) { var services []*definitions.ServiceDefinition cNum := do.Operations.ContainerNumber do.Args = append(do.Args, do.ServicesSlice...) logger.Infof("Building the Services Group =>\t%v\n", do.Args) for _, srv := range do.Args { s, e := BuildServicesGroup(srv, cNum) if e != nil { return e } services = append(services, s...) } for _, s := range services { // XXX does AutoMagic elim need for this? // [csk]: not totally we may need to have ops reconciliation, overwrite will, e.g., merge the maps and stuff util.OverWriteOperations(s.Operations, do.Operations) } logger.Debugln("services before build chain") for _, s := range services { logger.Debugln("\t", s.Name, s.Dependencies, s.Service.Links, s.Service.VolumesFrom) } services, err = BuildChainGroup(do.ChainName, services) if err != nil { return err } logger.Debugln("services after build chain") for _, s := range services { logger.Debugln("\t", s.Name, s.Dependencies, s.Service.Links, s.Service.VolumesFrom) } // NOTE: the top level service should be at the end of the list topService := services[len(services)-1] topService.Service.Environment = append(topService.Service.Environment, do.Env...) topService.Service.Links = append(topService.Service.Links, do.Links...) services[len(services)-1] = topService logger.Infof("Starting Services Group.\n") return StartGroup(services) }
func StartChain(do *definitions.Do) error { chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { logger.Infoln("Cannot start a chain I cannot find.") do.Result = "no file" return nil } if chain.Name == "" { logger.Infoln("Cannot start a chain without a name.") do.Result = "no name" return nil } // boot the dependencies (eg. keys) if err := bootDependencies(chain, do); err != nil { return err } chain.Service.Command = loaders.ErisChainStart util.OverWriteOperations(chain.Operations, do.Operations) chain.Service.Environment = append(chain.Service.Environment, "CHAIN_ID="+chain.ChainID) chain.Service.Environment = append(chain.Service.Environment, do.Env...) if do.Run { chain.Service.Environment = append(chain.Service.Environment, "ERISDB_API=true") } chain.Service.Links = append(chain.Service.Links, do.Links...) logger.Infof("StartChainRaw to DockerRun =>\t%s\n", chain.Service.Name) logger.Debugf("\twith ChainID =>\t\t%v\n", chain.ChainID) logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment) logger.Debugf("\twith AllPortsPublshd =>\t%v\n", chain.Operations.PublishAllPorts) if _, err := perform.DockerRun(chain.Service, chain.Operations); err != nil { do.Result = "error" return err } return nil }
func ConnectChainToService(chainFlag, chainNameAndOpts string, srv *definitions.ServiceDefinition) (*definitions.ServiceDefinition, error) { chainName, internalName, link, mount := util.ParseDependency(chainNameAndOpts) if chainFlag != "" { // flag overwrites whatever is in the service definition chainName = chainFlag } else if strings.HasPrefix(srv.Chain, "$chain") { // if there's a $chain and no flag or checked out chain, we err var err error chainName, err = util.GetHead() if chainName == "" || err != nil { return nil, fmt.Errorf("Marmot disapproval face.\nYou tried to start a service which has a `$chain` variable but didn't give us a chain.\nPlease rerun the command either after [eris chains checkout CHAINNAME] *or* with a --chain flag.\n") } } s, err := loaders.ChainsAsAService(chainName, false, srv.Operations.ContainerNumber) if err != nil { return nil, err } // link the service container linked to the chain // XXX: we may have name collision here if we're not careful. loaders.ConnectToAChain(srv.Service, srv.Operations, chainName, internalName, link, mount) util.OverWriteOperations(s.Operations, srv.Operations) return s, nil }