From 28add1a7096a305447cbcae28df2910585e7ce7c Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Wed, 6 Apr 2016 14:11:14 +0000 Subject: [PATCH] Task #8437: Remove bash from docker command line to make signal propagation easier --- .../lofarpipe/support/remotecommand.py | 30 ++++++++++++------- .../recipes/sip/pipeline.cfg.CEP4.tmpl | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CEP/Pipeline/framework/lofarpipe/support/remotecommand.py b/CEP/Pipeline/framework/lofarpipe/support/remotecommand.py index 7ac394c699e..4edf2d52a2c 100644 --- a/CEP/Pipeline/framework/lofarpipe/support/remotecommand.py +++ b/CEP/Pipeline/framework/lofarpipe/support/remotecommand.py @@ -196,7 +196,9 @@ def run_via_custom_cmdline(logger, host, command, environment, arguments, config with the following strings replaced: {host} := host to execute command on - {command} := bash command line to be executed + {env} := "A=B C=D" string, the environment to set + {docker_env} := "-e A=B -e C=D" string, the environment to set + {command} := command to be executed {uid} := uid of the calling user {slurm_job_id} := the SLURM job id to allocate resources in @@ -205,9 +207,17 @@ def run_via_custom_cmdline(logger, host, command, environment, arguments, config {nr_cores} := number of cores to allocate for this job """ - commandArray = ["%s=%s" % (key, value) for key, value in environment.items()] - commandArray.append(command) - commandArray.extend(re.escape(str(arg)) for arg in arguments) + + # construct {env} + envPairs = ["%s=%s" % (key, value) for key, value in environment.items()] + envStr = " ".join(envPairs) + + # construct {docker-env} + dockerEnvPairs = ["-e %s=%s" % (key, value) for key, value in environment.items()] + dockerEnvStr = " ".join(dockerEnvPairs) + + # construct {command} + commandArray = [command] + [re.escape(str(arg)) for arg in arguments] commandStr = " ".join(commandArray) # Determine job name @@ -219,20 +229,20 @@ def run_via_custom_cmdline(logger, host, command, environment, arguments, config return args[1] if args[0] == "python" else args[0] - # Construct the full command line, except for {command}, as that itself - # can contain spaces which we don't want to split on. + # Construct the full command line full_command_line = config.get('remote', 'cmdline').format( uid = os.geteuid(), slurm_job_id = os.environ.get("SLURM_JOB_ID"), host = host, - command = "{command}", + + env = envStr, + docker_env = dockerEnvStr, + + command = commandStr, job_name = jobname(command), nr_cores = resources.get("cores", 1), ).split(' ') - # Fill in {command} somewhere - full_command_line = [x.format(command = commandStr) for x in full_command_line] - logger.debug("Dispatching command to %s with custom_cmdline: %s" % (host, full_command_line)) process = spawn_process(full_command_line, logger) diff --git a/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl b/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl index 6c1c35a244a..473eb91eeaf 100644 --- a/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl +++ b/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl @@ -67,4 +67,4 @@ globalfs = yes # /bin/bash -c # # Required because the pipeline framework needs some bash functionality in the commands it starts. -cmdline = ssh -n -tt -x localhost srun --exclusive --ntasks=1 --cpus-per-task={nr_cores} --jobid={slurm_job_id} --job-name={job_name} docker run --rm -e LUSER={uid} -v /data:/data --net=host lofar-pipeline:${LOFAR_TAG} /bin/bash -c "\"{command}\"" +cmdline = ssh -n -tt -x localhost srun --exclusive --ntasks=1 --cpus-per-task={nr_cores} --jobid={slurm_job_id} --job-name={job_name} docker run --rm -e LUSER={uid} -v /data:/data --net=host lofar-pipeline:${LOFAR_TAG} {docker-env} {command} -- GitLab