Running passenger utilities on an rbenv’d production machine

The passenger-memory-stats and passenger-status utilities are super duper useful for checking on your production machine, troubleshooting problems, seeing how it’s handling load, etc.

Our production machine has an rbenv installed in a particular user account that owns the app.  That’s Method 1 of this rbenv wiki page.   We experimented with an rbenv shared install (I wrote much of that wiki page based on my attempts), but found “Method 1” to be simpler and less error-prone in the end.

We deploy with passenger and apache, so we install passenger-apache in that rbenv. Easy to do, just log in as that user and run “gem install passenger-apache” or whatever.

Only problem is, how do you run the passenger-status and passenger-memory-stats utility now?  Can’t log in as the app user to do it, because you need sudo, and the app user doesn’t have it (and shouldn’t have general sudo). You could give that app user special permissions to sudo just certain scripts; and then you’d need rbenv sudo becuase ordinary sudo doesn’t actually work right for rbenv command lines like this; and then it would still be annoying because, when troubleshooting something urgent, I want to intersperse passenger-stats with other things requring sudo, like killing and restarting processes.

A complicated setup for still not a great workspace.

Solution? I just wrote a simple 10 line bash wrapper script, which I call “catalyst-passenger” (catalyst is the name of my app and account rbenv runs in), and stick it in /usr/local/bin.  Now you can just run “catalyst-passenger status”, “catalyst-passenger memory-stats” or even “catalyst-passenger config –version”, and it Just Works.

Here’s my script (DOH, WordPress’s ability to embed a gist, which I was so excited to discover yesterday, seems to be all wonky with this one, I wonder if the gist upgrade broke it. DOH. Here’s the gist direct.)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s