1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/arvados.git/sdk/go/arvados"
15 // Run a service using the arvados-server binary.
17 // In future this will bring up the service in the current process,
18 // but for now (at least until the subcommand handlers get a shutdown
19 // mechanism) it starts a child process using the arvados-server
20 // binary, which the supervisor is assumed to have installed in
21 // {super.tempdir}/bin/.
22 type runServiceCommand struct {
23 name string // arvados-server subcommand, e.g., "controller"
24 svc arvados.Service // cluster.Services.* entry with the desired InternalURLs
25 depends []supervisedTask // wait for these tasks before starting
28 func (runner runServiceCommand) String() string {
32 func (runner runServiceCommand) Run(ctx context.Context, fail func(error), super *Supervisor) error {
33 binfile := filepath.Join(super.bindir, "arvados-server")
34 err := super.RunProgram(ctx, super.bindir, runOptions{}, binfile, "-version")
38 super.wait(ctx, createCertificates{})
39 super.wait(ctx, runner.depends...)
40 for u := range runner.svc.InternalURLs {
42 if islocal, err := addrIsLocal(u.Host); err != nil {
47 super.waitShutdown.Add(1)
49 defer super.waitShutdown.Done()
50 fail(super.RunProgram(ctx, super.tempdir, runOptions{env: []string{"ARVADOS_SERVICE_INTERNAL_URL=" + u.String()}}, binfile, runner.name, "-config", super.configfile))
56 // Run a Go service that isn't bundled in arvados-server.
57 type runGoProgram struct {
58 src string // source dir, e.g., "services/keepproxy"
59 svc arvados.Service // cluster.Services.* entry with the desired InternalURLs
60 depends []supervisedTask // wait for these tasks before starting
63 func (runner runGoProgram) String() string {
64 _, basename := filepath.Split(runner.src)
68 func (runner runGoProgram) Run(ctx context.Context, fail func(error), super *Supervisor) error {
69 if len(runner.svc.InternalURLs) == 0 {
70 return errors.New("bug: runGoProgram needs non-empty svc.InternalURLs")
73 binfile, err := super.installGoProgram(ctx, runner.src)
81 err = super.RunProgram(ctx, super.tempdir, runOptions{}, binfile, "-version")
86 super.wait(ctx, createCertificates{})
87 super.wait(ctx, runner.depends...)
88 for u := range runner.svc.InternalURLs {
90 if islocal, err := addrIsLocal(u.Host); err != nil {
95 super.waitShutdown.Add(1)
97 defer super.waitShutdown.Done()
98 fail(super.RunProgram(ctx, super.tempdir, runOptions{env: []string{"ARVADOS_SERVICE_INTERNAL_URL=" + u.String()}}, binfile))