18700: Add systemd unit file to arvados-server-easy package.
[arvados.git] / lib / install / deps.go
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