Example #1
0
func start(flagSet *flag.FlagSet, path string, controller confab.Controller, agentClient *confab.AgentClient) {
	timeout := confab.NewTimeout(time.After(time.Duration(controller.Config.Confab.TimeoutInSeconds) * time.Second))

	_, err := os.Stat(controller.Config.Path.ConsulConfigDir)
	if err != nil {
		printUsageAndExit(fmt.Sprintf("\"consul_config_dir\" %q could not be found",
			controller.Config.Path.ConsulConfigDir), flagSet)
	}

	if len(agentClient.ExpectedMembers) == 0 {
		printUsageAndExit("at least one \"expected-member\" must be provided", flagSet)
	}

	err = controller.WriteServiceDefinitions()
	if err != nil {
		stderr.Printf("error writing service definitions: %s", err)
		os.Exit(1)
	}

	err = controller.BootAgent(timeout)
	if err != nil {
		stderr.Printf("error booting consul agent: %s", err)

		// DO NOT call StopAgent:
		//   - the agent may aleady be running
		//   - the pidfile may contain the PID of another running process
		os.Exit(1)
	}

	if controller.Config.Consul.Agent.Server {
		configureServer(controller, agentClient, timeout)
	} else {
		configureClient(controller)
	}
}
Example #2
0
func start(flagSet *flag.FlagSet, path string, controller confab.Controller, agentClient *agent.Client) {
	timeout := confab.NewTimeout(time.After(time.Duration(controller.Config.Confab.TimeoutInSeconds) * time.Second))

	_, err := os.Stat(controller.Config.Path.ConsulConfigDir)
	if err != nil {
		printUsageAndExit(fmt.Sprintf("\"consul_config_dir\" %q could not be found",
			controller.Config.Path.ConsulConfigDir), flagSet)
	}

	if len(agentClient.ExpectedMembers) == 0 {
		printUsageAndExit("at least one \"expected-member\" must be provided", flagSet)
	}

	err = controller.WriteConsulConfig()
	if err != nil {
		stderr.Printf("error writing consul config file: %s", err)
		os.Exit(1)
	}

	err = controller.WriteServiceDefinitions()
	if err != nil {
		stderr.Printf("error writing service definitions: %s", err)
		os.Exit(1)
	}

	err = controller.BootAgent(timeout)
	if err != nil {
		stderr.Printf("error booting consul agent: %s", err)
		exit(controller, 1)
	}

	if controller.Config.Consul.Agent.Mode == "server" {
		configureServer(controller, agentClient, timeout)
	} else {
		configureClient(controller)
	}
}
Example #3
0
package confab_test

import (
	"time"

	"confab"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Timeout", func() {
	Describe("Done", func() {
		It("closes the channel when the timer finishes", func() {
			timer := make(chan time.Time)
			timeout := confab.NewTimeout(timer)

			Expect(timeout.Done()).NotTo(BeClosed())

			timer <- time.Now()

			Eventually(timeout.Done).Should(BeClosed())
		})
	})
})
					},
					{
						Action: "controller.write-service-definitions.write",
					},
					{
						Action: "controller.write-service-definitions.write.failed",
						Error:  errors.New("write definitions error"),
					},
				}))
			})
		})
	})

	Describe("BootAgent", func() {
		It("launches the consul agent and confirms that it joined the cluster", func() {
			Expect(controller.BootAgent(confab.NewTimeout(make(chan time.Time)))).To(Succeed())
			Expect(agentRunner.RunCalls.CallCount).To(Equal(1))
			Expect(agentClient.VerifyJoinedCalls.CallCount).To(Equal(1))
			Expect(logger.Messages).To(ContainSequence([]fakes.LoggerMessage{
				{
					Action: "controller.boot-agent.run",
				},
				{
					Action: "controller.boot-agent.verify-joined",
				},
				{
					Action: "controller.boot-agent.success",
				},
			}))
		})