95 Commits

Author SHA1 Message Date
Dimitri John Ledkov 5774390b2d Refactor stage1/init to source most of options from manifest, rather than flavor/stampfile-based.
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.
2015-06-09 10:47:56 +01:00
Alban Crequy ae9cdf168e stage1: refresh systemd patches for v219
With this change, the only patches applied on v219 are backports from systemd upstream:

https://github.com/systemd/systemd/commit/4f923a1984476de3441922ee5bf7102ebdd250ef
https://github.com/systemd/systemd/commit/47bc12e1ba35d38edda737dae232088d6d3ae688
https://github.com/systemd/systemd/commit/54b4755f15438c86991d5a4eaadc47150f7e5a84
https://github.com/systemd/systemd/commit/875e1014dd9d55cd0692dcce843598cffb2d09b0
https://github.com/systemd/systemd/commit/6b7d2e9ea4cdb4cfa1512d37548a1a967623d7f2

The patches in stage1/rootfs/usr_from_src/patches/v219/ have been tagged
with the "Origin" URL.

stage1/init/init.go is modified accordingly to avoid --keep-fd.

Fixes: #998
2015-06-08 18:26:56 +02:00
Kyle Ibrahim e5585a5239 stage1:init fix wrong ppid when using --private-net 2015-06-07 22:06:07 +00:00
Jonathan Boulle 7bf926e4fe Merge pull request #990 from endocode/iaguis/check-cgroups-before-enabling-them
stage1: take into account not-supported isolators
2015-06-05 10:10:04 -07:00
Iago López Galeiras e04ef0a43f stage1: add test for parseCgroups function
This commit modifies parseCgroups() to take an io.Reader as parameter
and adds a test for it.
2015-06-05 17:23:05 +02:00
Iago López Galeiras 27ec47b2cd stage1: use --link-journal=try-host in systemd-nspawn
--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.
2015-06-05 15:43:28 +02:00
Iago López Galeiras 906ce611bd stage1: check if isolators are supported and warn if not
Warn the user if an isolator is requested but is not supported.
2015-06-04 18:11:00 +02:00
Iago López Galeiras 3eeb27ffbe stage1: refactor cgroup-related functions
Move them to a new cgroup.go file.
2015-06-04 18:11:00 +02:00
Iago López Galeiras d5a3f50306 stage1: mount cgroup file RW only if it exists
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.
2015-06-04 18:11:00 +02:00
Alban Crequy 510930bf09 stage1, flavor usr-from-host: look in /usr/lib first
See:
http://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/
2015-06-04 17:57:12 +02:00
Alban Crequy 2824964937 stage1: add RKT_STAGE1_USR_FROM=usr-from-host 2015-06-04 16:33:45 +02:00
Iago López Galeiras 74075ab1d6 stage1: bind-mount cgroup controller files RW
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.
2015-06-03 18:42:17 +02:00
Iago López Galeiras c2c9ea9fc1 stage1: fix parseCgroups function
It wasn't taking into account if the cgroup controller was enabled or
not.
2015-06-03 16:07:46 +02:00
Iago López Galeiras 52213ca754 stage1: handle CPU isolator 2015-06-03 14:28:14 +02:00
Iago López Galeiras 9fb037d019 stage1: handle memory isolator 2015-06-03 14:28:14 +02:00
Iago López Galeiras 67c6c73a9e stage1: create cgroups before calling systemd-nspawn
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.
2015-06-03 14:28:14 +02:00
Alban Crequy 2c25275523 stage1: remove --pid-file patches from systemd-nspawn
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
2015-06-03 12:58:09 +02:00
Eugene Yakubovich 2440b4a54d Merge pull request #960 from steveeJ/private-net-selection2
networking: allow network selection with private-net (2nd impl.)
2015-05-29 17:42:47 -07:00
Stefan Junker c65f7aa31f networking: allow network selection with private-net
This commit adds the possiblity of passing a comma separated list of network
names to the '-private-net' argument. Only networks with their names specified
are loaded in the pods network stack.

