Beispiel #1
0
func cmdInfo(c *cli.Context) {
	haproxyOut, hErr := exec.Command("/usr/sbin/haproxy", "-v").Output()
	if hErr != nil {
		log.Fatal(hErr)
	}

	hData := strings.Split(string(haproxyOut), "\n")

	nginxOut, nErr := exec.Command("/usr/sbin/nginx", "-v").CombinedOutput()
	if nErr != nil {
		log.Fatal(nErr)
	}

	nData := strings.Split(string(nginxOut), "\n")

	fmt.Println("interlock " + version.FullVersion())
	fmt.Println(" " + string(hData[0]))
	fmt.Println(" " + string(nData[0]))
}
Beispiel #2
0
func cmdStart(c *cli.Context) {
	username := c.GlobalString("username")
	apiKey := c.GlobalString("api-key")
	clusterName := c.GlobalString("clustername")
	endpoint := c.GlobalString("endpoint")

	if clusterName == "" {
		log.Fatalf("cluster name must not be empty")
	}

	config := &interlock.Config{}

	client, err := libcarina.NewClusterClient(endpoint, username, apiKey)

	if err != nil {
		log.Fatalf("error getting access to the cluster: %s", err)
	}

	swarmURL, tlsConfig, err := client.GetDockerConfig(clusterName)
	if err != nil {
		log.Fatalf("error retrieving tls config and swarm URL: %s", err)
	}

	config.SwarmUrl = swarmURL
	config.EnabledPlugins = c.GlobalStringSlice("plugin")

	m := NewManager(config, tlsConfig)

	log.Infof("interlock running version=%s", version.FullVersion())
	if err := m.Run(); err != nil {
		log.Fatal(err)
	}

	waitForInterrupt()

	log.Infof("shutting down")
	if err := m.Stop(); err != nil {
		log.Fatal(err)
	}
}
Beispiel #3
0
func main() {
	app := cli.NewApp()
	app.Name = "interlock"
	app.Version = version.FullVersion()
	app.Author = "@rgbkrk"
	app.Email = ""
	app.Usage = "event driven docker plugins"
	app.Before = func(c *cli.Context) error {
		if c.GlobalBool("debug") {
			log.SetLevel(log.DebugLevel)
		}
		return nil
	}
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "username",
			Usage: "carina username",
		},
		cli.StringFlag{
			Name:  "api-key, apikey",
			Usage: "carina API key",
		},
		cli.StringFlag{
			Name:  "clustername",
			Usage: "name of the swarm cluster",
		},
		cli.StringFlag{
			Name:  "endpoint",
			Value: libcarina.BetaEndpoint,
			Usage: "endpoint for carina",
		},
		cli.StringSliceFlag{
			Name:  "plugin, p",
			Usage: "enable plugin",
			Value: &cli.StringSlice{},
		},
		cli.BoolFlag{
			Name:  "debug, D",
			Usage: "enable debug",
		},
	}
	// base commands
	baseCommands := []cli.Command{
		{
			Name:   "start",
			Action: cmdStart,
		},
		{
			Name:   "list-plugins",
			Action: cmdListPlugins,
		},
		{
			Name:   "info",
			Action: cmdInfo,
		},
	}
	// plugin supplied commands
	baseCommands = append(baseCommands, plugins.GetCommands()...)

	app.Commands = baseCommands

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}