2016-05-07 19:37:15 +00:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
2018-01-24 14:09:53 +00:00
|
|
|
cstructs "github.com/hashicorp/nomad/client/structs"
|
2017-02-21 03:35:51 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2016-05-07 19:37:15 +00:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2017-09-26 22:26:33 +00:00
|
|
|
const (
|
|
|
|
// The key populated in Node Attributes to indicate the presence of the Exec
|
|
|
|
// driver
|
|
|
|
execDriverAttr = "driver.exec"
|
|
|
|
)
|
|
|
|
|
2018-01-24 14:09:53 +00:00
|
|
|
func (d *ExecDriver) Fingerprint(req *cstructs.FingerprintRequest, resp *cstructs.FingerprintResponse) error {
|
2016-05-07 19:37:15 +00:00
|
|
|
// Only enable if cgroups are available and we are root
|
2018-01-24 14:09:53 +00:00
|
|
|
if !cgroupsMounted(req.Node) {
|
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: cgroups unavailable, disabling")
|
|
|
|
}
|
2017-02-21 03:35:51 +00:00
|
|
|
d.fingerprintSuccess = helper.BoolToPtr(false)
|
2018-01-24 14:09:53 +00:00
|
|
|
return nil
|
2016-05-07 19:37:15 +00:00
|
|
|
} 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")
|
|
|
|
}
|
2017-02-21 03:35:51 +00:00
|
|
|
d.fingerprintSuccess = helper.BoolToPtr(false)
|
2018-01-24 14:09:53 +00:00
|
|
|
return nil
|
2016-05-07 19:37:15 +00:00
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
}
|
2018-01-24 14:09:53 +00:00
|
|
|
resp.Attributes[execDriverAttr] = "1"
|
2017-02-21 03:35:51 +00:00
|
|
|
d.fingerprintSuccess = helper.BoolToPtr(true)
|
2018-01-24 14:09:53 +00:00
|
|
|
return nil
|
2016-05-07 19:37:15 +00:00
|
|
|
}
|