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 "SSLCERT": filepath.Join(boot.SourcePath, "services", "api", "tmp", "self-signed.pem"), // TODO: root ca
28 "SSLKEY": filepath.Join(boot.SourcePath, "services", "api", "tmp", "self-signed.key"), // TODO: root ca
29 "ACCESSLOG": filepath.Join(boot.tempdir, "nginx_access.log"),
30 "ERRORLOG": filepath.Join(boot.tempdir, "nginx_error.log"),
31 "TMPDIR": boot.tempdir,
34 for _, cmpt := range []struct {
38 {"CONTROLLER", boot.cluster.Services.Controller},
39 {"KEEPWEB", boot.cluster.Services.WebDAV},
40 {"KEEPWEBDL", boot.cluster.Services.WebDAVDownload},
41 {"KEEPPROXY", boot.cluster.Services.Keepproxy},
42 {"GIT", boot.cluster.Services.GitHTTP},
43 {"WORKBENCH1", boot.cluster.Services.Workbench1},
44 {"WS", boot.cluster.Services.Websocket},
46 vars[cmpt.varname+"PORT"], err = internalPort(cmpt.svc)
48 return fmt.Errorf("%s internal port: %s (%v)", cmpt.varname, err, cmpt.svc)
50 vars[cmpt.varname+"SSLPORT"], err = externalPort(cmpt.svc)
52 return fmt.Errorf("%s external port: %s (%v)", cmpt.varname, err, cmpt.svc)
55 tmpl, err := ioutil.ReadFile(filepath.Join(boot.SourcePath, "sdk", "python", "tests", "nginx.conf"))
59 conf := regexp.MustCompile(`{{.*?}}`).ReplaceAllStringFunc(string(tmpl), func(src string) string {
63 return vars[src[2:len(src)-2]]
65 conffile := filepath.Join(boot.tempdir, "nginx.conf")
66 err = ioutil.WriteFile(conffile, []byte(conf), 0755)
71 if _, err := exec.LookPath(nginx); err != nil {
72 for _, dir := range []string{"/sbin", "/usr/sbin", "/usr/local/sbin"} {
73 if _, err = os.Stat(dir + "/nginx"); err == nil {
74 nginx = dir + "/nginx"
80 fail(boot.RunProgram(ctx, ".", nil, nil, nginx,
81 "-g", "error_log stderr info;",
82 "-g", "pid "+filepath.Join(boot.tempdir, "nginx.pid")+";",
85 return waitForConnect(ctx, boot.cluster.Services.Controller.ExternalURL.Host)