2016-05-07 19:37:15 +00:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
2017-02-21 03:35:51 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2016-05-07 19:37:15 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (d *ExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
|
|
|
|
// Only enable if cgroups are available and we are root
|
2017-02-21 03:35:51 +00:00
|
|
|
if !cgroupsMounted(node) {
|
|
|
|
if d.fingerprintSuccess == nil || *d.fingerprintSuccess {
|
2016-05-07 19:37:15 +00:00
|
|
|
d.logger.Printf("[DEBUG] driver.exec: cgroups unavailable, disabling")
|
|
|
|
}
|
2017-02-21 03:35:51 +00:00
|
|
|
d.fingerprintSuccess = helper.BoolToPtr(false)
|
2016-05-07 19:37:15 +00:00
|
|
|
delete(node.Attributes, execDriverAttr)
|
|
|
|
return false, nil
|
|
|
|
} else if unix.Geteuid() != 0 {
|
2017-02-21 03:35:51 +00:00
|
|
|
if d.fingerprintSuccess == nil || *d.fingerprintSuccess {
|
2016-05-07 19:37:15 +00:00
|
|
|
d.logger.Printf("[DEBUG] driver.exec: must run as root user, disabling")
|
|
|
|
}
|
|
|
|
delete(node.Attributes, execDriverAttr)
|
2017-02-21 03:35:51 +00:00
|
|
|
d.fingerprintSuccess = helper.BoolToPtr(false)
|
2016-05-07 19:37:15 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2017-02-23 22:40:24 +00:00
|
|
|
if d.fingerprintSuccess == nil || !*d.fingerprintSuccess {
|
2016-05-07 19:37:15 +00:00
|
|
|
d.logger.Printf("[DEBUG] driver.exec: exec driver is enabled")
|
|
|
|
}
|
|
|
|
node.Attributes[execDriverAttr] = "1"
|
2017-02-21 03:35:51 +00:00
|
|
|
d.fingerprintSuccess = helper.BoolToPtr(true)
|
2016-05-07 19:37:15 +00:00
|
|
|
return true, nil
|
|
|
|
}
|