0
@@ -14,6 +14,7 @@ module Merb
0
:reload_classes => true,
0
+ :fork_for_class_load => !RUBY_PLATFORM.in?("windows", "java"),
0
:environment => "development",
0
@@ -102,6 +103,12 @@ module Merb
0
# Configuration settings to use. These are merged with the defaults.
0
def setup(settings = {})
0
@configuration = defaults.merge(settings)
0
+ unless @configuration[:reload_classes]
0
+ @configuration[:fork_for_class_load] = false
0
# Parses the command line arguments and stores them in the config.
0
@@ -122,99 +129,158 @@ module Merb
0
opts.banner = "Usage: merb [uGdcIpPhmailLerkKX] [argument]"
0
opts.define_head "Merb. Pocket rocket web framework"
0
- opts.separator 'If no flags are given, Merb starts in the foreground on port 4000.'
0
- opts.on("-u", "--user USER", "This flag is for having merb run as a user other than the one currently logged in. Note: if you set this you must also provide a --group option for it to take effect.") do |user|
0
+ opts.separator '*' * 80
0
+ opts.separator "If no flags are given, Merb starts in the " \
0
+ "foreground on port 4000."
0
+ opts.separator '*' * 80
0
+ opts.on("-u", "--user USER", "This flag is for having merb run " \
0
+ "as a user other than the one currently logged in. Note: " \
0
+ "if you set this you must also provide a --group option " \
0
+ "for it to take effect.") do |user|
0
- opts.on("-G", "--group GROUP", "This flag is for having merb run as a group other than the one currently logged in. Note: if you set this you must also provide a --user option for it to take effect.") do |group|
0
+ opts.on("-G", "--group GROUP", "This flag is for having merb run " \
0
+ "as a group other than the one currently logged in. Note: " \
0
+ "if you set this you must also provide a --user option " \
0
+ "for it to take effect.") do |group|
0
options[:group] = group
0
- opts.on("-d", "--daemonize", "This will run a single merb in the background.") do |daemon|
0
+ opts.on("-d", "--daemonize", "This will run a single merb in the " \
0
+ "background.") do |daemon|
0
options[:daemonize] = true
0
+ opts.on("-N", "--no-daemonize", "This will allow you to run a " \
0
+ "cluster in console mode") do |no_daemon|
0
+ options[:daemonize] = false
0
- opts.on("-c", "--cluster-nodes NUM_MERBS", "Number of merb daemons to run.") do |nodes|
0
+ opts.on("-c", "--cluster-nodes NUM_MERBS", Integer,
0
+ "Number of merb daemons to run.") do |nodes|
0
+ options[:daemonize] = true unless options.key?(:daemonize)
0
options[:cluster] = nodes
0
- opts.on("-I", "--init-file FILE", "File to use for initialization on load, defaults to config/init.rb") do |init_file|
0
+ opts.on("-I", "--init-file FILE", "File to use for initialization " \
0
+ "on load, defaults to config/init.rb") do |init_file|
0
options[:init_file] = init_file
0
- opts.on("-p", "--port PORTNUM", "Port to run merb on, defaults to 4000.") do |port|
0
+ opts.on("-p", "--port PORTNUM", Integer, "Port to run merb on, " \
0
+ "defaults to 4000.") do |port|
0
- opts.on("-o", "--socket-file FILE", "Socket file to run merb on, defaults to [Merb.root]/log/merb.sock") do |port|
0
+ opts.on("-o", "--socket-file FILE", "Socket file to run merb on, " \
0
+ "defaults to [Merb.root]/log/merb.sock. This is for " \
0
+ "web servers, like thin, that use sockets.") do |port|
0
options[:socket_file] = port
0
- opts.on("-s", "--socket SOCKNUM", "Socket number to run merb on, defaults to 0.") do |port|
0
+ opts.on("-s", "--socket SOCKNUM", Integer, "Socket number to run " \
0
+ "merb on, defaults to 0.") do |port|
0
options[:socket] = port
0
- opts.on("-P", "--pid PIDFILE", "PID file, defaults to [Merb.root]/log/merb.[port_number].pid") do |pid_file|
0
+ opts.on("-P", "--pid PIDFILE", "PID file, defaults to " \
0
+ "[Merb.root]/log/merb.main.pid for the master process and" \
0
+ "[Merb.root]/log/merb.[port number].pid for worker " \
0
+ "processes. For clusters, use %s to specify where " \
0
+ "in the file merb should place the port number. For " \
0
+ "instance: -P myapp.%s.pid") do |pid_file|
0
options[:pid_file] = pid_file
0
- opts.on("-h", "--host HOSTNAME", "Host to bind to (default is 0.0.0.0).") do |host|
0
+ opts.on("-h", "--host HOSTNAME", "Host to bind to " \
0
+ "(default is 0.0.0.0).") do |host|
0
- opts.on("-m", "--merb-root /path/to/approot", "The path to the Merb.root for the app you want to run (default is current working dir).") do |root|
0
+ opts.on("-m", "--merb-root /path/to/approot", "The path to the " \
0
+ "Merb.root for the app you want to run " \
0
+ "(default is current working directory).") do |root|
0
options[:merb_root] = File.expand_path(root)
0
- opts.on("-a", "--adapter mongrel", "The rack adapter to use to run merb[mongrel, emongrel, thin, ebb, fastcgi, webrick, runner, irb]") do |adapter|
0
- options[:adapter] = adapter
0
+ adapters = [:mongrel, :emongrel, :thin, :ebb, :fastcgi, :webrick]
0
+ opts.on("-a", "--adapter ADAPTER",
0
+ "The rack adapter to use to run merb (default is mongrel)" \
0
+ "[#{adapters.join(', ')}]") do |adapter|
0
+ options[:adapter] ||= adapter
0
- opts.on("-R", "--rackup FILE", "Load an alternate Rack config file (default is config/rack.rb)") do |rackup|
0
+ opts.on("-R", "--rackup FILE", "Load an alternate Rack config " \
0
+ "file (default is config/rack.rb)") do |rackup|
0
options[:rackup] = rackup
0
- opts.on("-i", "--irb-console", "This flag will start merb in irb console mode. All your models and other classes will be available for you in an irb session.") do |console|
0
+ opts.on("-i", "--irb-console", "This flag will start merb in " \
0
+ "irb console mode. All your models and other classes will " \
0
+ "be available for you in an irb session.") do |console|
0
options[:adapter] = 'irb'
0
- opts.on("-S", "--sandbox", "This flag will enable a sandboxed irb console. If your ORM supports transactions, all edits will be rolled back on exit.") do |sandbox|
0
+ opts.on("-S", "--sandbox", "This flag will enable a sandboxed irb " \
0
+ "console. If your ORM supports transactions, all edits will " \
0
+ "be rolled back on exit.") do |sandbox|
0
options[:sandbox] = true
0
- opts.on("-l", "--log-level LEVEL", "Log levels can be set to any of these options: debug < info < warn < error < fatal") do |log_level|
0
+ opts.on("-l", "--log-level LEVEL", "Log levels can be set to any of " \
0
+ "these options: debug < info < warn < error < " \
0
+ "fatal (default is info)") do |log_level|
0
options[:log_level] = log_level.to_sym
0
- opts.on("-L", "--log LOGFILE", "A string representing the logfile to use.") do |log_file|
0
+ opts.on("-L", "--log LOGFILE", "A string representing the logfile to " \
0
+ "use. Defaults to [Merb.root]/log/merb.[main].log for the " \
0
+ "master process and [Merb.root]/log/merb[port number].log" \
0
+ "for worker processes") do |log_file|
0
options[:log_file] = log_file
0
- opts.on("-e", "--environment STRING", "Run merb in the correct mode(development, production, testing)") do |env|
0
+ opts.on("-e", "--environment STRING", "Environment to run Merb " \
0
+ "under [development, production, testing] " \
0
+ "(default is development)") do |env|
0
options[:environment] = env
0
opts.on("-r", "--script-runner ['RUBY CODE'| FULL_SCRIPT_PATH]",
0
- "Command-line option to run scripts and/or code in the merb app.") do |code_or_file|
0
+ "Command-line option to run scripts and/or code in the " \
0
+ "merb app.") do |code_or_file|
0
options[:runner_code] = code_or_file
0
options[:adapter] = 'runner'
0
- opts.on("-K", "--graceful PORT or all", "Gracefully kill one merb proceses by port number. Use merb -K all to gracefully kill all merbs.") do |ports|
0
+ opts.on("-K", "--graceful PORT or all", "Gracefully kill one " \
0
+ "merb proceses by port number. Use merb -K all to " \
0
+ "gracefully kill all merbs.") do |ports|
0
options[:action] = :kill
0
+ ports = "main" if ports == "all"
0
- opts.on("-k", "--kill PORT or all", "Kill one merb proceses by port number. Use merb -k all to kill all merbs.") do |port|
0
+ opts.on("-k", "--kill PORT", "Force kill one merb worker " \
0
+ "by port number. This will cause the worker to" \
0
+ "be respawned. If you want to kill ") do |port|
0
options[:action] = :kill_9
0
+ port = "main" if port == "all"
0
+ opts.on("--fast-deploy", "Reload the code, but not your" \
0
+ options[:action] = :fast_deploy
0
- opts.on("-X", "--mutex on/off", "This flag is for turning the mutex lock on and off.") do |mutex|
0
+ # @todo Do we really need this flag? It seems unlikely to want to
0
+ # change the mutex from the command-line.
0
+ opts.on("-X", "--mutex on/off", "This flag is for turning the " \
0
+ "mutex lock on and off.") do |mutex|
0
options[:use_mutex] = false
0
@@ -226,10 +292,13 @@ module Merb
0
- Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
0
+ if Debugger.respond_to?(:settings)
0
+ Debugger.settings[:autoeval] = true
0
puts "Debugger enabled"
0
- puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
0
+ puts "You need to install ruby-debug to run the server in " \
0
+ "debugging mode. With gems, use `gem install ruby-debug'"
0
@@ -249,7 +318,11 @@ module Merb
0
# Parse what we have on the command line
0
+ rescue OptionParser::InvalidOption => e
0
+ Merb.fatal! e.message, e
0
Merb::Config.setup(options)