Skip to content

Commit 7236f83

Browse files
committed
Fix Orphaned processes when using Singularity
Signed-off-by: Paolo Di Tommaso <[email protected]>
1 parent fb71767 commit 7236f83

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

modules/nextflow/src/main/groovy/nextflow/container/ContainerBuilder.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package nextflow.container
1919

2020
import java.nio.file.Path
2121

22+
import nextflow.executor.BashWrapperBuilder
2223
import nextflow.util.Escape
2324
import nextflow.util.MemoryUnit
2425
import nextflow.util.PathTrie
@@ -160,7 +161,7 @@ abstract class ContainerBuilder<V extends ContainerBuilder> {
160161
return run + ' ' + launcher
161162
}
162163

163-
String getKillCommand() { return '[[ "$pid" ]] && kill $pid 2>/dev/null' }
164+
String getKillCommand() { BashWrapperBuilder.KILL_CMD }
164165

165166
String getRemoveCommand() { return null }
166167

modules/nextflow/src/test/groovy/nextflow/container/UdockerBuilderTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class UdockerBuilderTest extends Specification {
115115
.stripIndent().trim()
116116

117117
builder.getRemoveCommand() == null
118-
builder.getKillCommand() == '[[ "$pid" ]] && kill $pid 2>/dev/null'
118+
builder.getKillCommand() == '[[ "$pid" ]] && nxf_kill $pid'
119119
}
120120

121121
def 'should append the run command line with launcher' () {
@@ -132,7 +132,7 @@ class UdockerBuilderTest extends Specification {
132132
.stripIndent().trim()
133133

134134
builder.getRemoveCommand() == null
135-
builder.getKillCommand() == '[[ "$pid" ]] && kill $pid 2>/dev/null'
135+
builder.getKillCommand() == '[[ "$pid" ]] && nxf_kill $pid'
136136

137137

138138
when:
@@ -147,7 +147,7 @@ class UdockerBuilderTest extends Specification {
147147
.stripIndent().trim()
148148

149149
builder.getRemoveCommand() == null
150-
builder.getKillCommand() == '[[ "$pid" ]] && kill $pid 2>/dev/null'
150+
builder.getKillCommand() == '[[ "$pid" ]] && nxf_kill $pid'
151151
}
152152

153153
}

modules/nextflow/src/test/groovy/nextflow/executor/BashWrapperBuilderTest.groovy

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ class BashWrapperBuilderTest extends Specification {
480480
binding.task_env == 'export FOO="aa"\nexport BAR="bb"\n'
481481
binding.container_env == null
482482
!binding.launch_cmd.contains('nxf_container_env')
483+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
483484
}
484485

485486
def 'should create secret env' () {
@@ -839,7 +840,7 @@ class BashWrapperBuilderTest extends Specification {
839840
sarus run --mount=type=bind,source=/work/dir,destination=/work/dir -w "$PWD" busybox /bin/bash -ue /work/dir/.command.sh
840841
'''.stripIndent().rightTrim()
841842
binding.cleanup_cmd == ""
842-
binding.kill_cmd == '[[ "$pid" ]] && kill $pid 2>/dev/null'
843+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
843844
}
844845

845846
def 'should create wrapper with sarus and environment'() {
@@ -856,7 +857,7 @@ class BashWrapperBuilderTest extends Specification {
856857
sarus run --mount=type=bind,source=/work/dir,destination=/work/dir -w "$PWD" busybox /bin/bash -c "eval $(nxf_container_env); /bin/bash -ue /work/dir/.command.sh"
857858
'''.stripIndent().rightTrim()
858859
binding.cleanup_cmd == ""
859-
binding.kill_cmd == '[[ "$pid" ]] && kill $pid 2>/dev/null'
860+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
860861
and:
861862
binding.container_env == '''\
862863
nxf_container_env() {
@@ -881,7 +882,7 @@ class BashWrapperBuilderTest extends Specification {
881882
sarus run --mount=type=bind,source=/folder\\ with\\ blanks,destination=/folder\\ with\\ blanks --mount=type=bind,source=/work/dir,destination=/work/dir -w "$PWD" busybox /bin/bash -ue /work/dir/.command.sh
882883
'''.stripIndent().rightTrim()
883884
binding.cleanup_cmd == ""
884-
binding.kill_cmd == '[[ "$pid" ]] && kill $pid 2>/dev/null'
885+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
885886
}
886887

887888
def 'should create wrapper with sarus container custom options'() {
@@ -898,7 +899,7 @@ class BashWrapperBuilderTest extends Specification {
898899
sarus run --mount=type=bind,source=/work/dir,destination=/work/dir -w "$PWD" --mount=type=bind,source=/foo,destination=/bar busybox /bin/bash -ue /work/dir/.command.sh
899900
'''.stripIndent().rightTrim()
900901
binding.cleanup_cmd == ""
901-
binding.kill_cmd == '[[ "$pid" ]] && kill $pid 2>/dev/null'
902+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
902903
}
903904

904905
def 'should create wrapper with shifter'() {
@@ -921,7 +922,7 @@ class BashWrapperBuilderTest extends Specification {
921922
shifter --image docker://ubuntu:latest /bin/bash -c "eval $(nxf_container_env); /bin/bash -ue /work/dir/.command.sh"
922923
'''.stripIndent().rightTrim()
923924
binding.cleanup_cmd == ""
924-
binding.kill_cmd == '[[ "$pid" ]] && kill $pid 2>/dev/null'
925+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
925926

926927
}
927928

@@ -936,7 +937,7 @@ class BashWrapperBuilderTest extends Specification {
936937
then:
937938
binding.launch_cmd == 'set +u; env - PATH="$PATH" ${TMP:+SINGULARITYENV_TMP="$TMP"} ${TMPDIR:+SINGULARITYENV_TMPDIR="$TMPDIR"} singularity exec docker://ubuntu:latest /bin/bash -c "cd $PWD; eval $(nxf_container_env); /bin/bash -ue /work/dir/.command.sh"'
938939
binding.cleanup_cmd == ""
939-
binding.kill_cmd == '[[ "$pid" ]] && kill $pid 2>/dev/null'
940+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
940941
}
941942

942943
def 'should create wrapper with singularity legacy entry'() {
@@ -950,7 +951,7 @@ class BashWrapperBuilderTest extends Specification {
950951
then:
951952
binding.launch_cmd == 'set +u; env - PATH="$PATH" ${TMP:+SINGULARITYENV_TMP="$TMP"} ${TMPDIR:+SINGULARITYENV_TMPDIR="$TMPDIR"} singularity exec docker://ubuntu:latest /bin/bash -c "cd $PWD; eval $(nxf_container_env); /bin/bash -ue /work/dir/.command.sh"'
952953
binding.cleanup_cmd == ""
953-
binding.kill_cmd == '[[ "$pid" ]] && kill $pid 2>/dev/null'
954+
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
954955
}
955956

956957
def 'should create task and container env' () {

0 commit comments

Comments
 (0)