18700: Add systemd unit file to arvados-server-easy package.
authorTom Clegg <tom@curii.com>
Thu, 24 Mar 2022 17:39:31 +0000 (13:39 -0400)
committerTom Clegg <tom@curii.com>
Thu, 24 Mar 2022 17:39:31 +0000 (13:39 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

cmd/arvados-package/fpm.go
lib/install/arvados.service [new file with mode: 0644]
lib/install/deps.go

index aec645a684ad2f4adf94ec0b8107fbc213e98727..d81abab583cc78a3ddb5b0421ee38963d8187f83 100644 (file)
@@ -97,6 +97,10 @@ func fpm(ctx context.Context, opts opts, stdin io.Reader, stdout, stderr io.Writ
                "--verbose",
                "--deb-use-file-permissions",
                "--rpm-use-file-permissions",
+               "/etc/systemd/system/multi-user.target.wants/arvados.service",
+               "/lib/systemd/system/arvados.service",
+               "/usr/bin/arvados-client",
+               "/usr/bin/arvados-server",
                "/var/lib/arvados",
                "/var/www/.gem",
                "/var/www/.passenger",
diff --git a/lib/install/arvados.service b/lib/install/arvados.service
new file mode 100644 (file)
index 0000000..cb411c6
--- /dev/null
@@ -0,0 +1,27 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+[Unit]
+Description=Arvados server
+Documentation=https://doc.arvados.org/
+After=network.target
+AssertPathExists=/etc/arvados/config.yml
+
+# systemd>=230 (debian:9) obeys StartLimitIntervalSec in the [Unit] section
+StartLimitIntervalSec=0
+
+[Service]
+Type=notify
+EnvironmentFile=-/etc/arvados/environment
+ExecStart=/usr/bin/arvados-server boot
+# Set a reasonable default for the open file limit
+LimitNOFILE=65536
+Restart=always
+RestartSec=1
+
+# systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
+StartLimitInterval=0
+
+[Install]
+WantedBy=multi-user.target
index 44e46eec4c7cd963cd4a3b28eb6e611feb2f5fa7..2aa77f0a284345026ccedcae6a7c154e879b7aaa 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bufio"
        "bytes"
        "context"
+       _ "embed"
        "errors"
        "flag"
        "fmt"
@@ -42,6 +43,9 @@ const (
        workbench2version       = "5e020488f67b5bc919796e0dc8b0b9f3b3ff23b0"
 )
 
+//go:embed arvados.service
+var arvadosServiceFile []byte
+
 type installCommand struct {
        ClusterType    string
        SourcePath     string
@@ -540,6 +544,19 @@ yarn install
                        }
                }
 
+               // Symlink user-facing Go programs /usr/bin/x ->
+               // /var/lib/arvados/bin/x
+               for _, prog := range []string{"arvados-client", "arvados-server"} {
+                       err = os.Remove("/usr/bin/" + prog)
+                       if err != nil && !errors.Is(err, os.ErrNotExist) {
+                               return 1
+                       }
+                       err = os.Symlink("/var/lib/arvados/bin/"+prog, "/usr/bin/"+prog)
+                       if err != nil {
+                               return 1
+                       }
+               }
+
                // Copy assets from source tree to /var/lib/arvados/share
                cmd := exec.Command("install", "-v", "-t", "/var/lib/arvados/share", filepath.Join(inst.SourcePath, "sdk/python/tests/nginx.conf"))
                cmd.Stdout = stdout
@@ -611,6 +628,23 @@ rsync -a --delete-after build/ /var/lib/arvados/workbench2/
 `, stdout, stderr); err != nil {
                        return 1
                }
+
+               err = os.WriteFile("/lib/systemd/system/arvados.service", arvadosServiceFile, 0777)
+               if err != nil {
+                       return 1
+               }
+               // This is equivalent to "systemd enable", but does
+               // not depend on the systemctl program being
+               // available.
+               symlink := "/etc/systemd/system/multi-user.target.wants/arvados.service"
+               err = os.Remove(symlink)
+               if err != nil && !errors.Is(err, os.ErrNotExist) {
+                       return 1
+               }
+               err = os.Symlink("/lib/systemd/system/arvados.service", symlink)
+               if err != nil {
+                       return 1
+               }
        }
 
        return 0