Пример #1
0
func serviceCommand() cli.Command {
	factory := &projectFactory{}

	app := cli.Command{}
	app.Name = "service"
	app.ShortName = "s"
	app.Usage = "Command line interface for services and compose."
	app.Before = beforeApp
	app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
	app.Subcommands = append(serviceSubCommands(),
		command.BuildCommand(factory),
		command.CreateCommand(factory),
		command.UpCommand(factory),
		command.StartCommand(factory),
		command.LogsCommand(factory),
		command.RestartCommand(factory),
		command.StopCommand(factory),
		command.ScaleCommand(factory),
		command.RmCommand(factory),
		command.PullCommand(factory),
		command.KillCommand(factory),
		command.PortCommand(factory),
		command.PsCommand(factory),
	)

	return app
}
Пример #2
0
func getCommands(config Config) []cli.Command {
	exportCmds := []cli.Command{}

	var keys []string
	for k := range config.Commands {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	for _, name := range keys {
		cmd := config.Commands[name]
		cmdName := name
		subCommands := []cli.Command{}

		// Handle the import of subcommands.
		if cmd.Import != "" {
			// If the first character isn't "/" or "~" we assume a relative path.
			subSource := cmd.Import
			if cmd.Import[0] != "/"[0] || cmd.Import[0] != "~"[0] {
				subSource = filepath.Join(sourcedir, cmd.Import)
			}
			logger("info", "Importing commands into '"+name+"' command from "+subSource)
			subConfig, _ := getConfig(subSource)
			subCommands = getCommands(subConfig)
		}

		newCmd := cli.Command{
			Name:            name,
			SkipFlagParsing: true,
			HideHelp:        cmd.Hide,
		}

		if cmd.Usage != "" {
			newCmd.Usage = cmd.Usage
		}

		if cmd.Cmd != "" {
			newCmd.Action = func(c *cli.Context) {
				args = c.Args()
				runCommand(cmdName, cmd.Cmd)
			}
		}

		if subCommands != nil {
			newCmd.Subcommands = subCommands
		}

		//log.Println("found command: ", name, " > ", cmd.Cmd )
		exportCmds = append(exportCmds, newCmd)
	}

	return exportCmds
}
Пример #3
0
func selinuxCommand() cli.Command {
	app := cli.Command{}
	app.Name = "selinux"
	app.Usage = "Launch SELinux tools container."
	app.Action = func(c *cli.Context) error {
		argv := []string{"system-docker", "run", "-it", "--privileged", "--rm",
			"--net", "host", "--pid", "host", "--ipc", "host",
			"-v", "/usr/bin/docker:/usr/bin/docker.dist:ro",
			"-v", "/usr/bin/ros:/usr/bin/dockerlaunch:ro",
			"-v", "/usr/bin/ros:/usr/bin/user-docker:ro",
			"-v", "/usr/bin/ros:/usr/bin/system-docker:ro",
			"-v", "/usr/bin/ros:/sbin/poweroff:ro",
			"-v", "/usr/bin/ros:/sbin/reboot:ro",
			"-v", "/usr/bin/ros:/sbin/halt:ro",
			"-v", "/usr/bin/ros:/sbin/shutdown:ro",
			"-v", "/usr/bin/ros:/usr/bin/respawn:ro",
			"-v", "/usr/bin/ros:/usr/bin/ros:ro",
			"-v", "/usr/bin/ros:/usr/bin/cloud-init:ro",
			"-v", "/usr/bin/ros:/usr/sbin/netconf:ro",
			"-v", "/usr/bin/ros:/usr/sbin/wait-for-network:ro",
			"-v", "/usr/bin/ros:/usr/sbin/wait-for-docker:ro",
			"-v", "/var/lib/docker:/var/lib/docker",
			"-v", "/var/lib/rkt:/var/lib/rkt",
			"-v", "/dev:/host/dev",
			"-v", "/etc/docker:/etc/docker",
			"-v", "/etc/hosts:/etc/hosts",
			"-v", "/etc/resolv.conf:/etc/resolv.conf",
			"-v", "/etc/rkt:/etc/rkt",
			"-v", "/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt.rancher",
			"-v", "/lib/firmware:/lib/firmware",
			"-v", "/lib/modules:/lib/modules",
			"-v", "/run:/run",
			"-v", "/usr/share/ros:/usr/share/ros",
			"-v", "/var/lib/rancher/conf:/var/lib/rancher/conf",
			"-v", "/var/lib/rancher:/var/lib/rancher",
			"-v", "/var/log:/var/log",
			"-v", "/var/run:/var/run",
			"-v", "/home:/home",
			"-v", "/opt:/opt",
			"-v", "/etc/selinux:/etc/selinux",
			"-v", "/var/lib/selinux:/var/lib/selinux",
			"-v", "/usr/share/selinux:/usr/share/selinux",
			fmt.Sprintf("rancher/os-selinuxtools:%s", config.VERSION+config.SUFFIX), "bash"}
		syscall.Exec("/bin/system-docker", argv, []string{})
		return nil
	}

	return app
}
Пример #4
0
func getCommands(config Config) []cli.Command {
	exportCmds := []cli.Command{}

	var keys []string
	for k := range config.Commands {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	for _, name := range keys {
		cmd := config.Commands[name]
		cmdName := name

		newCmd := cli.Command{
			Name:            name,
			SkipFlagParsing: true,
			HideHelp:        cmd.Hide,
		}

		if cmd.Usage != "" {
			newCmd.Usage = cmd.Usage
		}

		if cmd.Cmd != "" {
			newCmd.Action = func(c *cli.Context) {
				args = c.Args()
				runCommand(cmdName, cmd.Cmd)
			}
		}

		subCommands := getSubCommands(cmd.Imports)
		if subCommands != nil {
			newCmd.Subcommands = subCommands
		}

		//log.Println("found command: ", name, " > ", cmd.Cmd )
		exportCmds = append(exportCmds, newCmd)
	}

	return exportCmds
}
Пример #5
0
func getCommand(baseName string, metadata command_metadata.CommandMetadata, runner command_runner.Runner) cli.Command {
	command := cli.Command{
		Name:        metadata.Name,
		Aliases:     metadata.Aliases,
		ShortName:   metadata.ShortName,
		Description: metadata.Description,
		Usage:       strings.Replace(metadata.Usage, "BROOKLYN_NAME", baseName, -1),
		Action: func(context *cli.Context) {
			err := runner.RunCmdByName(metadata.Name, context)
			if err != nil {
				error_handler.ErrorExit(err)
			}
		},
		Flags:           metadata.Flags,
		SkipFlagParsing: metadata.SkipFlagParsing,
	}

	if nil != metadata.Operands {
		command.Subcommands = make([]cli.Command, 0)
		for _, operand := range metadata.Operands {
			command.Subcommands = append(command.Subcommands, cli.Command{
				Name:            operand.Name,
				Aliases:         operand.Aliases,
				ShortName:       operand.ShortName,
				Description:     operand.Description,
				Usage:           operand.Usage,
				Flags:           operand.Flags,
				SkipFlagParsing: operand.SkipFlagParsing,
				Action:          subCommandAction(command.Name, operand.Name, runner),
			})
			command.Usage = strings.Join([]string{
				command.Usage, "\n... ", operand.Usage, "\t", operand.Description,
			}, "")
		}
	}

	return command
}