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:32:19 UTC
[26/50] 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/3a055801
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3a055801
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3a055801
Branch: refs/heads/0.26.x
Commit: 3a0558014db707825df4e1a6192cb04c260ce35e
Parents: 1d07486
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Fri Feb 5 10:32:48 2016 -0500
Committer: Michael Park <mp...@apache.org>
Committed: Fri Feb 26 20:59:06 2016 -0800
----------------------------------------------------------------------
src/linux/systemd.cpp | 26 +++++++++++++++++++-
src/slave/containerizer/linux_launcher.cpp | 32 +++++++------------------
2 files changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3a055801/src/linux/systemd.cpp
----------------------------------------------------------------------
diff --git a/src/linux/systemd.cpp b/src/linux/systemd.cpp
index 9f484f8..bcd3bda 100644
--- a/src/linux/systemd.cpp
+++ b/src/linux/systemd.cpp
@@ -66,7 +66,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/3a055801/src/slave/containerizer/linux_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/linux_launcher.cpp b/src/slave/containerizer/linux_launcher.cpp
index 508ca2e..35f8db2 100644
--- a/src/slave/containerizer/linux_launcher.cpp
+++ b/src/slave/containerizer/linux_launcher.cpp
@@ -306,6 +306,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,
@@ -316,8 +323,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());
@@ -344,28 +350,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;