Exemple #1
0
func (FilePlugin) Perform(req *api.StatusRequest, ch chan bool) {

	client, err := docker.GetConnection(req.Socket)

	if err != nil {
		ch <- false
		return
	}

	filePath := "/tmp/.ready"

	if len(req.Args) > 1 {
		filePath = req.Args[1]
	}

	cmd := []string{"/bin/sh", "-c", "[ -e " + filePath + " ]"}

	containerNsPID, err := client.ChildProcessForContainer(req.Container)
	exitCode, err := namespace.RunIn(req.Container.Name, containerNsPID, cmd, req.Container.Config.Env)

	if req.Verbose {
		log.Printf("[file] The file '%s' exists == %t\n", filePath, exitCode)
	}

	if exitCode == 0 {
		ch <- true
	} else {
		ch <- false
	}

}
Exemple #2
0
func runCommandInContainer(name string, command []string, environment []string) {
	if len(command) == 0 {
		fmt.Println("No command specified")
		os.Exit(3)
	}

	client, err := docker.GetConnection("unix:///var/run/docker.sock")
	if err != nil {
		fmt.Printf("Unable to connect to server\n")
		os.Exit(3)
	}

	container, err := client.GetContainer(name, false)
	if err != nil {
		fmt.Printf("Unable to locate container named %v\n", name)
		os.Exit(3)
	}
	containerNsPID, err := client.ChildProcessForContainer(container)
	if err != nil {
		fmt.Println("Couldn't create child process for container")
		os.Exit(3)
	}

	namespace.RunIn(name, containerNsPID, command, environment)
}
Exemple #3
0
func runCommand(name string, command []string, environment []string) {
	client, err := docker.GetConnection("unix:///var/run/docker.sock")
	if err != nil {
		fmt.Printf("Unable to connect to server\n")
		os.Exit(3)
	}

	container, err := client.GetContainer(name, false)
	if err != nil {
		fmt.Printf("Unable to locate container named %v\n", name)
		os.Exit(3)
	}
	containerNsPID, err := client.ChildProcessForContainer(container)
	if err != nil {
		os.Exit(3)
	}
	namespace.RunIn(name, containerNsPID, command, environment)
}