简体   繁体   English

`rails server puma`与`puma`

[英]`rails server puma` vs. `puma`

Some guides ( example ) recommend this to start one's webserver 一些指南( 示例 )建议您启动一个网络服务器

bundle exec rails server puma

But I've always just started the server with puma directly 但我总是直接用puma启动服务器

bundle exec puma

Does something special happening when firing up puma (or any other server) via rails server ? 通过rails server启动puma(或任何其他服务器)时会发生什么特别的事情吗?

When you use rails s <server> , the server is launched from the Rails command and is aware of the Rails environment. 使用rails s <server> ,将从Rails命令启动服务器并了解Rails环境。

This makes possible, for example, to use any of the features and flags offered by the rails server command . 例如,这可以使用rails server command提供的任何功能和标志。

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.

For instance, you can attach a debugger to the session passing --debugger or daemonize the server. 例如,您可以将调试器附加到传递--debugger或daemonize服务器的会话。

The second advantage is that you can version the Puma instance, since you will have to list the gem in the Gemfile . 第二个优点是您可以对Puma实例进行版本控制,因为您必须在Gemfile列出gem。 This is already true if you start it with bundle exec like you are doing. 如果您像使用bundle exec一样启动它,那么这已经成立了。

Conversely, when you simply run $ puma (or $ bundle exec puma ) you're not passing through the Rails system. 相反,当你只是运行$ puma (或$ bundle exec puma )时,你并没有通过Rails系统。 Puma will try to find a rack bootstrap file and will use it (it works because Rails provides a config.ru script in the application root. Puma将尝试找到一个机架引导程序文件并将使用它(它的工作原理是因为Rails在应用程序根目录中提供了config.ru脚本。

Generally speaking, there is no real difference if you don't need to pass specific options to the server. 一般来说,如果您不需要将特定选项传递给服务器,则没有实际区别。 I like puma and I tend to use it in some projects even when on production we use Unicorn, thus running $ puma as a standalone command is handy because I don't need to add it to the Gemfile . 我喜欢puma,我倾向于在某些项目中使用它,即使在生产时我们使用Unicorn,因此运行$ puma作为独立命令很方便,因为我不需要将它添加到Gemfile

However, I would probably go with $ rails s puma if my entire stack uses Puma . 但是,如果我的整个堆栈使用Puma ,我可能会使用$ rails s puma This is also the command suggested in the documentation . 这也是文档中建议命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM