Skip to content

Commit

Permalink
daemon: Use systemd-run, not machine-config-daemon-host.service
Browse files Browse the repository at this point in the history
This is the mirror/dual of
openshift#1802

With this the MCD (when run as a pod) stops using `machine-config-daemon-host.service`.
and creates a dynamic unit instead.

With the combination of both, `machine-config-daemon-host.service` is on the
path to not being used by default and migrating to a "4.1 bootimage aid".

The systemd-run model of creating a unit dynamically is much clearer for what we want here;
conceptually the service is just a dynamic child of this pod (if we could we'd
tie the lifecycle together).  Further:

- Let's shorten our systemd unit names by using the `mco-` prefix
- Inject the `RPMOSTREE_CLIENT_ID`, see coreos/rpm-ostree@016c1c5

For example, one weird semantic of `systemctl start` is that it "joins" if
somehow the service is started for another reason.  But here, if somehow
two instances of the MCD were running then `systemd-run` will say e.g.:
`Failed to start transient service unit: Unit mco-pivot.service already exists.`
  • Loading branch information
cgwalters committed Jun 9, 2020
1 parent 97d5ed6 commit 3edf11d
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions pkg/daemon/rpm-ostree.go
Expand Up @@ -322,23 +322,16 @@ func (r *RpmOstreeClient) RunPivot(osImageURL string) error {
return errors.Wrap(err, "deleting pivot reboot-needed file")
}

service := "machine-config-daemon-host.service"
// We need to use pivot if it's there, because machine-config-daemon-host.service
// currently has a ConditionPathExists=!/usr/lib/systemd/system/pivot.service to
// avoid having *both* pivot and MCD try to update. This code can be dropped
// once we don't need to care about compat with older RHCOS.
var err error
_, err = os.Stat("/usr/lib/systemd/system/pivot.service")
// We used to start machine-config-daemon-host here, but now we make a dynamic
// unit because that service was started in too many ways, and the systemd-run
// model of creating a unit dynamically is much clearer for what we want here;
// conceptually the service is just a dynamic child of this pod (if we could we'd
// tie the lifecycle together). Further, let's shorten our systemd unit names
// by using the mco- prefix, and we also inject the RPMOSTREE_CLIENT_ID now.
err := exec.Command("systemd-run", "--wait", "--collect", "--unit=mco-pivot",
"-E", "RPMOSTREE_CLIENT_ID=mco", "/usr/libexec/machine-config-daemon", "pivot", osImageURL).Run()
if err != nil {
if !os.IsNotExist(err) {
return errors.Wrapf(err, "checking pivot service")
}
} else {
service = "pivot.service"
}
err = exec.Command("systemctl", "start", service).Run()
if err != nil {
return errors.Wrapf(err, "failed to start %s", service)
return errors.Wrapf(err, "failed to run pivot")
}
return nil
}
Expand All @@ -349,6 +342,7 @@ func followPivotJournalLogs(stopCh <-chan time.Time) {
cmd := exec.Command("journalctl", "-f", "-b", "-o", "cat",
"-u", "rpm-ostreed",
"-u", "pivot",
"-u", "mco-pivot",
"-u", "machine-config-daemon-host")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 3edf11d

Please sign in to comment.