1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
17 "git.arvados.org/arvados.git/sdk/go/arvados"
20 // Run an Nginx process that proxies the supervisor's configured
21 // ExternalURLs to the appropriate InternalURLs.
22 type runNginx struct{}
24 func (runNginx) String() string {
28 func (runNginx) Run(ctx context.Context, fail func(error), super *Supervisor) error {
29 vars := map[string]string{
30 "LISTENHOST": super.ListenHost,
31 "SSLCERT": filepath.Join(super.SourcePath, "services", "api", "tmp", "self-signed.pem"), // TODO: root ca
32 "SSLKEY": filepath.Join(super.SourcePath, "services", "api", "tmp", "self-signed.key"), // TODO: root ca
33 "ACCESSLOG": filepath.Join(super.tempdir, "nginx_access.log"),
34 "ERRORLOG": filepath.Join(super.tempdir, "nginx_error.log"),
35 "TMPDIR": super.tempdir,
38 for _, cmpt := range []struct {
42 {"CONTROLLER", super.cluster.Services.Controller},
43 {"KEEPWEB", super.cluster.Services.WebDAV},
44 {"KEEPWEBDL", super.cluster.Services.WebDAVDownload},
45 {"KEEPPROXY", super.cluster.Services.Keepproxy},
46 {"GIT", super.cluster.Services.GitHTTP},
47 {"WORKBENCH1", super.cluster.Services.Workbench1},
48 {"WS", super.cluster.Services.Websocket},
50 port, err := internalPort(cmpt.svc)
52 return fmt.Errorf("%s internal port: %s (%v)", cmpt.varname, err, cmpt.svc)
54 if ok, err := addrIsLocal(net.JoinHostPort(super.ListenHost, port)); !ok || err != nil {
55 return fmt.Errorf("urlIsLocal() failed for host %q port %q: %v", super.ListenHost, port, err)
57 vars[cmpt.varname+"PORT"] = port
59 port, err = externalPort(cmpt.svc)
61 return fmt.Errorf("%s external port: %s (%v)", cmpt.varname, err, cmpt.svc)
63 if ok, err := addrIsLocal(net.JoinHostPort(super.ListenHost, port)); !ok || err != nil {
64 return fmt.Errorf("urlIsLocal() failed for host %q port %q: %v", super.ListenHost, port, err)
66 vars[cmpt.varname+"SSLPORT"] = port
68 tmpl, err := ioutil.ReadFile(filepath.Join(super.SourcePath, "sdk", "python", "tests", "nginx.conf"))
72 conf := regexp.MustCompile(`{{.*?}}`).ReplaceAllStringFunc(string(tmpl), func(src string) string {
76 return vars[src[2:len(src)-2]]
78 conffile := filepath.Join(super.tempdir, "nginx.conf")
79 err = ioutil.WriteFile(conffile, []byte(conf), 0755)
84 if _, err := exec.LookPath(nginx); err != nil {
85 for _, dir := range []string{"/sbin", "/usr/sbin", "/usr/local/sbin"} {
86 if _, err = os.Stat(dir + "/nginx"); err == nil {
87 nginx = dir + "/nginx"
92 super.waitShutdown.Add(1)
94 defer super.waitShutdown.Done()
95 fail(super.RunProgram(ctx, ".", nil, nil, nginx,
96 "-g", "error_log stderr info;",
97 "-g", "pid "+filepath.Join(super.tempdir, "nginx.pid")+";",
100 return waitForConnect(ctx, super.cluster.Services.Controller.ExternalURL.Host)