You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/02/05 19:27:37 UTC
[1/2] mesos git commit: Added working dir flag to mesos containerizer
launch.
Repository: mesos
Updated Branches:
refs/heads/master 889d7e173 -> d27776d42
Added working dir flag to mesos containerizer launch.
Review: https://reviews.apache.org/r/43167/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e4e1e28b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e4e1e28b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e4e1e28b
Branch: refs/heads/master
Commit: e4e1e28bcae5297436efd526b27e27bf4c80075d
Parents: 889d7e1
Author: Gilbert Song <so...@gmail.com>
Authored: Fri Feb 5 09:38:35 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Feb 5 09:38:35 2016 -0800
----------------------------------------------------------------------
src/slave/containerizer/mesos/launch.cpp | 22 +++++++++++++++++-----
src/slave/containerizer/mesos/launch.hpp | 1 +
2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e4e1e28b/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index 23970a2..6b3bf16 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -53,9 +53,14 @@ MesosContainerizerLaunch::Flags::Flags()
add(&sandbox,
"sandbox",
- "The sandbox to chdir to. If rootfs is specified this must\n"
+ "The sandbox for the executor. If rootfs is specified this must\n"
"be relative to the new root.");
+ add(&working_directory,
+ "working_directory",
+ "The working directory for the executor. It will be ignored if\n"
+ "container root filesystem is not specified.");
+
add(&rootfs,
"rootfs",
"Absolute path to the container root filesystem.\n"
@@ -249,11 +254,18 @@ int MesosContainerizerLaunch::execute()
}
}
- // Enter sandbox directory, relative to the new root.
- Try<Nothing> chdir = os::chdir(flags.sandbox.get());
+ // Determine the current working directory for the executor.
+ string cwd;
+ if (flags.rootfs.isSome() && flags.working_directory.isSome()) {
+ cwd = flags.working_directory.get();
+ } else {
+ cwd = flags.sandbox.get();
+ }
+
+ Try<Nothing> chdir = os::chdir(cwd);
if (chdir.isError()) {
- cerr << "Failed to chdir into sandbox directory '"
- << flags.sandbox.get() << "': " << chdir.error() << endl;
+ cerr << "Failed to chdir into current working directory '"
+ << cwd << "': " << chdir.error() << endl;
return 1;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/e4e1e28b/src/slave/containerizer/mesos/launch.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.hpp b/src/slave/containerizer/mesos/launch.hpp
index 78d6b9d..7e29ca2 100644
--- a/src/slave/containerizer/mesos/launch.hpp
+++ b/src/slave/containerizer/mesos/launch.hpp
@@ -36,6 +36,7 @@ public:
Option<JSON::Object> command;
Option<std::string> sandbox;
+ Option<std::string> working_directory;
Option<std::string> rootfs;
Option<std::string> user;
Option<int> pipe_read;
[2/2] mesos git commit: Added working dir flag to command executor.
Posted by ji...@apache.org.
Added working dir flag to command executor.
Review: https://reviews.apache.org/r/43168/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d27776d4
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d27776d4
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d27776d4
Branch: refs/heads/master
Commit: d27776d427007ac61a9107ed8d04cd429fc636db
Parents: e4e1e28
Author: Gilbert Song <so...@gmail.com>
Authored: Fri Feb 5 09:40:18 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Feb 5 10:25:38 2016 -0800
----------------------------------------------------------------------
src/launcher/executor.cpp | 43 ++++++++++++++++++++++++++++++++++--------
1 file changed, 35 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/d27776d4/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index b214a3f..41ce439 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -82,6 +82,7 @@ public:
const Option<char**>& override,
const string& _healthCheckDir,
const Option<string>& _sandboxDirectory,
+ const Option<string>& _workingDirectory,
const Option<string>& _user,
const Option<string>& _taskCommand)
: state(REGISTERING),
@@ -95,6 +96,7 @@ public:
healthCheckDir(_healthCheckDir),
override(override),
sandboxDirectory(_sandboxDirectory),
+ workingDirectory(_workingDirectory),
user(_user),
taskCommand(_taskCommand) {}
@@ -213,9 +215,12 @@ public:
// If 'sandbox_diretory' is specified, that means the user
// task specifies a root filesystem, and that root filesystem has
// already been prepared at COMMAND_EXECUTOR_ROOTFS_CONTAINER_PATH.
- // The command executor is reponsible for mounting the sandbox
+ // The command executor is responsible for mounting the sandbox
// into the root filesystem, chrooting into it and changing the
// user before exec-ing the user process.
+ //
+ // TODO(gilbert): Consider a better way to detect if a root
+ // filesystem is specified for the command task.
#ifdef __linux__
Result<string> user = os::user();
if (user.isError()) {
@@ -345,10 +350,19 @@ public:
abort();
}
- Try<Nothing> chdir = os::chdir(sandboxDirectory.get());
+ // Determine the current working directory for the executor.
+ string cwd;
+ if (workingDirectory.isSome()) {
+ cwd = workingDirectory.get();
+ } else {
+ CHECK_SOME(sandboxDirectory);
+ cwd = sandboxDirectory.get();
+ }
+
+ Try<Nothing> chdir = os::chdir(cwd);
if (chdir.isError()) {
- cerr << "Failed to change directory to sandbox dir '"
- << sandboxDirectory.get() << "': " << chdir.error();
+ cerr << "Failed to chdir into current working directory '"
+ << cwd << "': " << chdir.error() << endl;
abort();
}
@@ -646,6 +660,7 @@ private:
string healthCheckDir;
Option<char**> override;
Option<string> sandboxDirectory;
+ Option<string> workingDirectory;
Option<string> user;
Option<string> taskCommand;
};
@@ -658,11 +673,17 @@ public:
const Option<char**>& override,
const string& healthCheckDir,
const Option<string>& sandboxDirectory,
+ const Option<string>& workingDirectory,
const Option<string>& user,
const Option<string>& taskCommand)
{
- process = new CommandExecutorProcess(
- override, healthCheckDir, sandboxDirectory, user, taskCommand);
+ process = new CommandExecutorProcess(override,
+ healthCheckDir,
+ sandboxDirectory,
+ workingDirectory,
+ user,
+ taskCommand);
+
spawn(process);
}
@@ -750,13 +771,17 @@ public:
"subsequent 'argv' to be used with 'execvp'",
false);
- // The following flags are only applicable when a rootfs is provisioned
- // for this command.
+ // The following flags are only applicable when a rootfs is
+ // provisioned for this command.
add(&sandbox_directory,
"sandbox_directory",
"The absolute path for the directory in the container where the\n"
"sandbox is mapped to");
+ add(&working_directory,
+ "working_directory",
+ "The working directory for the task in the container.");
+
add(&user,
"user",
"The user that the task should be running as.");
@@ -772,6 +797,7 @@ public:
bool override;
Option<string> sandbox_directory;
+ Option<string> working_directory;
Option<string> user;
Option<string> task_command;
};
@@ -816,6 +842,7 @@ int main(int argc, char** argv)
override,
path,
flags.sandbox_directory,
+ flags.working_directory,
flags.user,
flags.task_command);