Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Add an unregister command.
Browse files Browse the repository at this point in the history
* Optimize the register and unregister calls to only shell out once instead of
  for every application configured.
  • Loading branch information
Manfred committed Aug 25, 2011
1 parent f8c38b8 commit 5a379a3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .kick
Expand Up @@ -19,6 +19,12 @@ process do |files|
case file
when %r{^test/ppane/test_helper/add_allow_switch.rb$}
'test/ppane/test_helper/add_allow_switch_test.rb'
when %r{^lib/(.*).rb$}
testfile = "test/ppane/#{File.basename($1)}_test.rb"
if File.exist?(testfile)
files.delete(file)
testfile
end
end
end)

Expand Down
19 changes: 16 additions & 3 deletions lib/passenger_pane/runner.rb
Expand Up @@ -95,18 +95,29 @@ def restart(host)
end
end

def register
@configuration.applications.each do |app|
app.register
def _all_hosts
@configuration.applications.inject([]) do |hosts, application|
hosts.concat application.to_hash['hosts']
end
end

def register
PassengerPane::DirectoryServices.register(_all_hosts)
PassengerPane::DirectoryServices.write_to_hosts_file_if_broken
end

def unregister
PassengerPane::DirectoryServices.unregister(_all_hosts)
PassengerPane::DirectoryServices.write_to_hosts_file_if_broken
end

def self.usage
puts "Usage: #{File.basename($0)} <command> [options] [attributes]"
puts
puts "Commands:"
puts " list List all configured applications"
puts " register Register all configured hostnames with Directory Services*"
puts " unregister Unregister all configured hostnames with Directory Services*"
puts " info Show information about the system"
puts " configure Configure Apache for use with the Passenger Pane*"
puts " add <directory> Add an application in a directory*"
Expand Down Expand Up @@ -163,6 +174,8 @@ def self.run(flags, args)
new(options).list
when 'register'
new(options).register
when 'unregister'
new(options).unregister
else
path = trust(File.expand_path(command))
if File.exist?(path)
Expand Down
16 changes: 13 additions & 3 deletions test/ppane/runner_test.rb
Expand Up @@ -25,14 +25,24 @@
end

it "registers all configured hostnames" do
@conf.applications.each do |app|
PassengerPane::DirectoryServices.expects(:register).with(app.to_hash['hosts'])
end
all_hosts = %w(assets.skit.local skit.local weblog.local)
PassengerPane::Runner.any_instance.stubs(:_all_hosts).returns(all_hosts)
PassengerPane::DirectoryServices.expects(:register).with(all_hosts)
capture_stdout do
PassengerPane::Runner.run({}, %w(register))
end
end

it "unregisters all configured hostnames" do

all_hosts = %w(assets.skit.local skit.local weblog.local)
PassengerPane::Runner.any_instance.stubs(:_all_hosts).returns(all_hosts)
PassengerPane::DirectoryServices.expects(:unregister).with(all_hosts)
capture_stdout do
PassengerPane::Runner.run({}, %w(unregister))
end
end

it "shows information about the system" do
@conf.httpd.stubs(:passenger_module_installed?).returns(true)
PassengerPane::DirectoryServices.stubs(:registered_hosts).returns(%w(assets.skit.local skit.local weblog.local))
Expand Down

0 comments on commit 5a379a3

Please sign in to comment.