This refactor will make it easier to integrate lkvm support, and also
brings other benefits.
Specifically, with this refactor almost all functionality of stage1
init is flavor independent and can be fully controlled via a manifest
and uses as little hard coded paths as possible.
Thus, e.g. distribution packagers, can create package which will only
have rkt/stage1 provided binaries (gc, waiter, init, etc.) and specify
the rest of things in the manifest (path to nspawn, ld.so, LD LIBRARY
PATH, libfakesdbooted.so, etc). And create fully free-standing
stage1.aci by simply creating basic distribution chroot with
distro-native tools and supplying a matching/correct aci-manifest. By
fully free-standing, I mean similar to current coreos flavor, which is
completely independent of the host OS binaries & load paths and is
truly run everywhere.
Many of these refactors will be useful for future lkvm integration,
e.g. reusing ld.so load paths and similar.
$OSTYPE is "linux" on OpenSUSE 13.2. uname should be more reliable.
$OSTYPE was introduced for OS X in commit cb78269. Also, disable
functional tests on non-Linux.
Fixes: https://github.com/coreos/rkt/issues/1005
When systemd-nspawn receives a TERM signal it will send it to systemd in
stage1 which will try to run the halt.target. This target was not
present in the current stage1 so the container was not being shut down.
Fix this by adding halt.target which calls reaper.service to shut down
the container cleanly.
--link-journal=host fails if the host system doesn't have persistent
journaling enabled. Fix that by using "try-host"; if the system has
persistent journaling enabled it links the journal, otherwise it skips
the linking without exiting with a failure.
In 969a57c6 (stage1: use --link-journal=host instead of try-host) we
switched from "try-host" to "host" to support journal linking in systemd
versions <219 but now we don't support it on them anymore.
Some controller cgroup knob files can be disabled in kernel. If the
file we want doesn't exist, just ignore it when we bind-mount knobs over
themselves.
Instead of bind-mounting the whole controller subcgroup directory RW we
only bind-mount the files we need to set isolators. This reduces the
cgroup attack surface.
This commit adds memory and cpu isolators to test we don't break
anything. The next step is adding a functional test that actually checks
the isolators are respected.
To allow systemd inside stage1 to set resource limits for apps we mount
the cgroup controllers hierarchy in rkt. We need this because
systemd-nspawn mounts cgroup controllers as read-only.
We mimic systemd-nspawn cgroup mounts with the difference that we
bind-mount the apps' subdirectories over themselves so they stay
read-write. We leave the mounting of systemd's cgroup hierarchy to
nspawn.
SliceToPath explodes a slice name to its corresponding path in the cgroup
hierarchy. For example, a slice named "foo-bar-baz.slice" corresponds to the
path "foo.slice/foo-bar.slice/foo-bar-baz.slice". See systemd.slice(5)
Since SliceToPath needs to do escapings and sanity checks, several
functions used in systemd for that purpose are also ported.
Previously we were only entering a mount namespace in rkt when we used
overlay fs. Since we now mount the cgroup controller hierarchy we enter
a new mount namespace it in every case.
Instead of asking systemd-nspawn to write its "pid" file, rkt can write
the parent pid "ppid". Then, update getPID() to get the pid file from
/proc/$ppid/task/$ppid/children. In this way, we don't need to patch
systemd-nspawn.
getPID() is able to read both the "pid" file and the "ppid" file, in
order to work with alternative stage1s which choose to implement one or
the other method.
coreos/rkt#910