1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.arvados.org/arvados.git/sdk/go/arvados"
19 // Run an Nginx process that proxies the supervisor's configured
20 // ExternalURLs to the appropriate InternalURLs.
21 type runNginx struct{}
23 func (runNginx) String() string {
27 func (runNginx) Run(ctx context.Context, fail func(error), super *Supervisor) error {
28 vars := map[string]string{
29 "LISTENHOST": super.ListenHost,
30 "SSLCERT": filepath.Join(super.SourcePath, "services", "api", "tmp", "self-signed.pem"), // TODO: root ca
31 "SSLKEY": filepath.Join(super.SourcePath, "services", "api", "tmp", "self-signed.key"), // TODO: root ca
32 "ACCESSLOG": filepath.Join(super.tempdir, "nginx_access.log"),
33 "ERRORLOG": filepath.Join(super.tempdir, "nginx_error.log"),
34 "TMPDIR": super.tempdir,
37 for _, cmpt := range []struct {
41 {"CONTROLLER", super.cluster.Services.Controller},
42 {"KEEPWEB", super.cluster.Services.WebDAV},
43 {"KEEPWEBDL", super.cluster.Services.WebDAVDownload},
44 {"KEEPPROXY", super.cluster.Services.Keepproxy},
45 {"GIT", super.cluster.Services.GitHTTP},
46 {"WORKBENCH1", super.cluster.Services.Workbench1},
47 {"WS", super.cluster.Services.Websocket},
49 vars[cmpt.varname+"PORT"], err = internalPort(cmpt.svc)
51 return fmt.Errorf("%s internal port: %s (%v)", cmpt.varname, err, cmpt.svc)
53 vars[cmpt.varname+"SSLPORT"], err = externalPort(cmpt.svc)
55 return fmt.Errorf("%s external port: %s (%v)", cmpt.varname, err, cmpt.svc)
58 tmpl, err := ioutil.ReadFile(filepath.Join(super.SourcePath, "sdk", "python", "tests", "nginx.conf"))
62 conf := regexp.MustCompile(`{{.*?}}`).ReplaceAllStringFunc(string(tmpl), func(src string) string {
66 return vars[src[2:len(src)-2]]
68 conffile := filepath.Join(super.tempdir, "nginx.conf")
69 err = ioutil.WriteFile(conffile, []byte(conf), 0755)
74 if _, err := exec.LookPath(nginx); err != nil {
75 for _, dir := range []string{"/sbin", "/usr/sbin", "/usr/local/sbin"} {
76 if _, err = os.Stat(dir + "/nginx"); err == nil {
77 nginx = dir + "/nginx"
82 super.waitShutdown.Add(1)
84 defer super.waitShutdown.Done()
85 fail(super.RunProgram(ctx, ".", nil, nil, nginx,
86 "-g", "error_log stderr info;",
87 "-g", "pid "+filepath.Join(super.tempdir, "nginx.pid")+";",
90 return waitForConnect(ctx, super.cluster.Services.Controller.ExternalURL.Host)