15954: Avoid doing concurrent bundle/passenger installs.
[arvados.git] / lib / boot / nginx.go
index 11d823fc025f19d61b5ef2b2be24c39c061d10cb..5c1954c838d83b45ae5419fc0fa50d67c4e64161 100644 (file)
@@ -7,7 +7,6 @@ package boot
 import (
        "context"
        "fmt"
-       "io"
        "io/ioutil"
        "os"
        "os/exec"
@@ -17,13 +16,20 @@ import (
        "git.arvados.org/arvados.git/sdk/go/arvados"
 )
 
-func runNginx(ctx context.Context, boot *bootCommand, stdout, stderr io.Writer) error {
+type runNginx struct{}
+
+func (runNginx) String() string {
+       return "nginx"
+}
+
+func (runNginx) Run(ctx context.Context, fail func(error), boot *Booter) error {
        vars := map[string]string{
-               "SSLCERT":   filepath.Join(boot.sourcePath, "services", "api", "tmp", "self-signed.pem"), // TODO: root ca
-               "SSLKEY":    filepath.Join(boot.sourcePath, "services", "api", "tmp", "self-signed.key"), // TODO: root ca
-               "ACCESSLOG": filepath.Join(boot.tempdir, "nginx_access.log"),
-               "ERRORLOG":  filepath.Join(boot.tempdir, "nginx_error.log"),
-               "TMPDIR":    boot.tempdir,
+               "LISTENHOST": boot.ListenHost,
+               "SSLCERT":    filepath.Join(boot.SourcePath, "services", "api", "tmp", "self-signed.pem"), // TODO: root ca
+               "SSLKEY":     filepath.Join(boot.SourcePath, "services", "api", "tmp", "self-signed.key"), // TODO: root ca
+               "ACCESSLOG":  filepath.Join(boot.tempdir, "nginx_access.log"),
+               "ERRORLOG":   filepath.Join(boot.tempdir, "nginx_error.log"),
+               "TMPDIR":     boot.tempdir,
        }
        var err error
        for _, cmpt := range []struct {
@@ -35,6 +41,7 @@ func runNginx(ctx context.Context, boot *bootCommand, stdout, stderr io.Writer)
                {"KEEPWEBDL", boot.cluster.Services.WebDAVDownload},
                {"KEEPPROXY", boot.cluster.Services.Keepproxy},
                {"GIT", boot.cluster.Services.GitHTTP},
+               {"WORKBENCH1", boot.cluster.Services.Workbench1},
                {"WS", boot.cluster.Services.Websocket},
        } {
                vars[cmpt.varname+"PORT"], err = internalPort(cmpt.svc)
@@ -46,7 +53,7 @@ func runNginx(ctx context.Context, boot *bootCommand, stdout, stderr io.Writer)
                        return fmt.Errorf("%s external port: %s (%v)", cmpt.varname, err, cmpt.svc)
                }
        }
-       tmpl, err := ioutil.ReadFile(filepath.Join(boot.sourcePath, "sdk", "python", "tests", "nginx.conf"))
+       tmpl, err := ioutil.ReadFile(filepath.Join(boot.SourcePath, "sdk", "python", "tests", "nginx.conf"))
        if err != nil {
                return err
        }
@@ -70,8 +77,11 @@ func runNginx(ctx context.Context, boot *bootCommand, stdout, stderr io.Writer)
                        }
                }
        }
-       return boot.RunProgram(ctx, ".", nil, nil, nginx,
-               "-g", "error_log stderr info;",
-               "-g", "pid "+filepath.Join(boot.tempdir, "nginx.pid")+";",
-               "-c", conffile)
+       go func() {
+               fail(boot.RunProgram(ctx, ".", nil, nil, nginx,
+                       "-g", "error_log stderr info;",
+                       "-g", "pid "+filepath.Join(boot.tempdir, "nginx.pid")+";",
+                       "-c", conffile))
+       }()
+       return waitForConnect(ctx, boot.cluster.Services.Controller.ExternalURL.Host)
 }