Check if Docker is installed and installed
(nodeUser, node string)
| 116 | |
| 117 | // Check if Docker is installed and installed |
| 118 | func checkAndInstallDocker(nodeUser, node string) error { |
| 119 | // Check if Docker is installed |
| 120 | cmd := exec.Command("ssh", nodeUser+"@"+node, "docker --version") |
| 121 | output, err := cmd.Output() |
| 122 | if err == nil && strings.Contains(string(output), "Docker version") { |
| 123 | // log.Println("Docker installed") |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | // Docker not installed, installing Docker |
| 128 | cmd = exec.Command("ssh", nodeUser+"@"+node, "yum", "install", "docker", "-y") |
| 129 | |
| 130 | // Set output to standard output and standard error output |
| 131 | cmd.Stdout = os.Stdout |
| 132 | cmd.Stderr = os.Stderr |
| 133 | |
| 134 | // Execute Command |
| 135 | err = cmd.Run() |
| 136 | if err != nil { |
| 137 | return fmt.Errorf("failed to install Docker on node %s", node) |
| 138 | } |
| 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | // Check if the Docker service is started and started |
| 144 | func checkAndStartDockerService(nodeUser, node string) error { |
no test coverage detected