Flowdock
method

run

Importance_0
v2.2.1 - Show latest stable - 0 notes - Class: Rails::MongrelServer::Start
run() public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File railties/lib/rails/mongrel_server/commands.rb, line 110
      def run
        if @generate
          @generate = File.expand_path(@generate)
          Mongrel.log(:error, "** Writing config to \"#@generate\".")
          open(@generate, "w") {|f| f.write(settings.to_yaml) }
          Mongrel.log(:error, "** Finished.  Run \"mongrel_rails start -C #@generate\" to use the config file.")
          exit 0
        end

        config = RailsConfigurator.new(settings) do
          defaults[:log] = $stdout if defaults[:environment] == 'development'

          Mongrel.log("=> Rails #{Rails.version} application starting on http://#{defaults[:host]}:#{defaults[:port]}")

          unless defaults[:daemon]
            Mongrel.log("=> Call with -d to detach")
            Mongrel.log("=> Ctrl-C to shutdown server")
            start_debugger if defaults[:debug]
          end

          if defaults[:daemon]
            if File.exist? defaults[:pid_file]
              Mongrel.log(:error, "!!! PID file #{defaults[:pid_file]} already exists.  Mongrel could be running already.  Check your #{defaults[:log_file]} for errors.")
              Mongrel.log(:error, "!!! Exiting with error.  You must stop mongrel and clear the .pid before I'll attempt a start.")
              exit 1
            end

            daemonize

            Mongrel.log("Daemonized, any open files are closed.  Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.")
            Mongrel.log("Settings loaded from #{@config_file} (they override command line).") if @config_file
          end

          Mongrel.log("Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log")

          listener do
            prefix = defaults[:prefix] || '/'

            if defaults[:debug]
              Mongrel.log("Installing debugging prefixed filters. Look in log/mongrel_debug for the files.")
              debug(prefix)
            end

            setup_mime_types
            dir_handler = Mongrel::DirHandler.new(defaults[:docroot], false)
            dir_handler.passthrough_missing_files = true

            unless defaults[:environment] == 'production'
              Mongrel.log("Mounting DirHandler at #{prefix}...")
              uri prefix, :handler => dir_handler
            end


            Mongrel.log("Starting Rails with #{defaults[:environment]} environment...")
            Mongrel.log("Mounting Rails at #{prefix}...")
            mount_rails(prefix)
            Mongrel.log("Rails loaded.")


            Mongrel.log("Loading any Rails specific GemPlugins" )
            load_plugins

            if defaults[:config_script]
              Mongrel.log("Loading #{defaults[:config_script]} external config script")
              run_config(defaults[:config_script])
            end

            setup_signals
          end
        end

        config.run
        Mongrel.log("Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}")

        if config.defaults[:daemon]
          config.write_pid_file
        else
          Mongrel.log("Use CTRL-C to stop.")
          tail "log/#{config.defaults[:environment]}.log"
        end

        config.join

        if config.needs_restart
          unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
            cmd = "ruby #{__FILE__} start #{original_args.join(' ')}"
            Mongrel.log("Restarting with arguments:  #{cmd}")
            config.stop(false, true)
            config.remove_pid_file

            if config.defaults[:daemon]
              system cmd
            else
              Mongrel.log(:error, "Can't restart unless in daemon mode.")
              exit 1
            end
          else
            Mongrel.log("Win32 does not support restarts. Exiting.")
          end
        end
      end
Register or log in to add new notes.