Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for custom switch user commands in SingularityExecutor #705

Merged
merged 2 commits into from
Oct 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ public class SingularityExecutorConfiguration extends BaseRunnerConfiguration {
@JsonProperty
private String procCgroupFormat = "/proc/%s/cgroup";

@NotEmpty
@JsonProperty
private String switchUserCommandFormat = "sudo -E -u %s";

@JsonProperty
@NotEmpty
private List<String> artifactSignatureVerificationCommand = Arrays.asList("/usr/bin/gpg", "--verify", "{artifactSignaturePath}");
Expand Down Expand Up @@ -528,6 +532,14 @@ public void setProcCgroupFormat(String procCgroupFormat) {
this.procCgroupFormat = procCgroupFormat;
}

public String getSwitchUserCommandFormat() {
return switchUserCommandFormat;
}

public void setSwitchUserCommandFormat(String switchUserCommandFormat) {
this.switchUserCommandFormat = switchUserCommandFormat;
}

public List<String> getArtifactSignatureVerificationCommand() {
return artifactSignatureVerificationCommand;
}
Expand Down Expand Up @@ -587,8 +599,14 @@ public String toString() {
", useLocalDownloadService=" + useLocalDownloadService +
", localDownloadServiceTimeoutMillis=" + localDownloadServiceTimeoutMillis +
", maxTaskThreads=" + maxTaskThreads +
", dockerPrefix=" + dockerPrefix +
", dockerPrefix='" + dockerPrefix + '\'' +
", dockerStopTimeout=" + dockerStopTimeout +
", cgroupsMesosCpuTasksFormat='" + cgroupsMesosCpuTasksFormat + '\'' +
", procCgroupFormat='" + procCgroupFormat + '\'' +
", switchUserCommandFormat='" + switchUserCommandFormat + '\'' +
", artifactSignatureVerificationCommand=" + artifactSignatureVerificationCommand +
", failTaskOnInvalidArtifactSignature=" + failTaskOnInvalidArtifactSignature +
", signatureVerifyOut='" + signatureVerifyOut + '\'' +
']';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class RunnerContext {
private final Optional<Integer> maxTaskThreads;
private final boolean shouldChangeUser;
private final Integer maxOpenFiles;
private final String switchUserCommand;

public RunnerContext(String cmd, String taskAppDirectory, String logDir, String user, String logFile, String taskId, Optional<Integer> maxTaskThreads, boolean shouldChangeUser, Integer maxOpenFiles) {
public RunnerContext(String cmd, String taskAppDirectory, String logDir, String user, String logFile, String taskId, Optional<Integer> maxTaskThreads, boolean shouldChangeUser, Integer maxOpenFiles, String switchUserCommand) {
this.cmd = cmd;
this.taskAppDirectory = taskAppDirectory;
this.logDir = logDir;
Expand All @@ -29,6 +30,7 @@ public RunnerContext(String cmd, String taskAppDirectory, String logDir, String
this.maxTaskThreads = maxTaskThreads;
this.shouldChangeUser = shouldChangeUser;
this.maxOpenFiles = maxOpenFiles;
this.switchUserCommand = switchUserCommand;
}

public String getCmd() {
Expand Down Expand Up @@ -67,6 +69,10 @@ public Integer getMaxOpenFiles() {
return maxOpenFiles;
}

public String getSwitchUserCommand() {
return switchUserCommand;
}

@Override
public String toString() {
return "RunnerContext[" +
Expand All @@ -78,6 +84,7 @@ public String toString() {
", taskId='" + taskId + '\'' +
", maxTaskThreads=" + maxTaskThreads +
", shouldChangeUser=" + shouldChangeUser +
", switchUserCommand=" + switchUserCommand +
']';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private ProcessBuilder buildProcessBuilder(TaskInfo taskInfo, ExecutorData execu
task.getTaskId(),
executorData.getMaxTaskThreads().or(configuration.getMaxTaskThreads()),
!getExecutorUser().equals(executorData.getUser().or(configuration.getDefaultRunAsUser())),
executorData.getMaxOpenFiles().orNull());
executorData.getMaxOpenFiles().orNull(),
String.format(configuration.getSwitchUserCommandFormat(), executorData.getUser().or(configuration.getDefaultRunAsUser())));
EnvironmentContext environmentContext = new EnvironmentContext(taskInfo);
if (taskInfo.hasContainer() && taskInfo.getContainer().hasDocker()) {
task.getLog().info("Writing a runner script to execute {} in docker container", cmd);
Expand Down
4 changes: 2 additions & 2 deletions SingularityExecutor/src/main/resources/runner.sh.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ fi

# execute command
{{#if shouldChangeUser}}
echo "Executing: sudo -E -u {{{ user }}} {{#if maxOpenFiles}}/bin/bash -c 'ulimit -n {{{maxOpenFiles}}} && {{/if}}{{{ cmd }}}{{#if maxOpenFiles}}'{{/if}} >> ../{{{ logFile }}} 2>&1"
exec sudo -E -u {{{ user }}} {{#if maxOpenFiles}}/bin/bash -c 'ulimit -n {{{maxOpenFiles}}} && {{/if}}{{{ cmd }}}{{#if maxOpenFiles}}'{{/if}} >> ../{{{ logFile }}} 2>&1
echo "Executing: {{{ switchUserCommand }}} {{#if maxOpenFiles}}/bin/bash -c 'ulimit -n {{{maxOpenFiles}}} && {{/if}}{{{ cmd }}}{{#if maxOpenFiles}}'{{/if}} >> ../{{{ logFile }}} 2>&1"
exec {{{ switchUserCommand }}} {{#if maxOpenFiles}}/bin/bash -c 'ulimit -n {{{maxOpenFiles}}} && {{/if}}{{{ cmd }}}{{#if maxOpenFiles}}'{{/if}} >> ../{{{ logFile }}} 2>&1
{{else}}
echo "Executing: {{{ cmd }}} >> ../{{{ logFile }}} 2>&1"
{{#if maxOpenFiles}}ulimit -n {{{maxOpenFiles}}}{{/if}}
Expand Down