Class: PassengerPane::Runner
- Inherits:
-
Object
- Object
- PassengerPane::Runner
- Defined in:
- lib/passenger_pane/runner.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(directory) ⇒ Object
- #configure ⇒ Object
- #delete(host) ⇒ Object
- #info ⇒ Object
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #list ⇒ Object
- #machine_readable? ⇒ Boolean
- #register ⇒ Object
- #restart(host) ⇒ Object
- #update(host) ⇒ Object
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 |
# File 'lib/passenger_pane/runner.rb', line 5 def initialize() = @configuration = PassengerPane::Configuration.auto end |
Class Method Details
.needs_root ⇒ Object
187 188 189 |
# File 'lib/passenger_pane/runner.rb', line 187 def self.needs_root puts "[!] The command might not run because it requires root privileges" unless ENV['USER'] == 'root' end |
.run(flags, args) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/passenger_pane/runner.rb', line 128 def self.run(flags, args) = {} command = args.shift.to_s return usage if command == '' flags.each do |name, value| case name when 'h', 'help' command = 'help' when 'm', 'machine' ['machine_readable'] = true else [name] = value end end unless $stdin.tty? data = YAML.load($stdin.read) data.each do |name, value| [name] = value end if data end case command when 'info' new().info when 'configure' needs_root new().configure when 'add' needs_root new().add(args.first) when 'update' needs_root new().update(args.first) when 'delete' needs_root new().delete(args.first) when 'restart' host = args.first needs_root unless host new().restart(host) when 'list' new().list when 'register' needs_root new().register else path = File.(command) if File.exist?(path) needs_root new().add(path) else usage end end end |
.usage ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/passenger_pane/runner.rb', line 100 def self.usage puts "Usage: #{File.basename($0)} <command> [options]" puts puts "Commands:" puts " list: List all configured applications" puts " register: Register 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*" puts " update <host>: Update an application*" puts " delete <host>: Deletes an application*" puts " restart <host>: Restart an application" puts " restart: Restart Apache to pick up configuration changes*" puts puts "* requires root privileges" puts puts "Options:" puts " -h, --help: Show this help text" puts " -m, --machine Use machine readable output" puts puts "Attributes:" puts " --host: Hostname for the application (ie. myapp.local)" puts " --aliases: Aliases for the application (ie. assets.myapp.local)" puts " --path: The folder with the application" puts " --environment: The environment to run, usually development or production" puts " --framework: The framework, either rack or rails" end |
Instance Method Details
#add(directory) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/passenger_pane/runner.rb', line 39 def add(directory) = .dup [:path] = File.(directory) application = PassengerPane::Application.new(@configuration, ) if application.save @configuration.httpd.restart end if machine_readable? puts YAML.dump(application.to_hash) end end |
#configure ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/passenger_pane/runner.rb', line 31 def configure unless @configuration.httpd.passenger_configured? @configuration.httpd.configure_passenger @configuration.httpd.write @configuration.httpd.restart end end |
#delete(host) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/passenger_pane/runner.rb', line 63 def delete(host) if application = PassengerPane::Application.find(@configuration, :host => host) application.delete @configuration.httpd.restart end end |
#info ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/passenger_pane/runner.rb', line 14 def info if machine_readable? puts YAML.dump({ 'passenger_module_installed' => @configuration.httpd.passenger_module_installed?, 'passenger_configured' => @configuration.httpd.passenger_configured? }) else puts "Apache directory: #{@configuration.apache_directory}" puts "Passenger installed: #{@configuration.httpd.passenger_module_installed? ? 'yes' : 'no'}" puts "Passenger configured: #{@configuration.httpd.passenger_configured? ? 'yes' : 'no'}" puts "Registered hostnames:" PassengerPane::DirectoryServices.registered_hosts.each do |host| puts " #{host}" end end end |
#list ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/passenger_pane/runner.rb', line 70 def list if machine_readable? puts YAML.dump(@configuration.applications.map do |app| app.to_hash end) else @configuration.applications.each_with_index do |app, index| puts unless index == 0 puts "#{app.host}" puts " Aliases: #{app.aliases}" puts " Folder: #{app.path}" puts " Environment: #{app.environment}" end end end |
#machine_readable? ⇒ Boolean
10 11 12 |
# File 'lib/passenger_pane/runner.rb', line 10 def machine_readable? ['machine_readable'] end |
#register ⇒ Object
94 95 96 97 98 |
# File 'lib/passenger_pane/runner.rb', line 94 def register @configuration.applications.each do |app| app.register end end |
#restart(host) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/passenger_pane/runner.rb', line 86 def restart(host) if host and application = PassengerPane::Application.find(@configuration, :host => host) application.restart else @configuration.httpd.restart end end |
#update(host) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/passenger_pane/runner.rb', line 51 def update(host) if application = PassengerPane::Application.find(@configuration, :host => host) application.set() if application.save @configuration.httpd.restart end if machine_readable? puts YAML.dump(application.to_hash) end end end |