This commit is contained in:
Dave Poole 2024-04-24 11:04:11 -07:00
Родитель e4c00e98d7
Коммит 0c9a693cc7
1 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -311,10 +311,9 @@ func setupVMWatchCommand(s *vmWatchSettings, hEnv HandlerEnvironment) (*exec.Cmd
runningWithSystemd := false
var cmd *exec.Cmd
// if we have systemd available, we will use that to launch the process, otherwise we will launch directly and manipulate our own cgroups
// check if /run/systemd/system exists, if so we have systemd and can use systemd-run
// since systemd-run is in different paths on different distros, we will check for systemd but not use the full path
// to systemd-run. This is how guest agent handles it also so seems appropriate.
if info, err := os.Stat("/run/systemd/system"); err == nil && info.IsDir() {
if isSystemdAvailable() {
// since systemd-run is in different paths on different distros, we will check for systemd but not use the full path
// to systemd-run. This is how guest agent handles it also so seems appropriate.
systemdArgs := []string{"--scope", "-p", fmt.Sprintf("CPUQuota=%v%%", s.MaxCpuPercentage), "-p", fmt.Sprintf("MemoryMax=%v", s.MemoryLimitInBytes)}
// now append the env variables
for _, v := range GetVMWatchEnvironmentVariables(s.ParameterOverrides, hEnv) {
@ -333,6 +332,12 @@ func setupVMWatchCommand(s *vmWatchSettings, hEnv HandlerEnvironment) (*exec.Cmd
return cmd, runningWithSystemd, nil
}
func isSystemdAvailable() bool {
// check if /run/systemd/system exists, if so we have systemd
info, err := os.Stat("/run/systemd/system")
return err == nil && info.IsDir()
}
func createAndAssignCgroups(ctx *log.Context, vmwatchSettings *vmWatchSettings, vmWatchPid int) error {
// get our process and use this to determine the appropriate mount points for the cgroups
myPid := os.Getpid()