The network documentation has been updated accordingly.
2015-05-29 17:21:53 -07:00
Stefan Junker 299a0ee6ad networking: populate AC_METADATA_URL correctly
This commit allows the mentioned environment var to be populated correctly.
On the way some error handling for involved code was added.
2015-05-29 11:35:09 -07:00
Jonathan Boulle 33472688a4 stage1: fix metadata service registration errors
When registering a pod to the metadata service, if individual app
registrations failed then an error object was being instantiated but not
actually returned. This fixes it to return the error and also to make a
best-effort attempt to unregister the pod in this scenario.

Also tweaks the file operations to close manifests more immediately
after they've been used.

Also fixes minor typo in rkt/metadata_service error message.
2015-05-28 11:19:47 -07:00
Iago López Galeiras 910881404d stage1: write prepare-app service programmatically
In prepare-app we depend on systemd-journal.service only if journal
linking is supported by systemd in stage1.

This commit generates prepare-app@.service so we can add this dependency
only when it's supported.
2015-05-28 16:12:39 +02:00
Iago López Galeiras acdde8a34e stage1: link journal only on systemd v219, v220 and master
If we enable journal linking, there's a race in systemd v215 that makes
(very) short-lived containers not show their output in stdout, making
tests fail. Since the CoreOS image will be updated soon we don't bother
investigating this issue and just disable journal linking in old
versions of systemd
2015-05-28 12:32:30 +02:00
Iago López Galeiras 969a57c669 stage1: use --link-journal=host instead of try-host
Since we check if we're running systemd before appending --link-journal
to systemd-nspawn we can use host instead of try-host.

This allows connecting a pod's journal to the host's journal with
systemd version <219.
2015-05-28 12:18:52 +02:00
Iago López Galeiras 6b176f55f1 stage1: link journal to the host on hosts running systemd
This commit links the journal to the host passing the option
--link-journal=try-host to systemd-nspawn.

We also populate pod's /etc/machine-id with its UUID before running
systemd-nspawn because nspawn will try to read it.
2015-05-28 12:18:52 +02:00
Iago López Galeiras dcff3bd1d8 stage1: set SyslogIdentifier to the name of the executable 2015-05-28 10:22:59 +02:00
Iago López Galeiras cd4aec48cb stage1: connect stdout and stderr to journal+console
This will send apps' output to the journal as well.
2015-05-28 10:22:59 +02:00
Alban Crequy ab9182d182 rkt: better error messages when users don't give enough volumes
Example of output:
|  $ rkt --debug --insecure-skip-verify run docker://redis
|  Failed to generate nspawn args: no volume for mountpoint "volume-/data" in app "redis".
|  You can inspect the volumes with:
|  	sudo rkt image cat-manifest --pretty-print sha512-f95f15ce81345214328fdbe9407fdac3e46de0c11ceb69e8da5b0d1aa3158dfc
|  App "redis" requires the following volumes:
|  	--volume volume-/data,kind=host,source=/some/path

Fixes: https://github.com/coreos/rkt/issues/943
2015-05-27 12:51:02 +02:00
Alban Crequy f4b72c1c5b stage1: remove keep-fd patch when built against systemd git master
Because of the last changes in systemd git master, our --keep-fd patch
is not needed anymore.
2015-05-20 15:17:01 +02:00
Iago López Galeiras 230dc1bc8c stage1: dlopen libsystemd instead of libsystemd-login
In systemd-209 libsystemd-login was merged into libsystemd and a
compatibility libsystemd-login library was created. Unfortunately,
distributions like Fedora don't ship the compatibility libraries so
runningFromUnitFile will always return false.

