Question

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

bundle exec puma

Does something special happening when firing up puma (or any other server) via rails server?

Was it helpful?

Solution

When you use rails s <server>, the server is launched from the Rails command and is aware of the Rails environment.

This makes possible, for example, to use any of the features and flags offered by the 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.

The second advantage is that you can version the Puma instance, since you will have to list the gem in the Gemfile. This is already true if you start it with bundle exec like you are doing.

Conversely, when you simply run $ puma (or $ bundle exec puma) you're not passing through the Rails system. 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.

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.

However, I would probably go with $ rails s puma if my entire stack uses Puma. This is also the command suggested in the documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top