passenger standalone with god on rvm

Some time ago I have migrated my server to nginx. Now I got first chance to setup rails application on it.

Searching for new experiences I have tried a new setup – passenger standalone on rvm monitored by god and cron (see Q&A on the end).

Prerequisite to that guide is a working deployment script (putting files on server and db:migration working also rvm set up on server). Important is also to replace all occurrences of “/path/to/application” with your real path to application on server.

Nginx is also required, in case you do not have it already you can install it with following command (ubuntu server on linode):

sudo apt-get install nginx

Assuming you have an deploy script up and running you need to add few changes before deployment.

We need to install god and passenger (which we added on the beginning):

bundle install --without=development test cucumber

please note that cucumber is only required when you use it, skip this param if cucumber is only an tasty vegetable for you.

One of most important steps is to create god wrapper that will be used for starting application (replace my_ruby_1.9.2@my_application with your rvm identifier):

rvm wrapper my_ruby_1.9.2@my_application local god

Next we need to make test run of passenger, it will also compile nginx and notify of any problems if it finds any:

cd /path/to/application/current ; passenger start

Passenger will be started on port 3000 if there is no firewall on server (you missed to install it) then you can visit your browser and enter your server.address:3000. adding -p 8080 would server application on the port 8080 (welcome java users). To stop passenger just hit CTRL+C :)

When that works we can set up proxy in the main nginx configuration. On ubuntu (linode) the steps look as follows:

sudo vim /etc/nginx/available-sites/your-application.conf

and put the following content (do not forget to replace my_domain with your dns name of the server):

That’s all, in one minute your server should be ready, do not forget that first call to passenger application might be sluggish, but it is only the first one when rails need to be initialized, rest of them is really fast.

To check the whole setup you could put small change in some view, deploy application, refresh your browsers (wait few seconds for rails startup) and check your results.

Q & A

Q: Why passenger, why not unicorn or thin ?

A: It is extremely easy to set up.

A: It is one of the fastest ruby servers (some say it is fastest one).

I’d question the specifity of using passenger, as unicorn is faster and thin and unicorn support some cool things that passenger doesn’t. The concept is a nice one, but I’m not a fan of passenger. I’m not asking you to defend the reasoning, but perhaps be open to more than just a tool that comes prepackaged with some interesting features.

@erwann
It’s not exactly bundled but it gets installed as you start passenger-standalone.

I use two nginxs for separation reasons, so I can run multiple rails applications in total separation, without carrying about ruby, rails, passenger or any other gem version or compatibility.
It gives me also stability, I can run whatever without influencing the main nginx. Next issue is limiting resources per application, in passenger you can limit amount of threads per server only not per application. Using passenger-standalone you keep the limit per application.
Setup I provided can be quite easily modified to provide hosting with central god run from root user and set of sudo permissions allowing to interact only with your passenger-standalone instance.
Also the memory is so low that it justs asks itself for this, the main instance of nginx takes right now about 2-3MB