15954: Trim log prefix.
[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         bindir := filepath.Join(boot.tempdir, "bin")
49         err := boot.RunProgram(ctx, runner.src, nil, []string{"GOBIN=" + bindir}, "go", "install")
50         if err != nil {
51                 return err
52         }
53         if ctx.Err() != nil {
54                 return ctx.Err()
55         }
56         _, basename := filepath.Split(runner.src)
57         binfile := filepath.Join(bindir, basename)
58
59         if len(runner.svc.InternalURLs) > 0 {
60                 // Run one for each URL
61                 for u := range runner.svc.InternalURLs {
62                         u := u
63                         boot.waitShutdown.Add(1)
64                         go func() {
65                                 defer boot.waitShutdown.Done()
66                                 fail(boot.RunProgram(ctx, boot.tempdir, nil, []string{"ARVADOS_SERVICE_INTERNAL_URL=" + u.String()}, binfile))
67                         }()
68                 }
69         } else {
70                 // Just run one
71                 boot.waitShutdown.Add(1)
72                 go func() {
73                         defer boot.waitShutdown.Done()
74                         fail(boot.RunProgram(ctx, boot.tempdir, nil, nil, binfile))
75                 }()
76         }
77         return nil
78 }