15954: Merge branch 'master'
[arvados.git] / lib / boot / service.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package boot
6
7 import (
8         "context"
9         "path/filepath"
10
11         "git.arvados.org/arvados.git/sdk/go/arvados"
12 )
13
14 type runServiceCommand struct {
15         name    string
16         svc     arvados.Service
17         depends []bootTask
18 }
19
20 func (runner runServiceCommand) String() string {
21         return runner.name
22 }
23
24 func (runner runServiceCommand) Run(ctx context.Context, fail func(error), boot *Booter) error {
25         boot.wait(ctx, runner.depends...)
26         go func() {
27                 var u arvados.URL
28                 for u = range runner.svc.InternalURLs {
29                 }
30                 fail(boot.RunProgram(ctx, boot.tempdir, nil, []string{"ARVADOS_SERVICE_INTERNAL_URL=" + u.String()}, "arvados-server", runner.name, "-config", boot.configfile))
31         }()
32         return nil
33 }
34
35 type runGoProgram struct {
36         src     string
37         svc     arvados.Service
38         depends []bootTask
39 }
40
41 func (runner runGoProgram) String() string {
42         _, basename := filepath.Split(runner.src)
43         return basename
44 }
45
46 func (runner runGoProgram) Run(ctx context.Context, fail func(error), boot *Booter) error {
47         boot.wait(ctx, runner.depends...)
48         boot.RunProgram(ctx, runner.src, nil, nil, "go", "install")
49         if ctx.Err() != nil {
50                 return ctx.Err()
51         }
52         _, basename := filepath.Split(runner.src)
53         if len(runner.svc.InternalURLs) > 0 {
54                 // Run one for each URL
55                 for u := range runner.svc.InternalURLs {
56                         u := u
57                         go func() {
58                                 fail(boot.RunProgram(ctx, boot.tempdir, nil, []string{"ARVADOS_SERVICE_INTERNAL_URL=" + u.String()}, basename))
59                         }()
60                 }
61         } else {
62                 // Just run one
63                 go func() {
64                         fail(boot.RunProgram(ctx, boot.tempdir, nil, nil, basename))
65                 }()
66         }
67         return nil
68 }