Skip to content

Commit

Permalink
After Passenger Standalone downloads binaries, check whether they're …
Browse files Browse the repository at this point in the history
…usable
  • Loading branch information
FooBarWidget committed Aug 14, 2013
1 parent 724102f commit cfdc419
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
6 changes: 6 additions & 0 deletions ext/common/agents/HelperAgent/AgentOptions.h
Expand Up @@ -56,11 +56,17 @@ struct AgentOptions {
string adminToolStatusPassword;
vector<string> prestartUrls;

bool testBinary;
string requestSocketLink;

AgentOptions() { }

AgentOptions(const VariantMap &options) {
testBinary = options.get("test_binary", false) == "1";
if (testBinary) {
return;
}

// Required options for which a default is already set by the Watchdog.
passengerRoot = options.get("passenger_root");
tempDir = options.get("temp_dir");
Expand Down
5 changes: 5 additions & 0 deletions ext/common/agents/HelperAgent/Main.cpp
Expand Up @@ -587,6 +587,11 @@ int
main(int argc, char *argv[]) {
TRACE_POINT();
AgentOptions options(initializeAgent(argc, argv, "PassengerHelperAgent"));
if (options.testBinary) {
printf("PASS\n");
exit(0);
}

P_DEBUG("Starting PassengerHelperAgent...");
MultiLibeio::init();

Expand Down
4 changes: 4 additions & 0 deletions ext/common/agents/LoggingAgent/Main.cpp
Expand Up @@ -126,6 +126,10 @@ static void
initializeBareEssentials(int argc, char *argv[]) {
agentsOptions = initializeAgent(argc, argv, "PassengerLoggingAgent");
curl_global_init(CURL_GLOBAL_ALL);
if (agentsOptions.get("test_binary", false) == "1") {
printf("PASS\n");
exit(0);
}
}

static string
Expand Down
5 changes: 5 additions & 0 deletions ext/common/agents/Watchdog/Main.cpp
Expand Up @@ -413,6 +413,11 @@ initializeBareEssentials(int argc, char *argv[]) {
oldOomScore = setOomScoreNeverKill();

agentsOptions = initializeAgent(argc, argv, "PassengerWatchdog");

if (agentsOptions.get("test_binary", false) == "1") {
printf("PASS\n");
exit(0);
}
}

static void
Expand Down
27 changes: 25 additions & 2 deletions lib/phusion_passenger/standalone/runtime_installer.rb
Expand Up @@ -243,7 +243,19 @@ def download_support_binaries
FileUtils.mkdir_p(@support_dir)
Dir.chdir(@support_dir) do
puts "Extracting tarball..."
return extract_tarball(tarball)
result = extract_tarball(tarball)
return nil if !result

puts "Checking whether the downloaded binary is usable..."
["PassengerWatchdog", "PassengerHelperAgent", "PassengerLoggingAgent"].each do |exe|
output = `env LD_BIND_NOW=1 DYLD_BIND_AT_LAUNCH=1 ./agents/#{exe} --binary-test 1`
if !$? || $?.exitstatus != 0 || output != "PASS\n"
puts "Binary #{exe} is not usable."
return nil
end
end
puts "Binary is usable."
return result
end
rescue Interrupt
exit 2
Expand All @@ -266,7 +278,18 @@ def download_nginx_binary
FileUtils.mkdir_p(@nginx_dir)
Dir.chdir(@nginx_dir) do
puts "Extracting tarball..."
return extract_tarball(tarball)
result = extract_tarball(tarball)
return nil if !result

puts "Checking whether the downloaded binary is usable..."
output = `env LD_BIND_NOW=1 DYLD_BIND_AT_LAUNCH=1 ./nginx -h`
if $? && $?.exitstatus == 0 && output =~ /nginx version:/
puts "Binary is usable."
return result
else
puts "Binary is not usable."
return nil
end
end
rescue Interrupt
exit 2
Expand Down
43 changes: 35 additions & 8 deletions test/ruby/standalone/runtime_installer_spec.rb
Expand Up @@ -52,6 +52,25 @@ def create_tarball(filename, contents = nil)
end
end

def create_dummy_support_binaries
Dir.mkdir("agents")
["PassengerWatchdog", "PassengerHelperAgent", "PassengerLoggingAgent"].each do |exe|
File.open("agents/#{exe}", "w") do |f|
f.puts "#!/bin/bash"
f.puts "echo PASS"
end
File.chmod(0755, "agents/#{exe}")
end
end

def create_dummy_nginx_binary
File.open("nginx", "w") do |f|
f.puts "#!/bin/bash"
f.puts "echo nginx version: 1.0.0"
end
File.chmod(0755, "nginx")
end

def create_file(filename)
File.open(filename, "w").close
end
Expand All @@ -71,7 +90,9 @@ def test_download_nginx_binary
and_return do |url, output, options|
url.should == nginx_binary_url
options[:use_cache].should be_true
create_tarball(output, ["nginx.txt"])
create_tarball(output) do
create_dummy_nginx_binary
end
true
end

Expand All @@ -82,7 +103,7 @@ def test_download_nginx_binary
@installer.should_not_receive(:compile_nginx)
@installer.run

File.exist?("#{@temp_dir}/nginx/nginx.txt").should be_true
File.exist?("#{@temp_dir}/nginx/nginx").should be_true
end

def test_building_nginx_binary
Expand Down Expand Up @@ -139,7 +160,9 @@ def test_building_nginx_binary
and_return do |url, output, options|
url.should == "#{binaries_url_root}/#{version}/support-#{cxx_compat_id}.tar.gz"
options[:use_cache].should be_true
create_tarball(output, ["support.txt"])
create_tarball(output) do
create_dummy_support_binaries
end
true
end

Expand All @@ -150,7 +173,7 @@ def test_building_nginx_binary
@installer.should_not_receive(:compile_nginx)
@installer.run

File.exist?("#{@temp_dir}/support/support.txt").should be_true
File.exist?("#{@temp_dir}/support/agents/PassengerWatchdog").should be_true
end

it "downloads the Nginx binary from the Internet if :nginx is specified as target" do
Expand All @@ -167,9 +190,13 @@ def test_building_nginx_binary
twice.
and_return do |url, output, options|
if url == support_binaries_url
create_tarball(output, ["support.txt"])
create_tarball(output) do
create_dummy_support_binaries
end
elsif url == nginx_binary_url
create_tarball(output, ["nginx.txt"])
create_tarball(output) do
create_dummy_nginx_binary
end
else
raise "Unexpected download URL: #{url}"
end
Expand All @@ -184,8 +211,8 @@ def test_building_nginx_binary
@installer.should_not_receive(:compile_nginx)
@installer.run

File.exist?("#{@temp_dir}/support/support.txt").should be_true
File.exist?("#{@temp_dir}/nginx/nginx.txt").should be_true
File.exist?("#{@temp_dir}/support/agents/PassengerWatchdog").should be_true
File.exist?("#{@temp_dir}/nginx/nginx").should be_true
end

it "builds the support binaries if it cannot be downloaded" do
Expand Down

0 comments on commit cfdc419

Please sign in to comment.