Parent

Included Modules

Class Index [+]

Quicksearch

Ramaze::Bin::Start

The start command is used to start a Ramaze application. The ramaze start command optionally takes a directory or path to a file. If it’s a directory this command will look for a Rackup file in that directory, otherwise it assumes the specified file is a Rackup file.

Usage:

   ramaze start
   ramaze start /home/foobar/projects/blog/config.ru
   ramaze start /home/foobar/projects/blog

@author Yorick Peterse @since 21-07-2011

Constants

Description

The description of this command, displayed when the global help menu is invoked.

Banner

The banner of this command, displayed when it’s invoked with the -h or —help option.

Public Class Methods

new() click to toggle source

Creates a new instance of the command and prepares OptionParser.

@author Yorick Peterse @since 21-07-2011

     # File lib/ramaze/bin/start.rb, line 45
 45:       def initialize
 46:         @ruby_options = {}
 47:         @rack_options = {}
 48:         @options      = OptionParser.new do |opt|
 49:           opt.banner         = Banner
 50:           opt.summary_indent = '  '
 51: 
 52:           # Sets all Ruby options
 53:           opt.separator "\nRuby Options:\n"
 54: 
 55:           opt.on('-e', '--eval LINE', 'Evaluates a line of code') do |code|
 56:             @ruby_options['-e'] = code
 57:           end
 58: 
 59:           opt.on('-d', '--debug', 'Set debugging flags (set $DEBUG to true)') do
 60:             @ruby_options['-d'] = nil
 61:           end
 62: 
 63:           opt.on('-w', '--warn', 'Turns warnings on for the script') do
 64:             @ruby_options['-w'] = nil
 65:           end
 66: 
 67:           opt.on('-I', '--include PATH', 'specifies the $LOAD_PATH') do |path|
 68:             @ruby_options['-I'] = path
 69:           end
 70: 
 71:           opt.on(
 72:             '-r',
 73:             '--require LIBRARY',
 74:             'requires the library before starting'
 75:           ) do |library|
 76:             @ruby_options['-r'] = library
 77:           end
 78: 
 79:           # Set all Rack options
 80:           opt.separator "\nRack Options:\n"
 81: 
 82:           opt.on(
 83:             '-s',
 84:             '--server SERVER',
 85:             'Serve the application using the given server'
 86:           ) do |server|
 87:             @rack_options['-s'] = server
 88:           end
 89: 
 90:           opt.on(
 91:             '-o',
 92:             '--host HOST',
 93:             'Listens on the given host (0.0.0.0 by default)'
 94:           ) do |host|
 95:             @rack_options['-o'] = host
 96:           end
 97: 
 98:           opt.on(
 99:             '-p',
100:             '--port PORT',
101:             'Uses the given port, set to 9292 by default'
102:           ) do |port|
103:             @rack_options['-p'] = port
104:           end
105: 
106:           opt.on(
107:             '-O',
108:             '--option NAME[=VALUE]',
109:             'Passes the given option and it\s value to the server'
110:           ) do |name|
111:             @rack_options['-O'] = name
112:           end
113: 
114:           opt.on(
115:             '-E',
116:             '--env ENVIRONMENT',
117:             'Uses the specified environment, set to development by default'
118:           ) do |env|
119:             @rack_options['-E'] = env
120:           end
121: 
122:           opt.on('-D', '--daemonize', 'Runs as a daemon in the background') do
123:             @rack_options['-D'] = nil
124:           end
125: 
126:           opt.on(
127:             '-P',
128:             '--pid FILE',
129:             'File to store the PID in, defaults to rack.pid'
130:           ) do |pid|
131:             @rack_options['-P'] = pid
132:           end
133: 
134:           # Set all common options
135:           opt.separator "\nOptions\n"
136: 
137:           opt.on('-h', '--help', 'Shows this help message') do
138:             puts @options
139:             exit
140:           end
141:         end
142:       end

Public Instance Methods

run(argv = []) click to toggle source

Runs the command based on the given command line arguments.

@author Yorick Peterse @since 21-07-2011 @param [Array] argv An array of command line arguments.

     # File lib/ramaze/bin/start.rb, line 151
151:       def run(argv = [])
152:         begin
153:           @options.parse!(argv)
154:         rescue => e
155:           warn "Error: #{e.message}"
156:           abort @options.to_s
157:         end
158: 
159:         # Remove all trailing/leading whitespace from the options
160:         @rack_options.each do |k, v|
161:           @rack_options[k] = v.strip if v.respond_to?(:strip)
162:         end
163: 
164:         @ruby_options.each do |k, v|
165:           @ruby_options[k] = v.strip if v.respond_to?(:strip)
166:         end
167: 
168:         rackup_config = argv.delete_at(0)
169:         rackup_config = File.join(Dir.pwd, 'config.ru') if rackup_config.nil?
170: 
171:         # Check if the config is a directory or file
172:         if File.directory?(rackup_config)
173:           rackup_config = File.join(rackup_config, 'config.ru')
174:         end
175: 
176:         if !File.exist?(rackup_config)
177:           abort "The Rackup config #{rackup_config} does not exist"
178:         end
179: 
180:         # Set the default port and server to use.
181:         if !@rack_options['-p']
182:           @rack_options['-p'] = 7000
183:         end
184: 
185:         # Set the default server to use
186:         if !@rack_options['-s']
187:           @rack_options['-s'] = Ramaze.options.adapter.handler.to_s
188:         end
189: 
190:         # If a PID is supplied we should first check to see if Ramaze isn't
191:         # already running.
192:         if @rack_options.key?('-P') and is_running?(@rack_options['-P'])
193:           abort 'This application is already running'
194:         end
195: 
196:         params = []
197: 
198:         @ruby_options.merge(@rack_options).each do |opt, value|
199:           params.push("#{opt}#{value}")
200:         end
201: 
202:         start_server(rackup_path, rackup_config, *params)
203:       end
start_server(rackup_path, rackup_config, *params) click to toggle source

Starts a server baed on the rackup path, rackup configuration file and additional parameters.

@author Yorick Peterse @since 21-10-2011 @param [String] rackup_path The path to the Rackup executable. @param [String] rackup_config The path to the config.ru file to use. @param [Array] *params Additional parameters to pass to the ``exec()``

 method.
     # File lib/ramaze/bin/start.rb, line 216
216:       def start_server(rackup_path, rackup_config, *params)
217:         exec('ruby', rackup_path, rackup_config, *params)
218:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.