rubypassengerphusion

Start Phusion Passenger from Ruby code


I'd like to start the server from inside my gem code, the way Rails starts Unicorn, Puma, Webrick or whatever with "rails server". I'd like to have a binary like "mygem server" and that would start Passenger.

I tried with backticks but I'd like to avoid spawning another process if it's at all possible. (Also, I lost the stdout from Passenger when I did that.)

Is the command line the only way to start Passenger?


Solution

  • Passanger is a C++ "gem" that actually runs the Ruby layer separated from the root server process.

    The developers consider this approach to protect the server from Ruby related issues (I think this isn't necessary, but it's definitely interesting).

    This leaves you with a couple of options:

    1. You could use Kernel.exec which replaces the current process with the command line you provide.

    2. You could use another server, such as Puma, Iodine, Agoo or whatever you fancy.

      Each server has their advantages and their disadvantages so test and pick and choose.

      I know from experience that you can start all of them from within a block of code (or so I recall).