Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 71 lines (58 sloc) 1.797 kb
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
1 require 'osx/cocoa'
2 include OSX
3
e90332d Eloy Durán If the user wants it, we'll add the configuration needed by passenger to...
alloy authored
4 require File.expand_path('../shared_passenger_behaviour', __FILE__)
5
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
6 class PassengerApplication < NSObject
e90332d Eloy Durán If the user wants it, we'll add the configuration needed by passenger to...
alloy authored
7 include SharedPassengerBehaviour
8
4aed8cd Eloy Durán Added functionality to remove an application.
alloy authored
9 CONFIG_UNINSTALLER = File.expand_path('../config_uninstaller.rb', __FILE__)
10 CONFIG_INSTALLER = File.expand_path('../config_installer.rb', __FILE__)
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
11
12 kvc_accessor :host, :path
13
14 def init
15 if super_init
86f33e9 Eloy Durán Make sure an application is started if it's a new app and restarted if t...
alloy authored
16 @new_app = true
17 @dirty = false
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
18 @host, @path = '', ''
19 self
20 end
21 end
22
23 def initWithFile(file)
24 if init
86f33e9 Eloy Durán Make sure an application is started if it's a new app and restarted if t...
alloy authored
25 @new_app = false
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
26 data = File.read(file)
27 @host = data.match(/ServerName\s+(.+)\n/)[1]
28 @path = data.match(/DocumentRoot\s+"(.+)\/public"\n/)[1]
29 self
30 end
31 end
32
00b98a3 Eloy Durán Refactored the default hostname into PassengerApplication. Marked code t...
alloy authored
33 def initWithPath(path)
4978e25 Eloy Durán Small refactor.
alloy authored
34 if init
00b98a3 Eloy Durán Refactored the default hostname into PassengerApplication. Marked code t...
alloy authored
35 @path, @host = path, "#{File.basename(path).downcase}.local"
4978e25 Eloy Durán Small refactor.
alloy authored
36 self
37 end
38 end
39
e79b2e2 Eloy Durán Added code to actually start and restart an application.
alloy authored
40 def start
76c1df7 Eloy Durán Verified that restarting the application works. Cleaned UI and code.
alloy authored
41 p "Starting Rails application (restarting Apache gracefully): #{@path}"
88f61cb Eloy Durán Write out the config before starting an application.
alloy authored
42 save_config!
e826a0a Eloy Durán Gracefully restart apache.
alloy authored
43 execute '/usr/sbin/apachectl graceful'
e79b2e2 Eloy Durán Added code to actually start and restart an application.
alloy authored
44 end
45
46 def restart(sender = nil)
47 p "Restarting Rails application: #{@path}"
48 save_config! if @dirty
76c1df7 Eloy Durán Verified that restarting the application works. Cleaned UI and code.
alloy authored
49 Kernel.system("/usr/bin/touch '#{File.join(@path, 'tmp', 'restart.txt')}'")
e79b2e2 Eloy Durán Added code to actually start and restart an application.
alloy authored
50 end
86f33e9 Eloy Durán Make sure an application is started if it's a new app and restarted if t...
alloy authored
51
4aed8cd Eloy Durán Added functionality to remove an application.
alloy authored
52 def remove
53 p "Removing application: #{path}"
54 execute "/usr/bin/env ruby '#{CONFIG_UNINSTALLER}' '#{config_path}' '/etc/hosts' '#{@host}'"
55 end
86f33e9 Eloy Durán Make sure an application is started if it's a new app and restarted if t...
alloy authored
56
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
57 def save_config!
e79b2e2 Eloy Durán Added code to actually start and restart an application.
alloy authored
58 p "Saving configuration: #{config_path}"
088bd8b Eloy Durán Config installer will add an entry to /etc/hosts for the application.
alloy authored
59 execute "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '#{config_path}' '/etc/hosts' '#{@host}' '#{@path}'"
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
60 end
61
62 def config_path
88f61cb Eloy Durán Write out the config before starting an application.
alloy authored
63 @config_path ||= File.join(USERS_APACHE_PASSENGER_APPS_DIR, "#{@host}.vhost.conf")
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
64 end
65
86f33e9 Eloy Durán Make sure an application is started if it's a new app and restarted if t...
alloy authored
66 def rbSetValue_forKey(value, key)
67 super
68 @dirty = true
69 (@new_app ? start : restart) unless @host.empty? or @path.empty?
70 end
2e075ef Eloy Durán Added tests for PassengerApplication.
alloy authored
71 end
Something went wrong with that request. Please try again.