Ejemplo n.º 1
0
func restartContainer(cmd *cobra.Command, args []string) {
	if err := deployment.ExtractContainerLocatorsFromDeployment(deploymentPath, &args); err != nil {
		Fail(1, err.Error())
	}
	if len(args) < 1 {
		Fail(1, "Valid arguments: <id> ...\n")
	}
	ids, err := NewContainerLocators(args...)
	if err != nil {
		Fail(1, "You must pass one or more valid service names: %s\n", err.Error())
	}

	if len(ids) == 1 && !ids[0].IsRemote() {
		fmt.Fprintf(os.Stderr, "You can also control this container via 'systemctl restart %s'\n", ids[0].(ResourceLocator).Identifier().UnitNameFor())
	}
	Executor{
		On: ids,
		Serial: func(on Locator) jobs.Job {
			return &http.HttpRestartContainerRequest{
				RestartContainerRequest: jobs.RestartContainerRequest{
					Id: on.(ResourceLocator).Identifier(),
				},
			}
		},
		Output:    os.Stdout,
		LocalInit: needsSystemd,
	}.StreamAndExit()
}
Ejemplo n.º 2
0
func deleteContainer(cmd *cobra.Command, args []string) {
	if err := deployment.ExtractContainerLocatorsFromDeployment(deploymentPath, &args); err != nil {
		Fail(1, err.Error())
	}
	if len(args) < 1 {
		Fail(1, "Valid arguments: <id> ...\n")
	}
	ids, err := NewContainerLocators(args...)
	if err != nil {
		Fail(1, "You must pass one or more valid service names: %s\n", err.Error())
	}

	Executor{
		On: ids,
		Serial: func(on Locator) jobs.Job {
			return &http.HttpDeleteContainerRequest{
				Label: on.Identity(),
				DeleteContainerRequest: jobs.DeleteContainerRequest{
					Id: on.(ResourceLocator).Identifier(),
				},
			}
		},
		Output: os.Stdout,
		OnSuccess: func(r *CliJobResponse, w io.Writer, job interface{}) {
			fmt.Fprintf(w, "Deleted %s", job.(jobs.LabeledJob).JobLabel())
		},
		LocalInit: needsSystemdAndData,
	}.StreamAndExit()
}
Ejemplo n.º 3
0
func containerStatus(cmd *cobra.Command, args []string) {
	if err := deployment.ExtractContainerLocatorsFromDeployment(deploymentPath, &args); err != nil {
		Fail(1, err.Error())
	}
	if len(args) < 1 {
		Fail(1, "Valid arguments: <id> ...\n")
	}
	ids, err := NewContainerLocators(args...)
	if err != nil {
		Fail(1, "You must pass one or more valid service names: %s\n", err.Error())
	}

	if len(ids) == 1 && !ids[0].IsRemote() {
		fmt.Fprintf(os.Stderr, "You can also display the status of this container via 'systemctl status %s'\n", ids[0].(ResourceLocator).Identifier().UnitNameFor())
	}
	data, errors := Executor{
		On: ids,
		Serial: func(on Locator) jobs.Job {
			return &http.HttpContainerStatusRequest{
				ContainerStatusRequest: jobs.ContainerStatusRequest{
					Id: on.(ResourceLocator).Identifier(),
				},
			}
		},
		Output:    os.Stdout,
		LocalInit: needsSystemd,
	}.Gather()

	for i := range data {
		if buf, ok := data[i].(*bytes.Buffer); ok {
			if i > 0 {
				fmt.Fprintf(os.Stdout, "\n-------------\n")
			}
			buf.WriteTo(os.Stdout)
		}
	}
	if len(errors) > 0 {
		for i := range errors {
			fmt.Fprintf(os.Stderr, "Error: %s\n", errors[i])
		}
		os.Exit(1)
	}
	os.Exit(0)
}