1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.arvados.org/arvados.git/sdk/go/arvados"
19 // Don't trust "passenger-config" (or "bundle install") to handle
20 // concurrent installs.
21 var passengerInstallMutex sync.Mutex
23 var railsEnv = []string{
24 "ARVADOS_RAILS_LOG_TO_STDOUT=1",
25 "ARVADOS_CONFIG_NOLEGACY=1", // don't load database.yml from source tree
28 // Install a Rails application's dependencies, including phusion
30 type installPassenger struct {
32 depends []supervisedTask
35 func (runner installPassenger) String() string {
36 return "installPassenger:" + runner.src
39 func (runner installPassenger) Run(ctx context.Context, fail func(error), super *Supervisor) error {
40 err := super.wait(ctx, runner.depends...)
45 passengerInstallMutex.Lock()
46 defer passengerInstallMutex.Unlock()
49 err = super.RunProgram(ctx, runner.src, &buf, nil, "gem", "list", "--details", "bundler")
53 for _, version := range []string{"1.11.0", "1.17.3", "2.0.2"} {
54 if !strings.Contains(buf.String(), "("+version+")") {
55 err = super.RunProgram(ctx, runner.src, nil, nil, "gem", "install", "--user", "bundler:1.11", "bundler:1.17.3", "bundler:2.0.2")
62 err = super.RunProgram(ctx, runner.src, nil, nil, "bundle", "install", "--jobs", "4", "--path", filepath.Join(os.Getenv("HOME"), ".gem"))
66 err = super.RunProgram(ctx, runner.src, nil, nil, "bundle", "exec", "passenger-config", "build-native-support")
70 err = super.RunProgram(ctx, runner.src, nil, nil, "bundle", "exec", "passenger-config", "install-standalone-runtime")
74 err = super.RunProgram(ctx, runner.src, nil, nil, "bundle", "exec", "passenger-config", "validate-install")
75 if err != nil && !strings.Contains(err.Error(), "exit status 2") {
76 // Exit code 2 indicates there were warnings (like
77 // "other passenger installations have been detected",
78 // which we can't expect to avoid) but no errors.
79 // Other non-zero exit codes (1, 9) indicate errors.
85 type runPassenger struct {
88 depends []supervisedTask
91 func (runner runPassenger) String() string {
92 return "runPassenger:" + runner.src
95 func (runner runPassenger) Run(ctx context.Context, fail func(error), super *Supervisor) error {
96 err := super.wait(ctx, runner.depends...)
100 port, err := internalPort(runner.svc)
102 return fmt.Errorf("bug: no internalPort for %q: %v (%#v)", runner, err, runner.svc)
105 if lvl, ok := map[string]string{
113 }[super.cluster.SystemLogs.LogLevel]; ok {
116 super.waitShutdown.Add(1)
118 defer super.waitShutdown.Done()
119 err = super.RunProgram(ctx, runner.src, nil, railsEnv, "bundle", "exec",
120 "passenger", "start",
122 "--log-file", "/dev/stderr",
123 "--log-level", loglevel,
124 "--no-friendly-error-pages",
125 "--pid-file", filepath.Join(super.tempdir, "passenger."+strings.Replace(runner.src, "/", "_", -1)+".pid"))