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 if super.ClusterType == "production" {
41 // passenger has already been installed via package
44 err := super.wait(ctx, runner.depends...)
49 passengerInstallMutex.Lock()
50 defer passengerInstallMutex.Unlock()
53 err = super.RunProgram(ctx, runner.src, runOptions{output: &buf}, "gem", "list", "--details", "bundler")
57 for _, version := range []string{"1.16.6", "1.17.3", "2.0.2"} {
58 if !strings.Contains(buf.String(), "("+version+")") {
59 err = super.RunProgram(ctx, runner.src, runOptions{}, "gem", "install", "--user", "--conservative", "--no-document", "bundler:1.16.6", "bundler:1.17.3", "bundler:2.0.2")
66 err = super.RunProgram(ctx, runner.src, runOptions{}, "bundle", "install", "--jobs", "4", "--path", filepath.Join(os.Getenv("HOME"), ".gem"))
70 err = super.RunProgram(ctx, runner.src, runOptions{}, "bundle", "exec", "passenger-config", "build-native-support")
74 err = super.RunProgram(ctx, runner.src, runOptions{}, "bundle", "exec", "passenger-config", "install-standalone-runtime")
78 err = super.RunProgram(ctx, runner.src, runOptions{}, "bundle", "exec", "passenger-config", "validate-install")
79 if err != nil && !strings.Contains(err.Error(), "exit status 2") {
80 // Exit code 2 indicates there were warnings (like
81 // "other passenger installations have been detected",
82 // which we can't expect to avoid) but no errors.
83 // Other non-zero exit codes (1, 9) indicate errors.
89 type runPassenger struct {
90 src string // path to app in source tree
91 varlibdir string // path to app (relative to /var/lib/arvados) in OS package
93 depends []supervisedTask
96 func (runner runPassenger) String() string {
97 return "runPassenger:" + runner.src
100 func (runner runPassenger) Run(ctx context.Context, fail func(error), super *Supervisor) error {
101 err := super.wait(ctx, runner.depends...)
105 host, port, err := internalPort(runner.svc)
107 return fmt.Errorf("bug: no internalPort for %q: %v (%#v)", runner, err, runner.svc)
110 if super.ClusterType == "production" {
111 appdir = "/var/lib/arvados/" + runner.varlibdir
116 if lvl, ok := map[string]string{
124 }[super.cluster.SystemLogs.LogLevel]; ok {
127 super.waitShutdown.Add(1)
129 defer super.waitShutdown.Done()
132 "passenger", "start",
135 "--log-file", "/dev/stderr",
136 "--log-level", loglevel,
137 "--no-friendly-error-pages",
138 "--disable-anonymous-telemetry",
139 "--disable-security-update-check",
140 "--no-compile-runtime",
141 "--no-install-runtime",
142 "--pid-file", filepath.Join(super.wwwtempdir, "passenger."+strings.Replace(appdir, "/", "_", -1)+".pid"),
145 env: append([]string{
146 "TMPDIR=" + super.wwwtempdir,
149 if super.ClusterType == "production" {
150 opts.user = "www-data"
151 opts.env = append(opts.env, "HOME=/var/www")
153 // This would be desirable when changing uid
154 // too, but it fails because /dev/stderr is a
155 // symlink to a pty owned by root: "nginx:
156 // [emerg] open() "/dev/stderr" failed (13:
157 // Permission denied)"
158 cmdline = append(cmdline, "--log-file", "/dev/stderr")
160 err = super.RunProgram(ctx, appdir, opts, cmdline[0], cmdline[1:]...)