From 945a49d3bc1b0ce9adb33e6aa2ee76487a12549b Mon Sep 17 00:00:00 2001 From: Anurag Priyam Date: Tue, 13 Jan 2015 15:19:47 +0530 Subject: [PATCH] Ensure access to tty within container (close #3). And return exit value of command if invoked as `switch biolinux blastp ...`. Signed-off-by: Anurag Priyam --- Dockerfiles/baseimage/_init | 11 ++++++----- lib/switch.rb | 11 +++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Dockerfiles/baseimage/_init b/Dockerfiles/baseimage/_init index af74292..f6baf13 100755 --- a/Dockerfiles/baseimage/_init +++ b/Dockerfiles/baseimage/_init @@ -14,8 +14,9 @@ if [ $? -ne 0 ]; then passwd -d $user &> /dev/null fi -if [ $# -eq 0 ]; then - su -l $user -s $shell -c "[ -d $cwd ] && cd $cwd; exec $shell" -else - su -l $user -s $shell -c "[ -d $cwd ] && cd $cwd; $*" -fi +exec sudo -u $user -i exec $shell -c \ +" + [ -d $cwd ] && cd $cwd; + [ $# -gt 0 ] && exec $*; + exec $shell; +" diff --git a/lib/switch.rb b/lib/switch.rb index 4359153..e4d9558 100644 --- a/lib/switch.rb +++ b/lib/switch.rb @@ -31,7 +31,7 @@ def to_s include Timeout - # Captures a docker image. + # Captures a docker image's metadata. Image = Struct.new :repository, :tag, :id, :created, :size class Image @@ -147,9 +147,7 @@ def initialize(package, command = []) # images on the user's system. It must be noted though that other program # may use the same prefix, and thus our images aren't truly isolated. @imgname = "switch/#{@package.gsub('_', ':')}" - # We don't give up the pid untill docker completes. Thus appending pid to - # the package name gurantees us a unique container name. If we were using - # exec or fork, we would have to worry about pids being recycled. + @cntname = "#@package-#{Process.pid}" exec @@ -157,9 +155,6 @@ def initialize(package, command = []) attr_reader :package, :command, :imgname, :cntname - # NOTE: - # Doesn't really exec. Our ruby proecess waits till docker process started - # has been terminated. def exec ping and build and switch rescue ENODKR, ENOPKG => e @@ -172,7 +167,7 @@ def exec def switch cmdline = "docker run --name #{cntname} --hostname #{cntname} -it --rm=true" \ " #{mountargs} #{imgname} #{userargs} #{command}" - system cmdline + Kernel.exec cmdline end def build