(ctx context.Context, service, sock, basePath, dumpSpec string)
| 150 | } |
| 151 | |
| 152 | func start(ctx context.Context, service, sock, basePath, dumpSpec string) (string, uint32, string, error) { |
| 153 | path := filepath.Join(basePath, service) |
| 154 | |
| 155 | runtimeConfig := getRuntimeConfig(path) |
| 156 | |
| 157 | rootfs := filepath.Join(path, "rootfs") |
| 158 | |
| 159 | if err := prepareFilesystem(path, runtimeConfig); err != nil { |
| 160 | return "", 0, "preparing filesystem", err |
| 161 | } |
| 162 | |
| 163 | cli, err := client.New(sock) |
| 164 | if err != nil { |
| 165 | return "", 0, "creating containerd client", err |
| 166 | } |
| 167 | |
| 168 | var spec *specs.Spec |
| 169 | specf, err := os.Open(filepath.Join(path, "config.json")) |
| 170 | if err != nil { |
| 171 | return "", 0, "failed to read service spec", err |
| 172 | } |
| 173 | if err := json.NewDecoder(specf).Decode(&spec); err != nil { |
| 174 | return "", 0, "failed to parse service spec", err |
| 175 | } |
| 176 | |
| 177 | spec.Root.Path = rootfs |
| 178 | |
| 179 | if dumpSpec != "" { |
| 180 | d, err := os.Create(dumpSpec) |
| 181 | if err != nil { |
| 182 | return "", 0, "failed to open file for spec dump", err |
| 183 | } |
| 184 | enc := json.NewEncoder(d) |
| 185 | enc.SetIndent("", " ") |
| 186 | if err := enc.Encode(&spec); err != nil { |
| 187 | return "", 0, "failed to write spec dump", err |
| 188 | } |
| 189 | |
| 190 | } |
| 191 | |
| 192 | if runtimeConfig.Namespace != "" { |
| 193 | ctx = namespaces.WithNamespace(ctx, runtimeConfig.Namespace) |
| 194 | } |
| 195 | |
| 196 | ctr, err := cli.NewContainer(ctx, service, client.WithSpec(spec)) |
| 197 | if err != nil { |
| 198 | return "", 0, "failed to create container", err |
| 199 | } |
| 200 | |
| 201 | logger := GetLog(varLogDir) |
| 202 | |
| 203 | io := func(id string) (cio.IO, error) { |
| 204 | stdoutFile := logger.Path(service + ".out") |
| 205 | stderrFile := logger.Path(service) |
| 206 | return &logio{ |
| 207 | cio.Config{ |
| 208 | Stdin: "/dev/null", |
| 209 | Stdout: stdoutFile, |
no test coverage detected