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 type runNginx struct{}
21 func (runNginx) String() string {
25 func (runNginx) Run(ctx context.Context, fail func(error), boot *Booter) error {
26 vars := map[string]string{
27 "LISTENHOST": boot.ListenHost,
28 "SSLCERT": filepath.Join(boot.SourcePath, "services", "api", "tmp", "self-signed.pem"), // TODO: root ca
29 "SSLKEY": filepath.Join(boot.SourcePath, "services", "api", "tmp", "self-signed.key"), // TODO: root ca
30 "ACCESSLOG": filepath.Join(boot.tempdir, "nginx_access.log"),
31 "ERRORLOG": filepath.Join(boot.tempdir, "nginx_error.log"),
32 "TMPDIR": boot.tempdir,
35 for _, cmpt := range []struct {
39 {"CONTROLLER", boot.cluster.Services.Controller},
40 {"KEEPWEB", boot.cluster.Services.WebDAV},
41 {"KEEPWEBDL", boot.cluster.Services.WebDAVDownload},
42 {"KEEPPROXY", boot.cluster.Services.Keepproxy},
43 {"GIT", boot.cluster.Services.GitHTTP},
44 {"WORKBENCH1", boot.cluster.Services.Workbench1},
45 {"WS", boot.cluster.Services.Websocket},
47 vars[cmpt.varname+"PORT"], err = internalPort(cmpt.svc)
49 return fmt.Errorf("%s internal port: %s (%v)", cmpt.varname, err, cmpt.svc)
51 vars[cmpt.varname+"SSLPORT"], err = externalPort(cmpt.svc)
53 return fmt.Errorf("%s external port: %s (%v)", cmpt.varname, err, cmpt.svc)
56 tmpl, err := ioutil.ReadFile(filepath.Join(boot.SourcePath, "sdk", "python", "tests", "nginx.conf"))
60 conf := regexp.MustCompile(`{{.*?}}`).ReplaceAllStringFunc(string(tmpl), func(src string) string {
64 return vars[src[2:len(src)-2]]
66 conffile := filepath.Join(boot.tempdir, "nginx.conf")
67 err = ioutil.WriteFile(conffile, []byte(conf), 0755)
72 if _, err := exec.LookPath(nginx); err != nil {
73 for _, dir := range []string{"/sbin", "/usr/sbin", "/usr/local/sbin"} {
74 if _, err = os.Stat(dir + "/nginx"); err == nil {
75 nginx = dir + "/nginx"
81 fail(boot.RunProgram(ctx, ".", nil, nil, nginx,
82 "-g", "error_log stderr info;",
83 "-g", "pid "+filepath.Join(boot.tempdir, "nginx.pid")+";",
86 return waitForConnect(ctx, boot.cluster.Services.Controller.ExternalURL.Host)