diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index 3a35a9cc33..e5a1b8e18a 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -840,6 +840,32 @@ func restorePath(path string) error { return nil } +// parse path to find out if its a systemd dropin +// Returns is dropin (true/false), service name, dropin name +func isSystemdDropin(path string) (bool, string, string) { + glog.V(2).Infof("DEBUG isSystemdDropin path=%v", path) + if !strings.HasPrefix(path, "/etc/systemd/system") { + return false, "", "" + } + pathSegments := strings.Split(path, "/") + glog.V(2).Infof("DEBUG isSystemdDropin pathSegments=%v", pathSegments) + if len(pathSegments) != 5 { + return false, "", "" + } + dropinName := pathSegments[len(pathSegments)-1] + glog.V(2).Infof("DEBUG isSystemdDropin dropinName=%v", dropinName) + servicePart := pathSegments[len(pathSegments)-2] + glog.V(2).Infof("DEBUG isSystemdDropin servicePart=%v", servicePart) + allServiceSegments := strings.Split(servicePart, ".") + glog.V(2).Infof("DEBUG isSystemdDropin allServiceSegments=%v", allServiceSegments) + if allServiceSegments[len(allServiceSegments)-1] != "d" { + return false, "", "" + } + serviceName := strings.Join(allServiceSegments[:len(allServiceSegments)-1], ".") + glog.V(2).Infof("DEBUG isSystemdDropin serviceName=%v", serviceName) + return true, serviceName, dropinName +} + // deleteStaleData performs a diff of the new and the old Ignition config. It then deletes // all the files, units that are present in the old config but not in the new one. // this function will error out if it fails to delete a file (with the exception @@ -892,6 +918,34 @@ func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig *igntypes.Config) e continue } + // Check Systemd.Units.Dropins - don't remove the file if configuration has been converted into a dropin + fileReplacedWithDropin := false + if ok, service, dropin := isSystemdDropin(f.Path); ok { + glog.V(2).Infof("DEBUG isSystemdDropin ok=%v service=%v dropin=%v", ok, service, dropin) + for _, u := range newIgnConfig.Systemd.Units { + glog.V(2).Infof("DEBUG isSystemdDropin service=%v", u.Name) + if u.Name == service { + glog.V(2).Infof("DEBUG isSystemdDropin found matching service") + for _, j := range u.Dropins { + glog.V(2).Infof("DEBUG isSystemdDropin dropin=%v", j.Name) + if j.Name == dropin { + glog.V(2).Infof("DEBUG isSystemdDropin found matching dropin") + fileReplacedWithDropin = true + break + } + } + if fileReplacedWithDropin { + break + } + } + } + } + + if fileReplacedWithDropin { + glog.V(2).Infof("Not removing file %q: replaced with systemd dropin", f.Path) + continue + } + if err := os.Remove(origFileName(f.Path)); err != nil { return errors.Wrapf(err, "deleting orig file %q: %v", origFileName(f.Path), err) }