- 浏览: 1346326 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (732)
- Java_about (146)
- Spring_Hibernate_Struts_OpenSource (27)
- linux_unix (62)
- life_sth (22)
- js_css_html_xml_nodejs (69)
- design_pattens (1)
- Perl (8)
- php_ecshop (4)
- DB_Mysql_Oracle_Informix_SqlServer (43)
- JSTL (8)
- Testing_自动化测试 (42)
- DB_ID_UUID (4)
- SEM_SEO (1)
- english_study_improvement (4)
- SVN_Git (9)
- WebService_SOA_CloudComputing (3)
- E-Commerce (1)
- Lucene_Solr (7)
- others (2)
- Regex (2)
- tomcat_jetty (8)
- zeroc-ice (1)
- java_excel (5)
- ant_maven_gradle (5)
- Unity_VR_AR_C# (2)
- jmeter (1)
- XPath_dom4j (1)
- Ruby_and_Rails (68)
- write_a_rails (17)
- manage_and_team (1)
- getting_real (1)
- ubuntu (20)
- git_and_git_flow (7)
- TODO (1)
- PM_design (2)
- Python_and_Django (8)
- NoSql_mongo_redis (24)
- C/C++ (3)
- vi_vim_gvim (0)
- c#_.Net_windows编程_dll (10)
- Php_and_Yii (9)
- Android_IOS (31)
- Mysql (5)
- sa_运维_network_硬件 (37)
- lua (2)
- c_cpp_VisualStudio (21)
- 硬件-RM-Arduino (6)
最新评论
-
shenkun58:
...
NoClassDefFoundError: Could not initialize springframework.BeanCreationException -
liaojia1:
正解,感谢
NoClassDefFoundError: Could not initialize springframework.BeanCreationException -
flingfox63:
谢谢分享,电脑上有IPV6,导致了Guard启动不了……
ruby错误解决: Address family not supported by protocol - connect(2) -
c39274936:
s = "hello_world_ruby" ...
驼峰格式和下划线格式转换_translation between camel and snake format -
yfj300:
学习了学习了学习了学习了
硬盘基本知识(磁道、扇区、柱面、磁头数、簇、MBR、DBR)
Rails源码阅读(二)_script/server
如果明白了script/console,那么理解script/server会轻松些;
区别在于,启动console其实是需要加载irb,而启动server则要处理http请求;
http-server:动手写rails(一)_Rack标准和HttpServer之WEBrick
script/server的代码:
require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
第一行是准备环境, 第二行才是启动server
commands/server.rb的主要代码:
server = Rack::Handler.get(ARGV.first) rescue nil unless server begin server = Rack::Handler::Mongrel rescue LoadError => e server = Rack::Handler::WEBrick end end puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}#{options[:path]}" %w(cache pids sessions sockets).each do |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) end if options[:detach] Process.daemon pid = "#{RAILS_ROOT}/tmp/pids/server.pid" File.open(pid, 'w'){ |f| f.write(Process.pid) } at_exit { File.delete(pid) if File.exist?(pid) } end ENV["RAILS_ENV"] = options[:environment] RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) if File.exist?(options[:config]) config = options[:config] if config =~ /\.ru$/ cfgfile = File.read(config) if cfgfile[/^#\\(.*)/] opts.parse!($1.split(/\s+/)) end inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) else require config inner_app = Object.const_get(File.basename(config, '.rb').capitalize) end else require RAILS_ROOT + "/config/environment" inner_app = ActionController::Dispatcher.new end if options[:path].nil? map_path = "/" else ActionController::Base.relative_url_root = options[:path] map_path = options[:path] end app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] use Rails::Rack::Debugger if options[:debugger] map map_path do use Rails::Rack::Static run inner_app end }.to_app puts "=> Call with -d to detach" trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" begin server.run(app, options.merge(:AccessLog => [])) ensure puts 'Exiting' end
#(1) 可以指定maping的path,这样在rack中就map到这个路径:map map_path
if options[:path].nil? map_path = "/" else ActionController::Base.relative_url_root = options[:path] map_path = options[:path] end
#(2) 在启动rack之前,先要加载rails环境和组建
require RAILS_ROOT + "/config/environment"
#(3) 使用rack启动,用WEBrick做web服务,见下面分析。
commands/server.rb的启动,除了一些配置如端口等外,更重要的是用到了两个东西:
#1 server:WEBrick|Mongrel,用来处理http等
server = Rack::Handler.get(ARGV.first) rescue nil unless server begin server = Rack::Handler::Mongrel rescue LoadError => e server = Rack::Handler::WEBrick end end
看看WEBrick的源码:继承于::WEBrick::HTTPServlet::AbstractServlet
module Rack module Handler class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet def self.run(app, options={}) end def self.shutdown end def initialize(server, app) super server @app = Rack::ContentLength.new(app) end def service(req, res)
#2 rack 和 middleware
rack的应用上来说,比较简单直接:
#1 rackXXX = generate_a_rack_app #2 builder = Rack::Builder.new{ user middlewareXXX ... ... run rackXXX } #3 Rack::Handler::HandlerXXX.run builder
对应的server启动代码为:
#1 generate a racke proc # 这里只要实现call方法就行 inner_app = ActionController::Dispatcher.new #Dispatcher实现了call方法 #2 RackBuilder app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] use Rails::Rack::Debugger if options[:debugger] map map_path do use Rails::Rack::Static run inner_app end }.to_app #3 RackHandler
server = Rack::Handler.get(ARGV.first) rescue nil unless server begin server = Rack::Handler::Mongrel rescue LoadError => e server = Rack::Handler::WEBrick end end server.run(app, options.merge(:AccessLog => []))
这里要明白流程:
启动server是要启动什么?
HttpServer(CGIserver),这里就是WEBrick或者Mongrel
server怎么和ruby联系上了?
WEBrick等遵循rack标准,server.run(rack_app, options)
ruby写一个rack的app即可
rails里的rack是什么?
是:ActionController::Dispatcher
出处代码:inner_app = ActionController::Dispatcher.new
还需要哪些知识?
rack的介绍,原理,好处,标准,使用等
WEBrick活Mongrel的介绍和使用
====结束====
=== ===
== ==
= =
| |
发表评论
-
Rails外如何启动rails的类自动加载_activates autoloading using ActiveSupport 3.x
2016-06-22 12:08 736The following cod ... -
Rails源码阅读(13)rails中的autoload和ruby的autoload
2014-07-30 17:13 2041Rails源码阅读(13)rails中的autoload和 ... -
Rails源码阅读(12)叫Rails的模块module_Rails常量使用
2014-07-02 09:35 1167The module nams "Rail ... -
Rails源码阅读(11)Rails使用bundle保持多机器环境gem版本的一致性
2013-09-05 19:21 1556Rails源码阅读(11)Rails使用bundle ... -
Rails源码阅读(十)在console 使用ActionController::Integration::Session
2012-05-05 14:48 1839Rails源码阅读(十)在console 使用Actio ... -
Rails源码阅读(九)ActionView::Base_用户请求在rails中的处理流程(4)
2012-04-08 18:19 2286Rails源码阅读(九)ActionView::Base_用户 ... -
Rails源码阅读(八)ActionController::Base_用户请求在rails中的处理流程(3)
2012-04-06 23:01 1799Rails源码阅读(八)Actio ... -
Rails源码阅读(七)ActionController::Dispatcher_用户请求在rails中的处理流程(2)
2012-04-06 22:25 1441Rails源码阅读(七)Actio ... -
动手写rails(二)Rails_Ruby_ERB使用_模板_定制
2012-04-07 20:46 2646动手写rails(二)Rails_Ruby_ERB使用_模板_ ... -
Rails源码阅读(六)ActionController::Dispatcher_用户请求在rails中的处理流程(1)
2012-03-28 00:17 1784Rails源码阅读(六)ActionController::D ... -
Rails源码阅读(零)_config/boot
2012-03-15 11:56 1859不论是script/console 还是 script/ser ... -
动手写rails(一)_Rack标准和HttpServer之WEBrick
2012-03-15 07:22 2156无论如何,最终的结果是要启动一个server来接受请求, ... -
Rails源码阅读(五)with_scope 和 named_scope
2012-02-02 15:24 1510Rails源码阅读(四)with_scope and name ... -
Rails源码阅读(四)gem_rubygems之require_Rails_require_深入理解(一)
2011-11-16 10:39 2198Rails源码阅读(四)rubygems之require_Ra ... -
Rails源码阅读(三)Rails::Initializer
2011-10-14 10:58 2226启动的落脚点 不论启动console还是启动serve ... -
Rails源码阅读(一)_script/console
2011-09-05 11:13 2189Rails源码阅读_script/console启动 ...
相关推荐
在Rails 2.2.2时代,Webrick是常见的选择,只需在应用目录下运行`ruby script/server`启动。 10. **测试**:Rails的测试驱动开发(TDD)是其核心理念之一。通过`rake test`运行测试,确保代码正常工作。 11. **开发...
- 创建服务:使用 `ruby script/server -e production` 命令启动Redmine服务,并将该命令注册为Windows服务。 #### 四、总结 通过以上步骤,您应该已经在Windows环境下成功安装并配置好了Redmine-1.2.1。Redmine的...
- 在Redmine目录下,使用`ruby script/rails server webrick -e production`启动服务 - 如果需要,将3000端口添加到防火墙允许列表中 - 可以使用`screen`命令后台运行服务,通过`alt+a+d`退出屏幕 - 访问`...
通过运行`ruby script/server webrick -e production`启动内置的Webrick服务器,这将使Redmine在本地3000端口上可用。在浏览器中访问`http://localhost:3000`,如果一切配置正确,你应该能够正常访问Redmine界面。 ...
在Redmine根目录下运行`ruby script/server`,然后在浏览器中输入`http://localhost:3000`。如果页面能够正常显示,那么恭喜你,Redmine已成功安装。 总的来说,Redmine的安装过程涉及到Ruby环境的搭建、相关Gem的...
$ ./bin/rails server Puma 预习 在Heroku上 部署方式 自动预览部署 :ribbon: 当Pull请求合并到master ,CircleCI将部署到Heroku。 手动部署到Heroku :moai: 您可以部署到来检查任何分支。 $ git push -f heroku...
8. **server** 或 **backend** 目录(如果存在):可能包含了后端服务器的代码,如Node.js、Python Flask或Ruby on Rails,它们处理来自前端的请求,与硬件设备通信,并返回数据。 为了深入了解"web_rocon_remocon...
"Java Servlet编程(第二版)"英文版专注于服务器端编程,"Java Script 高端程序设计(精华)"则关注JavaScript,这是构建交互式Web应用的关键。"《Java EE 编程技术》源代码和课件"为Java企业级应用提供了实践材料。 ...