feat: handle interrupt signal

This commit is contained in:
Glenn Y. Rolland 2023-01-20 09:21:09 +01:00
parent d3982daed1
commit 6b15ee0684

View file

@ -55,15 +55,17 @@ puts "docker_image = #{docker_image}"
puts "action = #{action}" puts "action = #{action}"
docker_name = "docmachine-#{basehash}" docker_name = "docmachine-#{basehash}"
docker_cid = %x{docker ps -f "name=#{docker_name} -q)}.strip docker_cid = %x{docker ps -f "name=#{docker_name}" -q}.strip
uid = %x{id -u}.strip uid = %x{id -u}.strip
gid = %x{id -g}.strip gid = %x{id -g}.strip
puts "uid: #{uid}"
puts "cid: #{gid}"
puts "docker_name: #{docker_name}" puts "docker_name: #{docker_name}"
puts "docker_cid: #{docker_cid}" puts "docker_cid: #{docker_cid}"
if !docker_cid.empty? if !docker_cid.empty?
Process.run("docker", ["kill", docker_cid]) Process.run("docker", ["kill", docker_name])
end end
docker_opts << "run" docker_opts << "run"
@ -127,5 +129,12 @@ docker_opts << docker_image
docker_opts << action docker_opts << action
puts docker_opts.inspect.colorize(:yellow) puts docker_opts.inspect.colorize(:yellow)
process = Process.run("docker", docker_opts, output: STDOUT, error: STDERR) process = Process.new("docker", docker_opts, output: STDOUT, error: STDERR)
Signal::INT.trap do
STDERR.puts "Received CTRL-C"
process.signal(Signal::KILL)
Process.run("docker", ["kill", docker_name])
end
process.wait