diff --git a/client/driver/docker.go b/client/driver/docker.go index aa5325c40..78c2a7bc2 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -162,20 +162,23 @@ func (d *DockerDriver) dockerClient() (*docker.Client, error) { } func (d *DockerDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { + // Get the current status so that we can log any debug messages only if the + // state changes + _, currentlyEnabled := node.Attributes[dockerDriverAttr] + // Initialize docker API client client, err := d.dockerClient() if err != nil { - d.logger.Printf("[INFO] driver.docker: failed to initialize client: %s", err) delete(node.Attributes, dockerDriverAttr) + if currentlyEnabled { + d.logger.Printf("[INFO] driver.docker: failed to initialize client: %s", err) + } return false, nil } privileged := d.config.ReadBoolDefault("docker.privileged.enabled", false) if privileged { - d.logger.Println("[DEBUG] driver.docker: privileged containers are enabled") node.Attributes["docker.privileged.enabled"] = "1" - } else { - d.logger.Println("[DEBUG] driver.docker: privileged containers are disabled") } // This is the first operation taken on the client so we'll try to @@ -183,13 +186,15 @@ func (d *DockerDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool // Docker isn't available so we'll simply disable the docker driver. env, err := client.Version() if err != nil { - d.logger.Printf("[DEBUG] driver.docker: could not connect to docker daemon at %s: %s", client.Endpoint(), err) + if currentlyEnabled { + d.logger.Printf("[DEBUG] driver.docker: could not connect to docker daemon at %s: %s", client.Endpoint(), err) + } delete(node.Attributes, dockerDriverAttr) return false, nil } + node.Attributes[dockerDriverAttr] = "1" node.Attributes["driver.docker.version"] = env.Get("Version") - return true, nil } diff --git a/client/driver/exec.go b/client/driver/exec.go index 3e5235850..71a9ab871 100644 --- a/client/driver/exec.go +++ b/client/driver/exec.go @@ -59,17 +59,28 @@ func NewExecDriver(ctx *DriverContext) Driver { } func (d *ExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { + // Get the current status so that we can log any debug messages only if the + // state changes + _, currentlyEnabled := node.Attributes[execDriverAttr] + // Only enable if cgroups are available and we are root if _, ok := node.Attributes["unique.cgroup.mountpoint"]; !ok { - d.logger.Printf("[DEBUG] driver.exec: cgroups unavailable, disabling") + if currentlyEnabled { + d.logger.Printf("[DEBUG] driver.exec: cgroups unavailable, disabling") + } delete(node.Attributes, execDriverAttr) return false, nil } else if syscall.Geteuid() != 0 { - d.logger.Printf("[DEBUG] driver.exec: must run as root user, disabling") + if currentlyEnabled { + d.logger.Printf("[DEBUG] driver.exec: must run as root user, disabling") + } delete(node.Attributes, execDriverAttr) return false, nil } + if !currentlyEnabled { + d.logger.Printf("[DEBUG] driver.exec: exec driver is enabled") + } node.Attributes[execDriverAttr] = "1" return true, nil } diff --git a/client/driver/java.go b/client/driver/java.go index 0ac6ce474..28d3f8407 100644 --- a/client/driver/java.go +++ b/client/driver/java.go @@ -67,9 +67,15 @@ func NewJavaDriver(ctx *DriverContext) Driver { } func (d *JavaDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { + // Get the current status so that we can log any debug messages only if the + // state changes + _, currentlyEnabled := node.Attributes[javaDriverAttr] + // Only enable if we are root and cgroups are mounted when running on linux systems. if runtime.GOOS == "linux" && (syscall.Geteuid() != 0 || !d.cgroupsMounted(node)) { - d.logger.Printf("[DEBUG] driver.java: root priviledges and mounted cgroups required on linux, disabling") + if currentlyEnabled { + d.logger.Printf("[DEBUG] driver.java: root priviledges and mounted cgroups required on linux, disabling") + } delete(node.Attributes, "driver.java") return false, nil } @@ -99,7 +105,9 @@ func (d *JavaDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, } if infoString == "" { - d.logger.Println("[WARN] driver.java: error parsing Java version information, aborting") + if currentlyEnabled { + d.logger.Println("[WARN] driver.java: error parsing Java version information, aborting") + } delete(node.Attributes, javaDriverAttr) return false, nil } diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 5ccd88653..e593df595 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -66,6 +66,10 @@ func NewQemuDriver(ctx *DriverContext) Driver { } func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { + // Get the current status so that we can log any debug messages only if the + // state changes + _, currentlyEnabled := node.Attributes[qemuDriverAttr] + bin := "qemu-system-x86_64" if runtime.GOOS == "windows" { // On windows, the "qemu-system-x86_64" command does not respond to the @@ -85,9 +89,11 @@ func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, return false, fmt.Errorf("Unable to parse Qemu version string: %#v", matches) } + if !currentlyEnabled { + d.logger.Printf("[DEBUG] driver.qemu: enabling driver") + } node.Attributes[qemuDriverAttr] = "1" node.Attributes["driver.qemu.version"] = matches[1] - return true, nil } diff --git a/client/driver/raw_exec.go b/client/driver/raw_exec.go index 85563b709..2421abd7b 100644 --- a/client/driver/raw_exec.go +++ b/client/driver/raw_exec.go @@ -57,11 +57,17 @@ func NewRawExecDriver(ctx *DriverContext) Driver { } func (d *RawExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { + // Get the current status so that we can log any debug messages only if the + // state changes + _, currentlyEnabled := node.Attributes[rawExecDriverAttr] + // Check that the user has explicitly enabled this executor. enabled := cfg.ReadBoolDefault(rawExecConfigOption, false) if enabled { - d.logger.Printf("[WARN] driver.raw_exec: raw exec is enabled. Only enable if needed") + if currentlyEnabled { + d.logger.Printf("[WARN] driver.raw_exec: raw exec is enabled. Only enable if needed") + } node.Attributes[rawExecDriverAttr] = "1" return true, nil } diff --git a/client/driver/rkt.go b/client/driver/rkt.go index 057020e54..fb0745bba 100644 --- a/client/driver/rkt.go +++ b/client/driver/rkt.go @@ -89,9 +89,15 @@ func NewRktDriver(ctx *DriverContext) Driver { } func (d *RktDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { + // Get the current status so that we can log any debug messages only if the + // state changes + _, currentlyEnabled := node.Attributes[rktDriverAttr] + // Only enable if we are root when running on non-windows systems. if runtime.GOOS != "windows" && syscall.Geteuid() != 0 { - d.logger.Printf("[DEBUG] driver.rkt: must run as root user, disabling") + if currentlyEnabled { + d.logger.Printf("[DEBUG] driver.rkt: must run as root user, disabling") + } delete(node.Attributes, rktDriverAttr) return false, nil }