From 18124ca1c2e0575404519d8b854d78187ad7bc43 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 27 Jun 2015 04:01:36 +0000 Subject: emulate sd_listen_fds for systemd support systemd socket emulation shares FDs across execve, just like the built-in SIGUSR2 upgrade process in unicorn. Thus it is easy to support inheriting sockets from systemd. Tested-by: Christos Trochalakis --- test/exec/test_exec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb index 6deb96b..af8de26 100644 --- a/test/exec/test_exec.rb +++ b/test/exec/test_exec.rb @@ -96,6 +96,30 @@ run lambda { |env| end end + def test_sd_listen_fds_emulation + File.open("config.ru", "wb") { |fp| fp.write(HI) } + sock = TCPServer.new(@addr, @port) + sock.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, 0) + + pid = xfork do + redirect_test_io do + # pretend to be systemd + ENV['LISTEN_PID'] = "#$$" + ENV['LISTEN_FDS'] = '1' + + # 3 = SD_LISTEN_FDS_START + exec($unicorn_bin, "-l", "#@addr:#@port", 3 => sock) + end + end + res = hit(["http://#{@addr}:#{@port}/"]) + assert_equal [ "HI\n"], res + assert_shutdown(pid) + assert_equal 1, sock.getsockopt(:SOL_SOCKET, :SO_KEEPALIVE).int, + "unicorn should always set SO_KEEPALIVE on inherited sockets" + ensure + sock.close if sock + end + def test_working_directory_rel_path_config_file other = Tempfile.new('unicorn.wd') File.unlink(other.path) -- cgit v1.2.3-24-ge0c7