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
213 "postgresql-contrib",
216 "python3-virtualenv",
230 "zlib1g-dev", // services/api
233 if osv.Debian && osv.Major <= 10 {
234 pkgs = append(pkgs, "iceweasel")
235 } else if osv.Debian && osv.Major >= 11 {
236 pkgs = append(pkgs, "firefox-esr")
238 pkgs = append(pkgs, "firefox")
240 if osv.Debian && osv.Major >= 11 {
241 // not available in Debian <11
242 pkgs = append(pkgs, "s3cmd")
247 "libglib2.0-dev", // singularity (conmon)
248 "libseccomp-dev", // singularity (seccomp)
249 "squashfs-tools", // singularity
250 "gnupg") // docker install recipe
253 case osv.Debian && osv.Major < 13,
254 osv.Ubuntu && osv.Major < 24:
255 pkgs = append(pkgs, "g++", "libcurl4", "libcurl4-openssl-dev")
256 case osv.Debian || osv.Ubuntu:
257 pkgs = append(pkgs, "g++", "libcurl4t64", "libcurl4-openssl-dev")
259 pkgs = append(pkgs, "gcc", "gcc-c++", "libcurl-devel", "postgresql-devel")
261 cmd := exec.CommandContext(ctx, "apt-get")
263 cmd = exec.CommandContext(ctx, "eatmydata", "apt-get")
265 cmd.Args = append(cmd.Args, "install", "--yes", "--no-install-recommends")
266 cmd.Args = append(cmd.Args, pkgs...)
267 cmd.Env = append(os.Environ(), "DEBIAN_FRONTEND=noninteractive")
277 if havedockerversion, err2 := exec.Command("docker", "--version").CombinedOutput(); err2 == nil {
278 logger.Printf("%s installed, assuming that version is ok", bytes.TrimSuffix(havedockerversion, []byte("\n")))
279 } else if osv.Debian {
283 codename = "bullseye"
285 codename = "bookworm"
287 err = fmt.Errorf("don't know how to install docker-ce for debian %d", osv.Major)
291 rm -f /usr/share/keyrings/docker-archive-keyring.gpg
292 curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
293 echo 'deb [arch=`+runtime.GOARCH+` signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian/ `+codename+` stable' | \
294 tee /etc/apt/sources.list.d/docker.list
296 DEBIAN_FRONTEND=noninteractive apt-get --yes --no-install-recommends install docker-ce
302 err = fmt.Errorf("don't know how to install docker for osversion %v", osv)
307 key=fs.inotify.max_user_watches
309 if [[ "$(sysctl --values "${key}")" -lt "${min}" ]]; then
310 sysctl "${key}=${min}"
311 # writing sysctl worked, so we should make it permanent
312 echo "${key}=${min}" | tee -a /etc/sysctl.conf
317 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`)")
322 os.Mkdir("/var/lib/arvados", 0755)
323 os.Mkdir("/var/lib/arvados/tmp", 0700)
325 u, er := user.Lookup("www-data")
327 err = fmt.Errorf("user.Lookup(%q): %w", "www-data", er)
330 uid, _ := strconv.Atoi(u.Uid)
331 gid, _ := strconv.Atoi(u.Gid)
332 os.Mkdir("/var/lib/arvados/wwwtmp", 0700)
333 err = os.Chown("/var/lib/arvados/wwwtmp", uid, gid)
338 rubyminorversion := inst.RubyVersion[:strings.LastIndex(inst.RubyVersion, ".")]
339 if haverubyversion, err := exec.Command("/var/lib/arvados/bin/ruby", "-v").CombinedOutput(); err == nil && bytes.HasPrefix(haverubyversion, []byte("ruby "+inst.RubyVersion)) {
340 logger.Print("ruby " + inst.RubyVersion + " already installed")
343 rubyversion="`+inst.RubyVersion+`"
344 rubyminorversion="`+rubyminorversion+`"
346 trap 'rm -r "${tmp}"' ERR EXIT
347 wget --progress=dot:giga -O- "https://cache.ruby-lang.org/pub/ruby/$rubyminorversion/ruby-$rubyversion.tar.gz" | tar -C "${tmp}" -xzf -
348 cd "${tmp}/ruby-$rubyversion"
349 ./configure --disable-install-static-library --enable-shared --disable-install-doc --prefix /var/lib/arvados
351 rm -f /var/lib/arvados/bin/erb
353 if [[ "$rubyversion" > "3" ]]; then
354 /var/lib/arvados/bin/gem update --no-document --system 3.4.21
356 /var/lib/arvados/bin/gem install --conservative --no-document --version '`+inst.BundlerVersion+`' bundler
364 if havegoversion, err := exec.Command("/usr/local/bin/go", "version").CombinedOutput(); err == nil && bytes.HasPrefix(havegoversion, []byte("go version go"+goversion+" ")) {
365 logger.Print("go " + goversion + " already installed")
369 rm -rf /var/lib/arvados/go/
370 wget --progress=dot:giga -O- https://storage.googleapis.com/golang/go`+goversion+`.linux-`+runtime.GOARCH+`.tar.gz | tar -C /var/lib/arvados -xzf -
371 ln -sfv /var/lib/arvados/go/bin/* /usr/local/bin/
380 if havegradleversion, err := exec.Command("/usr/local/bin/gradle", "--version").CombinedOutput(); err == nil && strings.Contains(string(havegradleversion), "Gradle "+gradleversion+"\n") {
381 logger.Print("gradle " + gradleversion + " already installed")
385 zip=/var/lib/arvados/tmp/gradle-${G}-bin.zip
387 wget --progress=dot:giga -O${zip} https://services.gradle.org/distributions/gradle-${G}-bin.zip
388 unzip -o -d /var/lib/arvados ${zip}
389 ln -sfv /var/lib/arvados/gradle-${G}/bin/gradle /usr/local/bin/
397 if havesingularityversion, err := exec.Command("/var/lib/arvados/bin/singularity", "--version").CombinedOutput(); err == nil && strings.Contains(string(havesingularityversion), inst.SingularityVersion) {
398 logger.Print("singularity " + inst.SingularityVersion + " already installed")
399 } else if dev || test {
401 S=`+inst.SingularityVersion+`
402 tmp=/var/lib/arvados/tmp/singularity
403 trap "rm -r ${tmp}" ERR EXIT
404 cd /var/lib/arvados/tmp
405 git clone --recurse-submodules https://github.com/sylabs/singularity
408 ./mconfig --prefix=/var/lib/arvados
410 make -C ./builddir install
418 install /usr/bin/nsenter /var/lib/arvados/bin/nsenter
419 setcap "cap_sys_admin+pei cap_sys_chroot+pei" /var/lib/arvados/bin/nsenter
425 // The entry in /etc/locale.gen is "en_US.UTF-8"; once
426 // it's installed, locale -a reports it as
428 wantlocale := "en_US.UTF-8"
429 if havelocales, err := exec.Command("locale", "-a").CombinedOutput(); err == nil && bytes.Contains(havelocales, []byte(strings.Replace(wantlocale+"\n", "UTF-", "utf", 1))) {
430 logger.Print("locale " + wantlocale + " already installed")
432 err = inst.runBash(`sed -i 's/^# *\(`+wantlocale+`\)/\1/' /etc/locale.gen && locale-gen`, stdout, stderr)
447 if pgLsclusters, err2 := exec.Command("pg_lsclusters", "--no-header").CombinedOutput(); err2 != nil {
448 err = fmt.Errorf("pg_lsclusters: %s", err2)
450 } else if pgclusters := strings.Split(strings.TrimSpace(string(pgLsclusters)), "\n"); len(pgclusters) != 1 {
451 logger.Warnf("pg_lsclusters returned %d postgresql clusters -- skipping postgresql initdb/startup, hope that's ok", len(pgclusters))
452 } 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 {
453 err = fmt.Errorf("error parsing pg_lsclusters output: %s", err)
455 } else if pgc.Status == "online" {
456 logger.Infof("postgresql cluster %s-%s is online", pgc.Version, pgc.Cluster)
458 logger.Infof("postgresql cluster %s-%s is %s; trying to start", pgc.Version, pgc.Cluster, pgc.Status)
459 cmd := exec.Command("pg_ctlcluster", "--foreground", pgc.Version, pgc.Cluster, "start")
467 cmd.Process.Signal(syscall.SIGTERM)
468 logger.Info("sent SIGTERM; waiting for postgres to shut down")
471 err = waitPostgreSQLReady()
477 if os.Getpid() == 1 {
478 // We are the init process (presumably in a
479 // docker container) so although postgresql is
480 // installed, it's not running, and initdb
481 // might never have been run.
484 var needcoll []string
485 // If the en_US.UTF-8 locale wasn't installed when
486 // postgresql initdb ran, it needs to be added
487 // explicitly before we can use it in our test suite.
488 for _, collname := range []string{"en_US", "en_US.UTF-8"} {
489 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')")
491 out, err2 := cmd.CombinedOutput()
493 err = fmt.Errorf("error while checking postgresql collations: %s", err2)
496 if strings.Contains(string(out), "1") {
497 logger.Infof("postgresql supports collation %s", collname)
499 needcoll = append(needcoll, collname)
502 if len(needcoll) > 0 && os.Getpid() != 1 {
503 // In order for the CREATE COLLATION statement
504 // below to work, the locale must have existed
505 // when PostgreSQL started up. If we're
506 // running as init, we must have started
507 // PostgreSQL ourselves after installing the
508 // locales. Otherwise, it might need a
509 // restart, so we attempt to restart it with
511 if err = inst.runBash(`sudo systemctl restart postgresql`, stdout, stderr); err != nil {
512 logger.Warn("`systemctl restart postgresql` failed; hoping postgresql does not need to be restarted")
513 } else if err = waitPostgreSQLReady(); err != nil {
517 for _, collname := range needcoll {
518 cmd := exec.Command("sudo", "-u", "postgres", "psql", "-c", "CREATE COLLATION \""+collname+"\" (LOCALE = \"en_US.UTF-8\")")
524 err = fmt.Errorf("error adding postgresql collation %s: %s", collname, err)
529 withstuff := "WITH LOGIN SUPERUSER ENCRYPTED PASSWORD " + pq.QuoteLiteral(devtestDatabasePassword)
530 cmd := exec.Command("sudo", "-u", "postgres", "psql", "-c", "ALTER ROLE arvados "+withstuff)
532 if err := cmd.Run(); err == nil {
533 logger.Print("arvados role exists; superuser privileges added, password updated")
535 cmd := exec.Command("sudo", "-u", "postgres", "psql", "-c", "CREATE ROLE arvados "+withstuff)
547 switch runtime.GOARCH {
551 njsArch = runtime.GOARCH
555 if havenodejsversion, err := exec.Command("/usr/local/bin/node", "--version").CombinedOutput(); err == nil && string(havenodejsversion) == "v"+inst.NodejsVersion+"\n" {
556 logger.Print("nodejs " + inst.NodejsVersion + " already installed")
559 NJS=v`+inst.NodejsVersion+`
560 rm -rf /var/lib/arvados/node-*-linux-`+njsArch+`
561 wget --progress=dot:giga -O- https://nodejs.org/dist/${NJS}/node-${NJS}-linux-`+njsArch+`.tar.xz | sudo tar -C /var/lib/arvados -xJf -
562 ln -sfv /var/lib/arvados/node-${NJS}-linux-`+njsArch+`/bin/{node,npm} /usr/local/bin/
569 if haveyarnversion, err := exec.Command("/usr/local/bin/yarn", "--version").CombinedOutput(); err == nil && len(haveyarnversion) > 0 {
570 logger.Print("yarn " + strings.TrimSpace(string(haveyarnversion)) + " already installed")
574 ln -sfv /var/lib/arvados/node-v`+inst.NodejsVersion+`-linux-`+njsArch+`/bin/{yarn,yarnpkg} /usr/local/bin/
583 // Install Go programs to /var/lib/arvados/bin/
584 for _, srcdir := range []string{
585 "cmd/arvados-client",
586 "cmd/arvados-server",
588 fmt.Fprintf(stderr, "building %s...\n", srcdir)
589 // -buildvcs=false here avoids a fatal "error
590 // obtaining VCS status" when git refuses to
591 // run (for example) as root in a docker
592 // container using a non-root-owned git tree
593 // mounted from the host -- as in
594 // "arvados-package build".
595 cmd := exec.Command("go", "install", "-buildvcs=false",
597 " -X git.arvados.org/arvados.git/lib/cmd.version="+inst.PackageVersion+
598 " -X git.arvados.org/arvados.git/lib/cmd.commit="+inst.Commit)
599 cmd.Env = append(cmd.Env, os.Environ()...)
600 cmd.Env = append(cmd.Env, "GOBIN=/var/lib/arvados/bin")
601 cmd.Dir = filepath.Join(inst.SourcePath, srcdir)
610 // Copy assets from source tree to /var/lib/arvados/share
611 cmd := exec.Command("install", "-v", "-t", "/var/lib/arvados/share", filepath.Join(inst.SourcePath, "sdk/python/tests/nginx.conf"))
619 // Install python SDK and arv-mount in
620 // /var/lib/arvados/lib/python.
622 // setup.py writes a file in the source directory in
623 // order to include the version number in the package
624 // itself. We don't want to write to the source tree
625 // (in "arvados-package" context it's mounted
626 // readonly) so we run setup.py in a temporary copy of
628 if err = inst.runBash(`
629 v=/var/lib/arvados/lib/python
630 tmp=/var/lib/arvados/tmp/python
633 pip3 install --no-cache-dir 'setuptools>=68' 'pip>=20'
634 export ARVADOS_BUILDING_VERSION="`+inst.PackageVersion+`"
635 for src in "`+inst.SourcePath+`/sdk/python" "`+inst.SourcePath+`/services/fuse"; do
636 rsync -a --delete-after "$src/" "$tmp/"
637 env -C "$tmp" python3 setup.py build
641 `, stdout, stderr); err != nil {
645 // Install RailsAPI to /var/lib/arvados/railsapi/
646 fmt.Fprintln(stderr, "building railsapi...")
647 cmd = exec.Command("rsync",
648 "-a", "--no-owner", "--no-group", "--delete-after", "--delete-excluded",
649 "--exclude", "/coverage",
651 "--exclude", "/node_modules",
653 "--exclude", "/public/assets",
654 "--exclude", "/vendor",
655 "--exclude", "/config/environments",
656 "./", "/var/lib/arvados/railsapi/")
657 cmd.Dir = filepath.Join(inst.SourcePath, "services", "api")
664 for _, cmdline := range [][]string{
665 {"mkdir", "-p", "log", "public/assets", "tmp", "vendor", ".bundle", "/var/www/.bundle", "/var/www/.gem", "/var/www/.npm", "/var/www/.passenger"},
666 {"touch", "log/production.log"},
667 {"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"},
668 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/gem", "install", "--user", "--conservative", "--no-document", "bundler:" + inst.BundlerVersion},
669 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "deployment", "true"},
670 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "path", "/var/www/.gem"},
671 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "without", "development test diagnostics performance"},
672 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "install", "--jobs", fmt.Sprintf("%d", runtime.NumCPU())},
674 {"chown", "www-data:www-data", ".", "public/assets"},
675 // {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "config", "set", "--local", "system", "true"},
676 {"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"},
677 {"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"},
678 {"chown", "root:root", "."},
679 {"chown", "-R", "root:root", "public/assets", "vendor"},
681 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "build-native-support"},
682 {"sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "install-standalone-runtime"},
684 if cmdline[len(cmdline)-2] == "rake" {
687 cmd = exec.Command(cmdline[0], cmdline[1:]...)
688 cmd.Dir = "/var/lib/arvados/railsapi"
691 fmt.Fprintf(stderr, "... %s\n", cmd.Args)
697 cmd = exec.Command("sudo", "-u", "www-data", "/var/lib/arvados/bin/bundle", "exec", "passenger-config", "validate-install")
698 cmd.Dir = "/var/lib/arvados/railsapi"
702 if err != nil && !strings.Contains(err.Error(), "exit status 2") {
703 // Exit code 2 indicates there were warnings (like
704 // "other passenger installations have been detected",
705 // which we can't expect to avoid) but no errors.
706 // Other non-zero exit codes (1, 9) indicate errors.
710 // Install workbench2 app to
711 // /var/lib/arvados/workbench2/.
713 // We copy the source tree from the (possibly
714 // readonly) source tree into a temp dir because `yarn
715 // build` writes to {source-tree}/build/. When we
716 // upgrade to react-scripts >= 4.0.2 we may be able to
717 // build from the source dir and write directly to the
718 // final destination (using
719 // YARN_INSTALL_STATE_PATH=/dev/null
720 // BUILD_PATH=/var/lib/arvados/workbench2) instead of
721 // using two rsync steps here.
722 if err = inst.runBash(`
723 src="`+inst.SourcePath+`/services/workbench2"
724 tmp=/var/lib/arvados/tmp/workbench2
725 trap "rm -r ${tmp}" ERR EXIT
726 dst=/var/lib/arvados/workbench2
727 rsync -a --delete-after "$src/" "$tmp/"
728 env -C "$tmp" VERSION="`+inst.PackageVersion+`" BUILD_NUMBER=1 GIT_COMMIT="`+inst.Commit[:9]+`" yarn build
729 rsync -a --delete-after "$tmp/build/" "$dst/"
730 `, stdout, stderr); err != nil {
734 // Install arvados-cli gem (binaries go in
735 // /var/lib/arvados/bin)
736 if err = inst.runBash(`
737 /var/lib/arvados/bin/gem install --conservative --no-document arvados-cli
738 `, stdout, stderr); err != nil {
742 err = os.WriteFile("/lib/systemd/system/arvados.service", arvadosServiceFile, 0777)
747 // (fpm will do this for us in the pkg case)
748 // This is equivalent to "systemd enable", but
749 // does not depend on the systemctl program
751 symlink := "/etc/systemd/system/multi-user.target.wants/arvados.service"
752 err = os.Remove(symlink)
753 if err != nil && !errors.Is(err, os.ErrNotExist) {
756 err = os.Symlink("/lib/systemd/system/arvados.service", symlink)
762 // Add symlinks in /usr/bin for user-facing programs
763 for _, srcdst := range [][]string{
765 {"bin/arvados-client"},
766 {"bin/arvados-client", "arv"},
767 {"bin/arvados-server"},
769 {"bin/arv", "arv-ruby"},
772 {"lib/python/bin/arv-copy"},
773 {"lib/python/bin/arv-federation-migrate"},
774 {"lib/python/bin/arv-get"},
775 {"lib/python/bin/arv-keepdocker"},
776 {"lib/python/bin/arv-ls"},
777 {"lib/python/bin/arv-normalize"},
778 {"lib/python/bin/arv-put"},
779 {"lib/python/bin/arv-ws"},
781 {"lib/python/bin/arv-mount"},
783 src := "/var/lib/arvados/" + srcdst[0]
784 if _, err = os.Stat(src); err != nil {
787 dst := srcdst[len(srcdst)-1]
788 _, dst = filepath.Split(dst)
789 dst = "/usr/bin/" + dst
791 if err != nil && !errors.Is(err, os.ErrNotExist) {
794 err = os.Symlink(src, dst)
804 type osversion struct {
811 func identifyOS() (osversion, error) {
813 f, err := os.Open("/etc/os-release")
819 kv := map[string]string{}
820 scanner := bufio.NewScanner(f)
822 line := strings.TrimSpace(scanner.Text())
823 if strings.HasPrefix(line, "#") {
826 toks := strings.SplitN(line, "=", 2)
828 return osv, fmt.Errorf("invalid line in /etc/os-release: %q", line)
831 v := strings.Trim(toks[1], `"`)
833 v = strings.Trim(v, `'`)
837 if err = scanner.Err(); err != nil {
846 idLikeMatched := false
847 for _, idLike := range strings.Split(kv["ID_LIKE"], " ") {
861 return osv, fmt.Errorf("no supported ID found in /etc/os-release")
864 vstr := kv["VERSION_ID"]
865 if i := strings.Index(vstr, "."); i > 0 {
868 osv.Major, err = strconv.Atoi(vstr)
870 return osv, fmt.Errorf("incomprehensible VERSION_ID in /etc/os-release: %q", kv["VERSION_ID"])
875 func waitPostgreSQLReady() error {
876 for deadline := time.Now().Add(10 * time.Second); ; {
877 output, err := exec.Command("pg_isready").CombinedOutput()
880 } else if time.Now().After(deadline) {
881 return fmt.Errorf("timed out waiting for pg_isready (%q)", output)
883 time.Sleep(time.Second)
888 func (inst *installCommand) runBash(script string, stdout, stderr io.Writer) error {
889 cmd := exec.Command("bash", "-")
891 cmd = exec.Command("eatmydata", "bash", "-")
893 cmd.Stdin = bytes.NewBufferString("set -ex -o pipefail\n" + script)
899 func prodpkgs(osv osversion) []string {
913 if osv.Debian || osv.Ubuntu {
914 if osv.Debian && osv.Major == 8 {
915 pkgs = append(pkgs, "libgnutls-deb0-28") // sdk/cwl
916 } else if osv.Debian && osv.Major >= 10 || osv.Ubuntu && osv.Major >= 16 {
917 pkgs = append(pkgs, "python3-distutils") // sdk/cwl
920 "mime-support", // keep-web
922 } else if osv.RedHat {
924 "fuse-libs", // services/fuse
925 "mailcap", // keep-web
928 panic("os version not supported")
932 func ProductionDependencies() ([]string, error) {
933 osv, err := identifyOS()
937 return prodpkgs(osv), nil