func reconfigure(u config.Upstream) error { u.Lock() defer u.Unlock() upstream, err := os.Create(u.File) if err != nil { return err } defer upstream.Close() upstream.WriteString(fmt.Sprintf("upstream %s {\n", u.Name)) upstream_filenames, err := filepath.Glob(filepath.Join(u.ContainerFolder, "*.upstream")) if err != nil { return err } for _, upstream_filename := range upstream_filenames { content, err := ioutil.ReadFile(upstream_filename) if err != nil { return err } upstream.WriteString(fmt.Sprintf(" %s", string(content))) } upstream.WriteString("}\n") return nil }
func addInstance(u config.Upstream, i *ec2.Instance) error { filename := getUpstreamFilenameForInstance(u, i) u.Lock() defer u.Unlock() upstream := fmt.Sprintf("server %s:80 max_fails=3 fail_timeout=60s; # %s\n", i.PrivateDNSName, i.InstanceId) buf := []byte(upstream) if err := ioutil.WriteFile(filename, buf, 0640); err != nil { return err } return nil }