1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
27 "git.arvados.org/arvados.git/lib/cmd"
28 "git.arvados.org/arvados.git/sdk/go/ctxlog"
32 var Command cmd.Handler = &installCommand{}
34 const goversion = "1.21.10"
37 defaultRubyVersion = "3.2.2"
38 defaultBundlerVersion = "~> 2.4.0"
39 defaultSingularityVersion = "3.10.4"
41 geckoversion = "0.24.0"
42 gradleversion = "5.3.1"
43 defaultNodejsVersion = "14.21.3"
44 devtestDatabasePassword = "insecure_arvados_test"
47 //go:embed arvados.service
48 var arvadosServiceFile []byte
50 type installCommand struct {
57 SingularityVersion string
62 func (inst *installCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
63 logger := ctxlog.New(stderr, "text", "info")
64 ctx := ctxlog.Context(context.Background(), logger)
65 ctx, cancel := context.WithCancel(ctx)
71 logger.WithError(err).Info("exiting")
75 flags := flag.NewFlagSet(prog, flag.ContinueOnError)
76 flags.SetOutput(stderr)
77 versionFlag := flags.Bool("version", false, "Write version information to stdout and exit 0")
78 flags.StringVar(&inst.ClusterType, "type", "production", "cluster `type`: development, test, production, or package")
79 flags.StringVar(&inst.SourcePath, "source", "/arvados", "source tree location (required for -type=package)")
80 flags.StringVar(&inst.Commit, "commit", "", "source commit `hash` to embed (blank means use 'git log' or all-zero placeholder)")
81 flags.StringVar(&inst.PackageVersion, "package-version", "0.0.0", "version string to embed in executable files")
82 flags.StringVar(&inst.RubyVersion, "ruby-version", defaultRubyVersion, "Ruby `version` to install (do not override in production mode)")
83 flags.StringVar(&inst.BundlerVersion, "bundler-version", defaultBundlerVersion, "Bundler `version` to install (do not override in production mode)")
84 flags.StringVar(&inst.SingularityVersion, "singularity-version", defaultSingularityVersion, "Singularity `version` to install (do not override in production mode)")
85 flags.StringVar(&inst.NodejsVersion, "nodejs-version", defaultNodejsVersion, "Nodejs `version` to install (not applicable in production mode)")
86 flags.BoolVar(&inst.EatMyData, "eatmydata", false, "use eatmydata to speed up install")
88 if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok {
90 } else if *versionFlag {
91 return cmd.Version.RunCommand(prog, args, stdin, stdout, stderr)
94 if inst.Commit == "" {
95 if commit, err := exec.Command("env", "-C", inst.SourcePath, "git", "log", "-n1", "--format=%H").CombinedOutput(); err == nil {
96 inst.Commit = strings.TrimSpace(string(commit))
98 inst.Commit = "0000000000000000000000000000000000000000"
102 var dev, test, prod, pkg bool
103 switch inst.ClusterType {
113 err = fmt.Errorf("invalid cluster type %q (must be 'development', 'test', 'production', or 'package')", inst.ClusterType)
118 err = errors.New("production install is not yet implemented")
122 if ok, _ := regexp.MatchString(`^\d\.\d+\.\d+$`, inst.RubyVersion); !ok {
123 fmt.Fprintf(stderr, "invalid argument %q for -ruby-version\n", inst.RubyVersion)
126 if ok, _ := regexp.MatchString(`^ *(|~>|[<>!=]=) *\d`, inst.BundlerVersion); !ok {
127 fmt.Fprintf(stderr, "invalid argument %q for -bundler-version\n", inst.BundlerVersion)
130 if ok, _ := regexp.MatchString(`^\d`, inst.SingularityVersion); !ok {
131 fmt.Fprintf(stderr, "invalid argument %q for -singularity-version\n", inst.SingularityVersion)
134 if ok, _ := regexp.MatchString(`^\d`, inst.NodejsVersion); !ok {
135 fmt.Fprintf(stderr, "invalid argument %q for -nodejs-version\n", inst.NodejsVersion)
139 osv, err := identifyOS()
144 listdir, err := os.Open("/var/lib/apt/lists")
146 logger.Warnf("error while checking whether to run apt-get update: %s", err)
147 } else if names, _ := listdir.Readdirnames(1); len(names) == 0 {
148 // Special case for a base docker image where the
149 // package cache has been deleted and all "apt-get
150 // install" commands will fail unless we fetch repos.
151 cmd := exec.CommandContext(ctx, "apt-get", "update")
161 cmd := exec.CommandContext(ctx, "apt-get", "install", "--yes", "--no-install-recommends", "eatmydata")
162 cmd.Env = append(os.Environ(), "DEBIAN_FRONTEND=noninteractive")
171 pkgs := prodpkgs(osv)
176 "eatmydata", // install it for later steps, even if we're not using it now
180 if dev || test || pkg {
189 "default-jdk-headless",
190 "default-jre-headless",
195 "libgbm1", // cypress / workbench2 tests
212 "postgresql-contrib",
215 "python3-virtualenv",
228 "zlib1g-dev", // services/api
231 if osv.Debian && osv.Major <= 10 {
232 pkgs = append(pkgs, "iceweasel")
233 } else if osv.Debian && osv.Major >= 11 {
234 pkgs = append(pkgs, "firefox-esr")
236 pkgs = append(pkgs, "firefox")
238 if osv.Debian && osv.Major >= 11 {
239 // not available in Debian <11
240 pkgs = append(pkgs, "s3cmd")
245 "libglib2.0-dev", // singularity (conmon)
246 "libseccomp-dev", // singularity (seccomp)
247 "squashfs-tools", // singularity
248 "gnupg") // docker install recipe
251 case osv.Debian && osv.Major >= 10,
252 osv.Ubuntu && osv.Major >= 22:
253 pkgs = append(pkgs, "g++", "libcurl4", "libcurl4-openssl-dev")
254 case osv.Debian || osv.Ubuntu:
255 pkgs = append(pkgs, "g++", "libcurl3", "libcurl3-openssl-dev")
257 pkgs = append(pkgs, "gcc", "gcc-c++", "libcurl-devel", "postgresql-devel")
259 cmd := exec.CommandContext(ctx, "apt-get")
261 cmd = exec.CommandContext(ctx, "eatmydata", "apt-get")
263 cmd.Args = append(cmd.Args, "install", "--yes", "--no-install-recommends")
264 cmd.Args = append(cmd.Args, pkgs...)
265 cmd.Env = append(os.Environ(), "DEBIAN_FRONTEND=noninteractive")
275 if havedockerversion, err2 := exec.Command("docker", "--version").CombinedOutput(); err2 == nil {
276 logger.Printf("%s installed, assuming that version is ok", bytes.TrimSuffix(havedockerversion, []byte("\n")))
277 } else if osv.Debian {
281 codename = "bullseye"
283 codename = "bookworm"
285 err = fmt.Errorf("don't know how to install docker-ce for debian %d", osv.Major)
289 rm -f /usr/share/keyrings/docker-archive-keyring.gpg
290 curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
291 echo 'deb [arch=`+runtime.GOARCH+` signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian/ `+codename+` stable' | \
292 tee /etc/apt/sources.list.d/docker.list
294 DEBIAN_FRONTEND=noninteractive apt-get --yes --no-install-recommends install docker-ce
300 err = fmt.Errorf("don't know how to install docker for osversion %v", osv)
305 key=fs.inotify.max_user_watches
307 if [[ "$(sysctl --values "${key}")" -lt "${min}" ]]; then
308 sysctl "${key}=${min}"
309 # writing sysctl worked, so we should make it permanent
310 echo "${key}=${min}" | tee -a /etc/sysctl.conf
315 err = fmt.Errorf("couldn't set fs.inotify.max_user_watches value. (Is this a docker container? Fix this on the docker host by adding fs.inotify.max_user_watches=524288 to /etc/sysctl.conf and running `sysctl -p`)")
320 os.Mkdir("/var/lib/arvados", 0755)
321 os.Mkdir("/var/lib/arvados/tmp", 0700)
323 u, er := user.Lookup("www-data")
325 err = fmt.Errorf("user.Lookup(%q): %w", "www-data", er)
328 uid, _ := strconv.Atoi(u.Uid)
329 gid, _ := strconv.Atoi(u.Gid)
330 os.Mkdir("/var/lib/arvados/wwwtmp", 0700)
331 err = os.Chown("/var/lib/arvados/wwwtmp", uid, gid)
336 rubyminorversion := inst.RubyVersion[:strings.LastIndex(inst.RubyVersion, ".")]
337 if haverubyversion, err := exec.Command("/var/lib/arvados/bin/ruby", "-v").CombinedOutput(); err == nil && bytes.HasPrefix(haverubyversion, []byte("ruby "+inst.RubyVersion)) {
338 logger.Print("ruby " + inst.RubyVersion + " already installed")
341 rubyversion="`+inst.RubyVersion+`"
342 rubyminorversion="`+rubyminorversion+`"
344 trap 'rm -r "${tmp}"' ERR EXIT
345 wget --progress=dot:giga -O- "https://cache.ruby-lang.org/pub/ruby/$rubyminorversion/ruby-$rubyversion.tar.gz" | tar -C "${tmp}" -xzf -
346 cd "${tmp}/ruby-$rubyversion"
347 ./configure --disable-install-static-library --enable-shared --disable-install-doc --prefix /var/lib/arvados
349 rm -f /var/lib/arvados/bin/erb
351 if [[ "$rubyversion" > "3" ]]; then
352 /var/lib/arvados/bin/gem update --no-document --system 3.4.21
354 /var/lib/arvados/bin/gem install --conservative --no-document --version '`+inst.BundlerVersion+`' bundler
362 if havegoversion, err := exec.Command("/usr/local/bin/go", "version").CombinedOutput(); err == nil && bytes.HasPrefix(havegoversion, []byte("go version go"+goversion+" ")) {
363 logger.Print("go " + goversion + " already installed")
367 rm -rf /var/lib/arvados/go/
368 wget --progress=dot:giga -O- https://storage.googleapis.com/golang/go`+goversion+`.linux-`+runtime.GOARCH+`.tar.gz | tar -C /var/lib/arvados -xzf -
369 ln -sfv /var/lib/arvados/go/bin/* /usr/local/bin/
378 if havegradleversion, err := exec.Command("/usr/local/bin/gradle", "--version").CombinedOutput(); err == nil && strings.Contains(string(havegradleversion), "Gradle "+gradleversion+"\n") {
379 logger.Print("gradle " + gradleversion + " already installed")
383 zip=/var/lib/arvados/tmp/gradle-${G}-bin.zip
385 wget --progress=dot:giga -O${zip} https://services.gradle.org/distributions/gradle-${G}-bin.zip
386 unzip -o -d /var/lib/arvados ${zip}
387 ln -sfv /var/lib/arvados/gradle-${G}/bin/gradle /usr/local/bin/
395 if havesingularityversion, err := exec.Command("/var/lib/arvados/bin/singularity", "--version").CombinedOutput(); err == nil && strings.Contains(string(havesingularityversion), inst.SingularityVersion) {
396 logger.Print("singularity " + inst.SingularityVersion + " already installed")
397 } else if dev || test {
399 S=`+inst.SingularityVersion+`
400 tmp=/var/lib/arvados/tmp/singularity
401 trap "rm -r ${tmp}" ERR EXIT
402 cd /var/lib/arvados/tmp
403 git clone --recurse-submodules https://github.com/sylabs/singularity
406 ./mconfig --prefix=/var/lib/arvados
408 make -C ./builddir install
416 install /usr/bin/nsenter /var/lib/arvados/bin/nsenter
417 setcap "cap_sys_admin+pei cap_sys_chroot+pei" /var/lib/arvados/bin/nsenter
423 // The entry in /etc/locale.gen is "en_US.UTF-8"; once
424 // it's installed, locale -a reports it as
426 wantlocale := "en_US.UTF-8"
427 if havelocales, err := exec.Command("locale", "-a").CombinedOutput(); err == nil && bytes.Contains(havelocales, []byte(strings.Replace(wantlocale+"\n", "UTF-", "utf", 1))) {
428 logger.Print("locale " + wantlocale + " already installed")
430 err = inst.runBash(`sed -i 's/^# *\(`+wantlocale+`\)/\1/' /etc/locale.gen && locale-gen`, stdout, stderr)
445 if pgLsclusters, err2 := exec.Command("pg_lsclusters", "--no-header").CombinedOutput(); err2 != nil {
446 err = fmt.Errorf("pg_lsclusters: %s", err2)
448 } else if pgclusters := strings.Split(strings.TrimSpace(string(pgLsclusters)), "\n"); len(pgclusters) != 1 {
449 logger.Warnf("pg_lsclusters returned %d postgresql clusters -- skipping postgresql initdb/startup, hope that's ok", len(pgclusters))
450 } else if _, err = fmt.Sscanf(pgclusters[0], "%s %s %d %s %s %s %s", &pgc.Version, &pgc.Cluster, &pgc.Port, &pgc.Status, &pgc.Owner, &pgc.DataDirectory, &pgc.LogFile); err != nil {
451 err = fmt.Errorf("error parsing pg_lsclusters output: %s", err)
453 } else if pgc.Status == "online" {
454 logger.Infof("postgresql cluster %s-%s is online", pgc.Version, pgc.Cluster)
456 logger.Infof("postgresql cluster %s-%s is %s; trying to start", pgc.Version, pgc.Cluster, pgc.Status)
457 cmd := exec.Command("pg_ctlcluster", "--foreground", pgc.Version, pgc.Cluster, "start")
465 cmd.Process.Signal(syscall.SIGTERM)
466 logger.Info("sent SIGTERM; waiting for postgres to shut down")
469 err = waitPostgreSQLReady()
475 if os.Getpid() == 1 {
476 // We are the init process (presumably in a
477 // docker container) so although postgresql is
478 // installed, it's not running, and initdb
479 // might never have been run.
482 var needcoll []string
483 // If the en_US.UTF-8 locale wasn't installed when
484 // postgresql initdb ran, it needs to be added
485 // explicitly before we can use it in our test suite.
486 for _, collname := range []string{"en_US", "en_US.UTF-8"} {
487 cmd := exec.Command("sudo", "-u", "postgres", "psql", "-t", "-c", "SELECT 1 FROM pg_catalog.pg_collation WHERE collname='"+collname+"' AND collcollate IN ('en_US.UTF-8', 'en_US.utf8')")
489 out, err2 := cmd.CombinedOutput()
491 err = fmt.Errorf("error while checking postgresql collations: %s", err2)
494 if strings.Contains(string(out), "1") {
495 logger.Infof("postgresql supports collation %s", collname)
497 needcoll = append(needcoll, collname)
500 if len(needcoll) > 0 && os.Getpid() != 1 {
501 // In order for the CREATE COLLATION statement
502 // below to work, the locale must have existed
503 // when PostgreSQL started up. If we're
504 // running as init, we must have started
505 // PostgreSQL ourselves after installing the
506 // locales. Otherwise, it might need a
507 // restart, so we attempt to restart it with
509 if err = inst.runBash(`sudo systemctl restart postgresql`, stdout, stderr); err != nil {
510 logger.Warn("`systemctl restart postgresql` failed; hoping postgresql does not need to be restarted")
511 } else if err = waitPostgreSQLReady(); err != nil {
515 for _, collname := range needcoll {
516 cmd := exec.Command("sudo", "-u", "postgres", "psql", "-c", "CREATE COLLATION \""+collname+"\" (LOCALE = \"en_US.UTF-8\")")
522 err = fmt.Errorf("error adding postgresql collation %s: %s", collname, err)
527 withstuff := "WITH LOGIN SUPERUSER ENCRYPTED PASSWORD " + pq.QuoteLiteral(devtestDatabasePassword)
528 cmd := exec.Command("sudo", "-u", "postgres", "psql", "-c", "ALTER ROLE arvados "+withstuff)
530 if err := cmd.Run(); err == nil {
531 logger.Print("arvados role exists; superuser privileges added, password updated")
533 cmd := exec.Command("sudo", "-u", "postgres", "psql", "-c", "CREATE ROLE arvados "+withstuff)
545 switch runtime.GOARCH {
549 njsArch = runtime.GOARCH
553 if havenodejsversion, err := exec.Command("/usr/local/bin/node", "--version").CombinedOutput(); err == nil && string(havenodejsversion) == "v"+inst.NodejsVersion+"\n" {
554 logger.Print("nodejs " + inst.NodejsVersion + " already installed")
557 NJS=v`+inst.NodejsVersion+`
558 rm -rf /var/lib/arvados/node-*-linux-`+njsArch+`
559 wget --progress=dot:giga -O- https://nodejs.org/dist/${NJS}/node-${NJS}-linux-`+njsArch+`.tar.xz | sudo tar -C /var/lib/arvados -xJf -
560 ln -sfv /var/lib/arvados/node-${NJS}-linux-`+njsArch+`/bin/{node,npm} /usr/local/bin/
567 if haveyarnversion, err := exec.Command("/usr/local/bin/yarn", "--version").CombinedOutput(); err == nil && len(haveyarnversion) > 0 {
568 logger.Print("yarn " + strings.TrimSpace(string(haveyarnversion)) + " already installed")
572 ln -sfv /var/lib/arvados/node-v`+inst.NodejsVersion+`-linux-`+njsArch+`/bin/{yarn,yarnpkg} /usr/local/bin/
581 // Install Go programs to /var/lib/arvados/bin/
582 for _, srcdir := range []string{
583 "cmd/arvados-client",
584 "cmd/arvados-server",
586 fmt.Fprintf(stderr, "building %s...\n", srcdir)
587 // -buildvcs=false here avoids a fatal "error
588 // obtaining VCS status" when git refuses to
589 // run (for example) as root in a docker
590 // container using a non-root-owned git tree
591 // mounted from the host -- as in
592 // "arvados-package build".
593 cmd := exec.Command("go", "install", "-buildvcs=false",
595 " -X git.arvados.org/arvados.git/lib/cmd.version="+inst.PackageVersion+
596 " -X git.arvados.org/arvados.git/lib/cmd.commit="+inst.Commit)
597 cmd.Env = append(cmd.Env, os.Environ()...)
598 cmd.Env = append(cmd.Env, "GOBIN=/var/lib/arvados/bin")
599 cmd.Dir = filepath.Join(inst.SourcePath, srcdir)
608 // Copy assets from source tree to /var/lib/arvados/share
609 cmd := exec.Command("install", "-v", "-t", "/var/lib/arvados/share", filepath.Join(inst.SourcePath, "sdk/python/tests/nginx.conf"))
617 // Install python SDK and arv-mount in
618 // /var/lib/arvados/lib/python.
620 // setup.py writes a file in the source directory in
621 // order to include the version number in the package
622 // itself. We don't want to write to the source tree
623 // (in "arvados-package" context it's mounted
624 // readonly) so we run setup.py in a temporary copy of
626 if err = inst.runBash(`
627 v=/var/lib/arvados/lib/python
628 tmp=/var/lib/arvados/tmp/python
631 pip3 install --no-cache-dir 'setuptools>=68' 'pip>=20'
632 export ARVADOS_BUILDING_VERSION="`+inst.PackageVersion+`"
633 for src in "`+inst.SourcePath+`/sdk/python" "`+inst.SourcePath+`/services/fuse"; do
634 rsync -a --delete-after "$src/" "$tmp/"
635 env -C "$tmp" python3 setup.py build
639 `, stdout, stderr); err != nil {
643 // Install RailsAPI to /var/lib/arvados/railsapi/
644 fmt.Fprintln(stderr, "building railsapi...")
645 cmd = exec.Command("rsync",
646 "-a", "--no-owner", "--no-group", "--delete-after", "--delete-excluded",
647 "--exclude", "/coverage",
649 "--exclude", "/node_modules",
651 "--exclude", "/public/assets",
652 "--exclude", "/vendor",
653 "--exclude", "/config/environments",
654 "./", "/var/lib/arvados/railsapi/")
655 cmd.Dir = filepath.Join(inst.SourcePath, "services", "api")
662 for _, cmdline := range [][]string{
663 {"mkdir", "-p", "log", "public/assets", "tmp", "vendor", ".bundle", "/var/www/.bundle", "/var/www/.gem", "/var/www/.npm", "/var/www/.passenger"},
664 {"touch", "log/production.log"},
665 {"chown", "-R", "--from=root", "www-data:www-data", "/var/www/.bundle", "/var/www/.gem", "/var/www/.npm", "/var/www/.passenger", "log", "tmp", "vendor", ".bundle", "Gemfile.lock", "config.ru", "config/environment.rb"},
666 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/gem", "install", "--user", "--conservative", "--no-document", "bundler:" + inst.BundlerVersion},
667 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "deployment", "true"},
668 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "path", "/var/www/.gem"},
669 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "without", "development test diagnostics performance"},
670 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "install", "--jobs", fmt.Sprintf("%d", runtime.NumCPU())},
672 {"chown", "www-data:www-data", ".", "public/assets"},
673 // {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "system", "true"},
674 {"sudo", "-u", "www-data", "ARVADOS_CONFIG=none", "RAILS_GROUPS=assets", "RAILS_ENV=production", "PATH=/var/lib/arvados/bin:" + os.Getenv("PATH"), "/var/lib/arvados/bin/bundle", "exec", "rake", "npm:install"},
675 {"sudo", "-u", "www-data", "ARVADOS_CONFIG=none", "RAILS_GROUPS=assets", "RAILS_ENV=production", "PATH=/var/lib/arvados/bin:" + os.Getenv("PATH"), "/var/lib/arvados/bin/bundle", "exec", "rake", "assets:precompile"},
676 {"chown", "root:root", "."},
677 {"chown", "-R", "root:root", "public/assets", "vendor"},
679 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "build-native-support"},
680 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "install-standalone-runtime"},
682 if cmdline[len(cmdline)-2] == "rake" {
685 cmd = exec.Command(cmdline[0], cmdline[1:]...)
686 cmd.Dir = "/var/lib/arvados/railsapi"
689 fmt.Fprintf(stderr, "... %s\n", cmd.Args)
695 cmd = exec.Command("sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "validate-install")
696 cmd.Dir = "/var/lib/arvados/railsapi"
700 if err != nil && !strings.Contains(err.Error(), "exit status 2") {
701 // Exit code 2 indicates there were warnings (like
702 // "other passenger installations have been detected",
703 // which we can't expect to avoid) but no errors.
704 // Other non-zero exit codes (1, 9) indicate errors.
708 // Install workbench2 app to
709 // /var/lib/arvados/workbench2/.
711 // We copy the source tree from the (possibly
712 // readonly) source tree into a temp dir because `yarn
713 // build` writes to {source-tree}/build/. When we
714 // upgrade to react-scripts >= 4.0.2 we may be able to
715 // build from the source dir and write directly to the
716 // final destination (using
717 // YARN_INSTALL_STATE_PATH=/dev/null
718 // BUILD_PATH=/var/lib/arvados/workbench2) instead of
719 // using two rsync steps here.
720 if err = inst.runBash(`
721 src="`+inst.SourcePath+`/services/workbench2"
722 tmp=/var/lib/arvados/tmp/workbench2
723 trap "rm -r ${tmp}" ERR EXIT
724 dst=/var/lib/arvados/workbench2
725 rsync -a --delete-after "$src/" "$tmp/"
726 env -C "$tmp" VERSION="`+inst.PackageVersion+`" BUILD_NUMBER=1 GIT_COMMIT="`+inst.Commit[:9]+`" yarn build
727 rsync -a --delete-after "$tmp/build/" "$dst/"
728 `, stdout, stderr); err != nil {
732 // Install arvados-cli gem (binaries go in
733 // /var/lib/arvados/bin)
734 if err = inst.runBash(`
735 /var/lib/arvados/bin/gem install --conservative --no-document arvados-cli
736 `, stdout, stderr); err != nil {
740 err = os.WriteFile("/lib/systemd/system/arvados.service", arvadosServiceFile, 0777)
745 // (fpm will do this for us in the pkg case)
746 // This is equivalent to "systemd enable", but
747 // does not depend on the systemctl program
749 symlink := "/etc/systemd/system/multi-user.target.wants/arvados.service"
750 err = os.Remove(symlink)
751 if err != nil && !errors.Is(err, os.ErrNotExist) {
754 err = os.Symlink("/lib/systemd/system/arvados.service", symlink)
760 // Add symlinks in /usr/bin for user-facing programs
761 for _, srcdst := range [][]string{
763 {"bin/arvados-client"},
764 {"bin/arvados-client", "arv"},
765 {"bin/arvados-server"},
767 {"bin/arv", "arv-ruby"},
770 {"lib/python/bin/arv-copy"},
771 {"lib/python/bin/arv-federation-migrate"},
772 {"lib/python/bin/arv-get"},
773 {"lib/python/bin/arv-keepdocker"},
774 {"lib/python/bin/arv-ls"},
775 {"lib/python/bin/arv-migrate-docker19"},
776 {"lib/python/bin/arv-normalize"},
777 {"lib/python/bin/arv-put"},
778 {"lib/python/bin/arv-ws"},
780 {"lib/python/bin/arv-mount"},
782 src := "/var/lib/arvados/" + srcdst[0]
783 if _, err = os.Stat(src); err != nil {
786 dst := srcdst[len(srcdst)-1]
787 _, dst = filepath.Split(dst)
788 dst = "/usr/bin/" + dst
790 if err != nil && !errors.Is(err, os.ErrNotExist) {
793 err = os.Symlink(src, dst)
803 type osversion struct {
810 func identifyOS() (osversion, error) {
812 f, err := os.Open("/etc/os-release")
818 kv := map[string]string{}
819 scanner := bufio.NewScanner(f)
821 line := strings.TrimSpace(scanner.Text())
822 if strings.HasPrefix(line, "#") {
825 toks := strings.SplitN(line, "=", 2)
827 return osv, fmt.Errorf("invalid line in /etc/os-release: %q", line)
830 v := strings.Trim(toks[1], `"`)
832 v = strings.Trim(v, `'`)
836 if err = scanner.Err(); err != nil {
845 idLikeMatched := false
846 for _, idLike := range strings.Split(kv["ID_LIKE"], " ") {
860 return osv, fmt.Errorf("no supported ID found in /etc/os-release")
863 vstr := kv["VERSION_ID"]
864 if i := strings.Index(vstr, "."); i > 0 {
867 osv.Major, err = strconv.Atoi(vstr)
869 return osv, fmt.Errorf("incomprehensible VERSION_ID in /etc/os-release: %q", kv["VERSION_ID"])
874 func waitPostgreSQLReady() error {
875 for deadline := time.Now().Add(10 * time.Second); ; {
876 output, err := exec.Command("pg_isready").CombinedOutput()
879 } else if time.Now().After(deadline) {
880 return fmt.Errorf("timed out waiting for pg_isready (%q)", output)
882 time.Sleep(time.Second)
887 func (inst *installCommand) runBash(script string, stdout, stderr io.Writer) error {
888 cmd := exec.Command("bash", "-")
890 cmd = exec.Command("eatmydata", "bash", "-")
892 cmd.Stdin = bytes.NewBufferString("set -ex -o pipefail\n" + script)
898 func prodpkgs(osv osversion) []string {
912 if osv.Debian || osv.Ubuntu {
913 if osv.Debian && osv.Major == 8 {
914 pkgs = append(pkgs, "libgnutls-deb0-28") // sdk/cwl
915 } else if osv.Debian && osv.Major >= 10 || osv.Ubuntu && osv.Major >= 16 {
916 pkgs = append(pkgs, "python3-distutils") // sdk/cwl
919 "mime-support", // keep-web
921 } else if osv.RedHat {
923 "fuse-libs", // services/fuse
924 "mailcap", // keep-web
927 panic("os version not supported")
931 func ProductionDependencies() ([]string, error) {
932 osv, err := identifyOS()
936 return prodpkgs(osv), nil