有些指南(例如)建议使用这种方法来启动自己的Web服务器。
bundle exec rails server puma
但我一直都是直接使用puma
启动服务器的
bundle exec puma
当通过rails server
启动puma(或任何其他服务器)时,是否会发生特殊的事情?
有些指南(例如)建议使用这种方法来启动自己的Web服务器。
bundle exec rails server puma
但我一直都是直接使用puma
启动服务器的
bundle exec puma
当通过rails server
启动puma(或任何其他服务器)时,是否会发生特殊的事情?
当你使用rails s <server>
命令时,该服务器将从Rails命令启动,并且知道Rails环境。
这使得例如可以使用任何rails server
命令提供的功能和标志。
rails s --help
Usage: rails server [mongrel, thin, etc] [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
Default: 0.0.0.0
-c, --config=file Use custom rackup configuration file
-d, --daemon Make server run as a Daemon.
-u, --debugger Enable ruby-debugging for the server.
-e, --environment=name Specifies the environment to run this server under (test/development/production).
Default: development
-P, --pid=pid Specifies the PID file.
Default: tmp/pids/server.pid
-h, --help Show this help message.
例如,您可以通过传递 --debugger
或将服务器设置为守护进程来将调试器附加到会话。
第二个优点是您可以对 Puma
实例进行版本控制,因为您必须在 Gemfile
中列出该 gem。如果像您现在这样使用 bundle exec
启动,则已经实现了此功能。
相反,当您仅运行 $ puma
(或 $ bundle exec puma
)时,不会经过 Rails 系统。Puma
将尝试查找 rack 引导文件并使用它(因为 Rails 在应用程序根目录提供了一个 config.ru
脚本,所以它可以正常工作)。
一般来说,如果您不需要向服务器传递特定选项,则没有真正的区别。我喜欢 Puma,并且倾向于在某些项目中使用它,即使在生产环境中我们使用 Unicorn,因此作为独立命令运行 $ puma
很方便,因为我不需要将其添加到 Gemfile
中。
然而,如果我的整个堆栈都使用 Puma
,我可能会选择 $ rails s puma
。这也是文档中建议的命令。
bundle exec puma
(2018年12月7日)。 - vinegarbinpuma
有一个单独的环境概念,用于选择配置文件。而bin/rails s
会自动获取这个环境(从RAILS_ENV
)。 - x-yuri