You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/04/25 23:36:18 UTC
[37/48] mesos git commit: Migrated linux launcher systemd executor
logic into subprocess hook.
Migrated linux launcher systemd executor logic into subprocess hook.
Review: https://reviews.apache.org/r/43306
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e83e63ad
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e83e63ad
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e83e63ad
Branch: refs/heads/0.27.x
Commit: e83e63adcade67d3aad97986cac575c259976947
Parents: bf6f190
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Fri Feb 5 10:32:48 2016 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Tue Feb 16 18:21:10 2016 -0500
----------------------------------------------------------------------
src/linux/systemd.cpp | 26 +++++++++++++++-
.../containerizer/mesos/linux_launcher.cpp | 32 +++++---------------
2 files changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e83e63ad/src/linux/systemd.cpp
----------------------------------------------------------------------
diff --git a/src/linux/systemd.cpp b/src/linux/systemd.cpp
index 69e8b39..0142caf 100644
--- a/src/linux/systemd.cpp
+++ b/src/linux/systemd.cpp
@@ -64,7 +64,31 @@ namespace mesos {
Try<Nothing> extendLifetime(pid_t child)
{
- // TODO(jmlvanre): Implement pid migration into systemd slice.
+ if (!systemd::exists()) {
+ return Error("systemd does not exist on this system");
+ }
+
+ if (!systemd::enabled()) {
+ return Error("systemd is not enabled on this system");
+ }
+
+ Try<Nothing> assign = cgroups::assign(
+ hierarchy(),
+ systemd::mesos::MESOS_EXECUTORS_SLICE,
+ child);
+
+ if (assign.isError()) {
+ LOG(ERROR) << "Failed to assign process " << child
+ << " to its systemd executor slice: " << assign.error();
+
+ ::kill(child, SIGKILL);
+ return Error("Failed to contain process on systemd");
+ }
+
+ LOG(INFO) << "Assigned child process '" << child << "' to '"
+ << systemd::mesos::MESOS_EXECUTORS_SLICE << "'";
+
+ return Nothing();
}
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/e83e63ad/src/slave/containerizer/mesos/linux_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.cpp b/src/slave/containerizer/mesos/linux_launcher.cpp
index 90f8c73..a5546c7 100644
--- a/src/slave/containerizer/mesos/linux_launcher.cpp
+++ b/src/slave/containerizer/mesos/linux_launcher.cpp
@@ -304,6 +304,13 @@ Try<pid_t> LinuxLauncher::fork(
LOG(INFO) << "Cloning child process with flags = "
<< ns::stringify(cloneFlags);
+ // If we are on systemd, then extend the life of the child. As with the
+ // freezer, any grandchildren will also be contained in the slice.
+ std::vector<Subprocess::Hook> parentHooks;
+ if (systemdHierarchy.isSome()) {
+ parentHooks.emplace_back(Subprocess::Hook(&systemd::mesos::extendLifetime));
+ }
+
Try<Subprocess> child = subprocess(
path,
argv,
@@ -314,8 +321,7 @@ Try<pid_t> LinuxLauncher::fork(
environment,
lambda::bind(&childSetup, pipes, setup),
lambda::bind(&os::clone, lambda::_1, cloneFlags),
- // TODO(jmlvanre): Use systemd hook.
- Subprocess::Hook::None());
+ parentHooks);
if (child.isError()) {
return Error("Failed to clone child process: " + child.error());
@@ -342,28 +348,6 @@ Try<pid_t> LinuxLauncher::fork(
return Error("Failed to contain process");
}
- // If we are on systemd, then move the child into the
- // `MESOS_EXECUTORS_SLICE`. As with the freezer, any grandchildren will also
- // be contained in the slice.
- if (systemdHierarchy.isSome()) {
- Try<Nothing> assign = cgroups::assign(
- systemdHierarchy.get(),
- systemd::mesos::MESOS_EXECUTORS_SLICE,
- child.get().pid());
-
- if (assign.isError()) {
- LOG(ERROR) << "Failed to assign process " << child.get().pid()
- << " of container '" << containerId << "'"
- << " to its systemd executor slice: " << assign.error();
-
- ::kill(child.get().pid(), SIGKILL);
- return Error("Failed to contain process on systemd");
- }
-
- LOG(INFO) << "Assigned child process '" << child.get().pid() << "' to '"
- << systemd::mesos::MESOS_EXECUTORS_SLICE << "'";
- }
-
// Now that we've contained the child we can signal it to continue
// by writing to the pipe.
char dummy;