Fix it by dlopening libsystemd.so instead of libsystemd-login.so.
2015-05-18 11:23:58 +02:00
Jonathan Boulle d61a4c52d7 Merge pull request #878 from endocode/iaguis/keep-unit
stage1: use systemd-nspawn's --keep-unit
2015-05-07 17:33:41 -07:00
Iago López Galeiras 3cbfa313f9 stage1: use systemd-nspawn's --keep-unit
If we're running from a unit file, we pass --keep-unit to systemd-nspawn
to avoid being moved to a different cgroup.
2015-05-07 15:24:00 -07:00
Jonathan Boulle 4c64fa6e93 Merge pull request #861 from jonboulle/copyright
*: adjust copyright header + remove NOTICE
2015-05-07 14:38:45 -07:00
Jonathan Boulle 9685f37575 *: adjust copyright header
Inspired by a similar change in the Kubernetes project [1], this changes
the copyright header to the more generic "The rkt Authors" rather than
"CoreOS, Inc.", which is only sometimes correct.

https://github.com/GoogleCloudPlatform/kubernetes/commit/6b3a6e6b983f967c88d14d26542ec6e30c49ebd3
2015-05-03 14:29:15 -07:00
Yifan Gu 6a97d6f65e stage1/init: Use pod manifest to get forwarded ports
Instead of using image manifest to get forwarded ports, we should
use pod manifest.
2015-05-02 17:14:22 -07:00
Alban Crequy e3bd37dafa stage1: systemd: register only if systemd on the host supports it 2015-04-28 17:24:52 +02:00
Alban Crequy d0d2396079 diagexec: non-root apps 2015-04-24 10:47:58 +02:00
Jonathan Boulle 19fee5b4f4 Merge pull request #754 from klizhentas/master
stage1: pass arguments for keeping lock and writing PID
2015-04-17 11:14:24 -07:00
Alexander Klizhentas 2cdcd631d0 stage1: pass lock and PID args for stage1 "src" flavor. refs coreos/rkt#753 2015-04-15 14:40:17 -07:00
Eugene Yakubovich bf33546a2d net: stage1 gc will clean up networking 2015-04-14 17:03:03 -07:00
Eugene Yakubovich d86dc77ce8 Merge pull request #731 from eyakubovich/extra-log-lines
stage1: discard logger output if no --debug is present
2015-04-08 10:18:01 -07:00
Eugene Yakubovich 8a83cf9e87 Merge pull request #703 from eyakubovich/expose-ports
net: add option to expose ports on hosts
2015-04-07 10:50:27 -07:00
Jonathan Boulle 006e2c4b31 stage1: rename container{,_test}.go -> pod{,_test} 2015-04-06 15:21:58 -07:00
Jonathan Boulle ca3910dd21 stage1: set systemd-nspawn machine to pod UUID 2015-04-06 14:34:48 -07:00
Eugene Yakubovich e01d4f2e02 stage1: discard logger output if no --debug is present
Also cleans up log.SetOutput handling in stage0 to only
do it once in main based on --debug.

Fixes #709
2015-04-06 13:09:25 -07:00
Eugene Yakubovich dbc1f0f238 net: add option to expose ports on hosts
Ports that were defined in app manifest can be
exposed via --port=name:host-port option on cmd line.
For example, given app manifest with ports entry:
{
    "name": "http",
    "port": 80,
    "protocol": "tcp"
}

rkt run --private-net --port=http:8888 myapp.aci
will forward traffic from host's tcp port 8888 to
container's port 80.

Fixes #624
2015-04-03 17:24:02 -07:00
Jonathan Boulle 79753c9b19 *: rocket -> rkt 2015-03-31 16:31:21 -07:00
Jonathan Boulle 3fd0303076 *: global containers -> pods rename 2015-03-31 15:55:06 -07:00
Jonathan Boulle 19dae09039 Merge pull request #697 from vcaputo/defaultenv
stage1/init: set minimum appc-required environment defaults
2015-03-30 19:05:18 -07:00
Vito Caputo 95d056b6aa stage1/init: set minimum appc-required environment defaults
These are currently being set to static root values, will revisit once
the spec matures in this area.

Fixes #687
2015-03-30 17:04:39 -07:00