Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Check if Docker is running
Browse files Browse the repository at this point in the history
  • Loading branch information
njuettner committed Nov 29, 2019
1 parent 0cb951f commit 3cae661
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ func (c *Cluster) Create() error {
if err := c.ensureSSHKey(); err != nil {
return err
}
if err := docker.IsRunning(); err != nil {
return err
}
for _, template := range c.spec.Machines {
if _, err := docker.PullIfNotPresent(template.Spec.Image, 2); err != nil {
return err
Expand Down Expand Up @@ -384,11 +387,17 @@ func (c *Cluster) DeleteMachine(machine *Machine, i int) error {

// Delete deletes the cluster.
func (c *Cluster) Delete() error {
if err := docker.IsRunning(); err != nil {
return err
}
return c.forEachMachine(c.DeleteMachine)
}

// Inspect will generate information about running or stopped machines.
func (c *Cluster) Inspect(hostnames []string) ([]*Machine, error) {
if err := docker.IsRunning(); err != nil {
return nil, err
}
machines, err := c.gatherMachines()
if err != nil {
return nil, err
Expand Down Expand Up @@ -510,6 +519,9 @@ func (c *Cluster) startMachine(machine *Machine, i int) error {

// Start starts the machines in cluster.
func (c *Cluster) Start(machineNames []string) error {
if err := docker.IsRunning(); err != nil {
return err
}
if len(machineNames) < 1 {
return c.forEachMachine(c.startMachine)
}
Expand Down Expand Up @@ -545,6 +557,9 @@ func (c *Cluster) stopMachine(machine *Machine, i int) error {

// Stop stops the machines in cluster.
func (c *Cluster) Stop(machineNames []string) error {
if err := docker.IsRunning(); err != nil {
return err
}
if len(machineNames) < 1 {
return c.forEachMachine(c.stopMachine)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/docker/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func Pull(image string, retries int) error {
return err
}

// IsRunning checks if Docker is running properly
func IsRunning() error {
cmd := exec.Command("docker", "info")
if err := cmd.Run(); err != nil {
log.WithError(err).Infoln("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
return err
}
return nil
}

func setPullCmd(image string) exec.Cmd {
cmd := exec.Command("docker", "pull", image)
cmd.SetStderr(os.Stderr)
Expand Down

0 comments on commit 3cae661

Please sign in to comment.