Permalink
Browse files

Write configs for multiple applications and reload the apache configs.

  • Loading branch information...
1 parent b52f45e commit 94cd90a825a030ef05835837cc51b430423ea580 @alloy alloy committed Jun 13, 2008
@@ -11,7 +11,9 @@ class PassengerApplication < NSObject
CONFIG_INSTALLER = File.expand_path('../config_installer.rb', __FILE__)
def self.startApplications(apps)
- SharedPassengerBehaviour.execute "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '/etc/hosts' '#{apps.map { |app| app.to_hash }.to_yaml}'"
+ data = apps.to_ruby.map { |app| app.to_hash }.to_yaml
+ SharedPassengerBehaviour.p "Starting Rails applications (restarting Apache gracefully):\n#{data}"
+ SharedPassengerBehaviour.execute "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '/etc/hosts' '#{data}' '/usr/sbin/apachectl graceful'"
end
kvc_accessor :host, :path
@@ -60,7 +62,7 @@ def remove
def save_config!(extra_command = nil)
p "Saving configuration: #{config_path}"
- command = "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '/etc/hosts' '#{config_path}' '#{@host}' '#{@path}'"
+ command = "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '/etc/hosts' '#{[to_hash].to_yaml}'"
command << " '#{extra_command}'" if extra_command
execute command
end
@@ -76,6 +78,6 @@ def rbSetValue_forKey(value, key)
end
def to_hash
- {'config_path' => config_path, 'host' => @host, 'path' => @path}
+ {'config_path' => config_path, 'host' => @host.to_s, 'path' => @path.to_s}
end
end
View
@@ -109,9 +109,9 @@ def tableView_validateDrop_proposedRow_proposedDropOperation(tableView, info, ro
end
def tableView_acceptDrop_row_dropOperation(tableView, info, row, operation)
- info.draggingPasteboard.propertyListForType(OSX::NSFilenamesPboardType).each do |path|
- @applicationsController.addObject PassengerApplication.alloc.initWithPath(path)
- end
+ apps = info.draggingPasteboard.propertyListForType(OSX::NSFilenamesPboardType).map { |path| PassengerApplication.alloc.initWithPath(path) }
+ @applicationsController.addObjects apps
+ PassengerApplication.startApplications apps
end
private
View
@@ -2,20 +2,23 @@
require 'osx/cocoa'
require File.expand_path('../file_backup_and_open', __FILE__)
+require 'yaml'
-vhost_file, hosts_file, host, app_path, extra_command = ARGV
+hosts_file, data, extra_command = ARGV
-vhost = %{
+YAML.load(data).each do |app|
+ vhost = %{
<VirtualHost *:80>
- ServerName #{host}
- DocumentRoot "#{File.join(app_path, 'public')}"
+ ServerName #{app['host']}
+ DocumentRoot "#{File.join(app['path'], 'public')}"
</VirtualHost>
}.sub(/^\n/, '')
-
-OSX::NSLog("Will write file: #{vhost_file}\nData: #{vhost}")
-File.backup_and_open(vhost_file, 'w', vhost)
-
-OSX::NSLog("Will append to file: #{hosts_file}\nData: #{host}")
-File.backup_and_open(hosts_file, 'a', "\n127.0.0.1\t\t\t#{host}")
+
+ OSX::NSLog("Will write file: #{app['config_path']}\nData: #{vhost}")
+ File.backup_and_open(app['config_path'], 'w', vhost)
+
+ OSX::NSLog("Will append to file: #{hosts_file}\nData: #{app['host']}")
+ File.backup_and_open(hosts_file, 'a', "\n127.0.0.1\t\t\t#{app['host']}")
+end
system(extra_command) if extra_command
@@ -13,8 +13,10 @@ def apple_script(command)
script = NSAppleScript.alloc.initWithSource(command)
script.performSelector_withObject("executeAndReturnError:", nil)
end
+ module_function :apple_script
def p(obj)
NSLog(obj.is_a?(String) ? obj : obj.inspect)
end
+ module_function :p
end
@@ -1,4 +1,5 @@
require File.expand_path('../test_helper', __FILE__)
+require 'yaml'
describe "Config installer" do
before do
@@ -21,7 +22,7 @@
file_which_is_created_by_the_optional_extra_command = File.join(@tmp, 'file_from_extra_command.txt')
- `/usr/bin/env ruby #{@config_installer} '#{vhost_file}' '#{hosts_file}' '#{host}' '#{path}' 'touch #{file_which_is_created_by_the_optional_extra_command}'`
+ `/usr/bin/env ruby #{@config_installer} '#{hosts_file}' '#{ [{ 'config_path' => vhost_file, 'host' => host, 'path' => path }].to_yaml }' 'touch #{file_which_is_created_by_the_optional_extra_command}'`
vhost = File.read(vhost_file)
vhost.should == "<VirtualHost *:80>\n ServerName #{host}\n DocumentRoot \"#{path}/public\"\n</VirtualHost>\n"
@@ -72,7 +72,7 @@ def after_setup
end
it "should be able to save the config file" do
- passenger_app.expects(:execute).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_INSTALLER}' '/etc/hosts' '#{passenger_app.config_path}' 'het-manfreds-blog.local' '/Users/het-manfred/rails code/blog'")
+ passenger_app.expects(:execute).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_INSTALLER}' '/etc/hosts' '#{[passenger_app.to_hash].to_yaml}'")
passenger_app.save_config!
end
@@ -118,16 +118,18 @@ def after_setup
passenger_app.remove
end
- it "should return it's attributes as a hash" do
- passenger_app.to_hash.should == {'config_path' => passenger_app.config_path, 'host' => passenger_app.host, 'path' => passenger_app.path}
+ it "should return it's attributes as a hash without NSStrings etc" do
+ assigns(:host, 'app.local'.to_ns)
+ passenger_app.to_hash.should == { 'config_path' => passenger_app.config_path, 'host' => 'app.local', 'path' => passenger_app.path }
+ passenger_app.to_hash.to_yaml.should.not.include 'NSCFString'
end
it "should start multiple applications at once" do
- app1 = PassengerApplication.alloc.initWithPath('/rails/app1')
- app2 = PassengerApplication.alloc.initWithPath('/rails/app2')
+ app1 = PassengerApplication.alloc.initWithPath('/rails/app1'.to_ns)
+ app2 = PassengerApplication.alloc.initWithPath('/rails/app2'.to_ns)
- SharedPassengerBehaviour.expects(:execute).times(1).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_INSTALLER}' '/etc/hosts' '#{[app1.to_hash, app2.to_hash].to_yaml}'")
+ SharedPassengerBehaviour.expects(:execute).times(1).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_INSTALLER}' '/etc/hosts' '#{[app1.to_hash, app2.to_hash].to_yaml}' '/usr/sbin/apachectl graceful'")
- PassengerApplication.startApplications [app1, app2]
+ PassengerApplication.startApplications [app1, app2].to_ns
end
end
@@ -190,15 +190,16 @@ def after_teardown
pref_pane.tableView_validateDrop_proposedRow_proposedDropOperation(nil, @info, nil, nil).should == OSX::NSDragOperationNone
end
- it "should add an application to the applications for each directory" do
+ it "should add an application to the applicationsController for each directory and then start them" do
stub_pb_and_info_with_two_directories
- pref_pane.tableView_acceptDrop_row_dropOperation(nil, @info, nil, nil)
- app1, app2 = applicationsController.content
- app1.path.should == @dirs.first
- app2.path.should == @dirs.last
- app1.host.should == 'app1.local'
- app2.host.should == 'app2.local'
+ apps_should_be = lambda do |apps|
+ apps.map { |app| app.path } == @dirs and apps.map { |app| app.host } == %w{ app1.local app2.local }
+ end
+
+ PassengerApplication.expects(:startApplications).with &apps_should_be
+ pref_pane.tableView_acceptDrop_row_dropOperation(nil, @info, nil, nil)
+ apps_should_be.call(applicationsController.content)
end
private
View
@@ -16,4 +16,5 @@ module Rucola::TestCase::InstanceMethods
module SharedPassengerBehaviour
# Silencio!
def p(obj); end
+ module_function :p
end

0 comments on commit 94cd90a

Please sign in to comment.