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

Commit

Permalink
If the user wants it, we'll add the configuration needed by passenger…
Browse files Browse the repository at this point in the history
… to an existing conf.
  • Loading branch information
alloy committed Jun 10, 2008
1 parent 7a99c9e commit e90332d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 46 deletions.
15 changes: 4 additions & 11 deletions PassengerApplication.rb
@@ -1,7 +1,11 @@
require 'osx/cocoa'
include OSX

require File.expand_path('../shared_passenger_behaviour', __FILE__)

class PassengerApplication < NSObject
include SharedPassengerBehaviour

CONFIG_PATH = "/etc/apache2/users/passenger_apps"
CONFIG_INSTALLER = File.expand_path('../config_installer.rb', __FILE__)

Expand Down Expand Up @@ -55,15 +59,4 @@ def rbSetValue_forKey(value, key)
@dirty = true
(@new_app ? start : restart) unless @host.empty? or @path.empty?
end

private

def execute(command)
script = NSAppleScript.alloc.initWithSource("do shell script \"#{command}\" with administrator privileges")
script.performSelector_withObject("executeAndReturnError:", nil)
end

def p(obj)
NSLog(obj.inspect)
end
end
20 changes: 8 additions & 12 deletions PassengerPref.rb
Expand Up @@ -11,9 +11,15 @@

OSX.require_framework 'PreferencePanes'

require File.expand_path('../shared_passenger_behaviour', __FILE__)
require File.expand_path('../PassengerApplication', __FILE__)

class PrefPanePassenger < NSPreferencePane
include SharedPassengerBehaviour

USERS_APACHE_CONFIG = "/etc/apache2/users/#{OSX.NSUserName}.conf"
PASSENGER_CONFIG_INSTALLER = File.expand_path('../passenger_config_installer.rb', __FILE__)

ib_outlet :applicationsController
kvc_accessor :applications

Expand Down Expand Up @@ -45,10 +51,6 @@ def restart(sender)
p "restart"
end

def users_apache_config
"/etc/apache2/users/#{OSX.NSUserName}.conf"
end

USERS_APACHE_CONFIG_LOAD_PASSENGER = [
'LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so',
'RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server',
Expand All @@ -57,7 +59,7 @@ def users_apache_config
]

def is_users_apache_config_setup?
conf = File.read(users_apache_config)
conf = File.read(USERS_APACHE_CONFIG)
USERS_APACHE_CONFIG_LOAD_PASSENGER.all? { |line| conf.include? line }
end

Expand All @@ -68,12 +70,6 @@ def user_wants_us_to_setup_config?
end

def setup_users_apache_config!

end

private

def p(obj)
NSLog(obj.inspect)
execute "/usr/bin/env ruby '#{PASSENGER_CONFIG_INSTALLER}' '#{USERS_APACHE_CONFIG}'"
end
end
10 changes: 10 additions & 0 deletions shared_passenger_behaviour.rb
@@ -0,0 +1,10 @@
module SharedPassengerBehaviour
def execute(command)
script = NSAppleScript.alloc.initWithSource("do shell script \"#{command}\" with administrator privileges")
script.performSelector_withObject("executeAndReturnError:", nil)
end

def p(obj)
NSLog(obj.inspect)
end
end
24 changes: 1 addition & 23 deletions test/pref_pane_passenger_test.rb
Expand Up @@ -58,26 +58,8 @@ def after_setup
end

it "should add the required lines to setup passenger to the users apache config" do
tmp = File.expand_path('../tmp', __FILE__)
FileUtils.mkdir_p tmp

conf = File.join(tmp, 'user.conf')
File.open(conf, 'w') { |f| f << "</Directory>" }

pref_pane.expects(:execute).with("/usr/bin/env ruby '#{PrefPanePassenger::PASSENGER_CONFIG_INSTALLER}' '#{PrefPanePassenger::USERS_APACHE_CONFIG}'")
pref_pane.setup_users_apache_config!

File.read(conf).should == %{
</Directory>
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
RailsEnv development
Include /private/etc/apache2/users/passenger_apps/*.vhost.conf
}.sub(/^\n/, '')

FileUtils.rm_rf tmp
end
end

Expand Down Expand Up @@ -111,8 +93,4 @@ def after_setup
pref_pane.remove(nil)
applicationsController.content.should == [stay_app]
end

it "should return the path to the users apache config" do
pref_pane.users_apache_config.should == "/etc/apache2/users/#{OSX.NSUserName}.conf"
end
end

0 comments on commit e90332d

Please sign in to comment.