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 err := super.wait(ctx, createCertificates{})
33 vars := map[string]string{
34 "LISTENHOST": super.ListenHost,
35 "SSLCERT": filepath.Join(super.tempdir, "server.crt"),
36 "SSLKEY": filepath.Join(super.tempdir, "server.key"),
37 "ACCESSLOG": filepath.Join(super.tempdir, "nginx_access.log"),
38 "ERRORLOG": filepath.Join(super.tempdir, "nginx_error.log"),
39 "TMPDIR": super.tempdir,
41 for _, cmpt := range []struct {
45 {"CONTROLLER", super.cluster.Services.Controller},
46 {"KEEPWEB", super.cluster.Services.WebDAV},
47 {"KEEPWEBDL", super.cluster.Services.WebDAVDownload},
48 {"KEEPPROXY", super.cluster.Services.Keepproxy},
49 {"GIT", super.cluster.Services.GitHTTP},
50 {"HEALTH", super.cluster.Services.Health},
51 {"WORKBENCH1", super.cluster.Services.Workbench1},
52 {"WS", super.cluster.Services.Websocket},
54 port, err := internalPort(cmpt.svc)
56 return fmt.Errorf("%s internal port: %s (%v)", cmpt.varname, err, cmpt.svc)
58 if ok, err := addrIsLocal(net.JoinHostPort(super.ListenHost, port)); !ok || err != nil {
59 return fmt.Errorf("urlIsLocal() failed for host %q port %q: %v", super.ListenHost, port, err)
61 vars[cmpt.varname+"PORT"] = port
63 port, err = externalPort(cmpt.svc)
65 return fmt.Errorf("%s external port: %s (%v)", cmpt.varname, err, cmpt.svc)
67 if ok, err := addrIsLocal(net.JoinHostPort(super.ListenHost, port)); !ok || err != nil {
68 return fmt.Errorf("urlIsLocal() failed for host %q port %q: %v", super.ListenHost, port, err)
70 vars[cmpt.varname+"SSLPORT"] = port
72 tmpl, err := ioutil.ReadFile(filepath.Join(super.SourcePath, "sdk", "python", "tests", "nginx.conf"))
76 conf := regexp.MustCompile(`{{.*?}}`).ReplaceAllStringFunc(string(tmpl), func(src string) string {
80 return vars[src[2:len(src)-2]]
82 conffile := filepath.Join(super.tempdir, "nginx.conf")
83 err = ioutil.WriteFile(conffile, []byte(conf), 0755)
88 if _, err := exec.LookPath(nginx); err != nil {
89 for _, dir := range []string{"/sbin", "/usr/sbin", "/usr/local/sbin"} {
90 if _, err = os.Stat(dir + "/nginx"); err == nil {
91 nginx = dir + "/nginx"
96 super.waitShutdown.Add(1)
98 defer super.waitShutdown.Done()
99 fail(super.RunProgram(ctx, ".", nil, nil, nginx,
100 "-g", "error_log stderr info;",
101 "-g", "pid "+filepath.Join(super.tempdir, "nginx.pid")+";",
104 return waitForConnect(ctx, super.cluster.Services.Controller.ExternalURL.Host)