MCPcopy Create free account
hub / github.com/cortexproject/cortex / Start

Method Start

integration/e2e/service.go:103–149  ·  view source on GitHub ↗
(networkName, sharedDir string)

Source from the content-addressed store, hash-verified

101}
102
103func (s *ConcreteService) Start(networkName, sharedDir string) (err error) {
104 // In case of any error, if the container was already created, we
105 // have to cleanup removing it. We ignore the error of the "docker rm"
106 // because we don't know if the container was created or not.
107 defer func() {
108 if err != nil {
109 _, _ = RunCommandAndGetOutput("docker", "rm", "--force", s.name)
110 }
111 }()
112
113 cmd := exec.Command("docker", s.buildDockerRunArgs(networkName, sharedDir)...)
114 cmd.Stdout = &LinePrefixLogger{prefix: s.name + ": ", logger: logger}
115 cmd.Stderr = &LinePrefixLogger{prefix: s.name + ": ", logger: logger}
116 if err = cmd.Start(); err != nil {
117 return err
118 }
119 s.usedNetworkName = networkName
120
121 // Wait until the container has been started.
122 if err = s.WaitForRunning(); err != nil {
123 return err
124 }
125
126 // Get the dynamic local ports mapped to the container.
127 for _, containerPort := range s.networkPorts {
128 var out []byte
129
130 out, err = RunCommandAndGetOutput("docker", "port", s.containerName(), strconv.Itoa(containerPort))
131 if err != nil {
132 // Catch init errors.
133 if werr := s.WaitForRunning(); werr != nil {
134 return errors.Wrapf(werr, "failed to get mapping for port as container %s exited: %v", s.containerName(), err)
135 }
136 return errors.Wrapf(err, "unable to get mapping for port %d; service: %s; output: %q", containerPort, s.name, out)
137 }
138
139 localPort, err := parseDockerIPv4Port(string(out))
140 if err != nil {
141 return errors.Wrapf(err, "unable to get mapping for port %d (output: %s); service: %s", containerPort, string(out), s.name)
142 }
143
144 s.networkPortsContainerToLocal[containerPort] = localPort
145 }
146
147 logger.Log("Ports for container:", s.containerName(), "Mapping:", s.networkPortsContainerToLocal)
148 return nil
149}
150
151func (s *ConcreteService) Stop() error {
152 if !s.isExpectedRunning() {

Callers

nothing calls this directly

Calls 7

buildDockerRunArgsMethod · 0.95
WaitForRunningMethod · 0.95
containerNameMethod · 0.95
RunCommandAndGetOutputFunction · 0.85
parseDockerIPv4PortFunction · 0.85
StartMethod · 0.65
LogMethod · 0.45

Tested by

no test coverage detected