Greg Blass
Greg Blass

Reputation: 3660

Proper way to start nginx/passenger (non-standalone) on Ubuntu with Rails 3?

I configured my Rails 3 production app about 6 months ago on Ubuntu running nginx/passenger, using git and Capistrano for deployment.

Fast forward to last week - The data center I was using (DigitalOcean NYC) actually had a complete power failure (and the battery backup didn't work) - resulting in my server shutting completely down.

I did not set passenger or mysql to start on reboot, so when the hardware server restarted, my app was still down.

I really did not know much about what I was doing at the time when I launched it (since it was my first production server that I have worked with), and I followed a guide to get it up and running.

When I attempted to get the app running again, I managed to start mysqld no problem - but for the life of me couldn't remember how to get nginx/passenger running again.

Since time was of the essence (my client needed the app up and running ASAP), I ended up getting the app back up and running by navigating to my app directory (/current) and using the command:

passenger start -p 80 -e production

This did the trick but actually started Passenger Standalone. It seems to work fine (it is not a big or complicated app at all, maybe a few users at a time). I can navigate back to my directory and start and stop it using the above command (and passenger stop -p 80).

However, now my capistrano deploy (cap deploy) no longer restarts the server on a deploy (it is trying to run touch tmp/restart.txt) - which even if I try to run manually, does nothing since the server is running Passenger Standalone.

I can't remember how I got the server up and running in the first place because it was so long ago. I'm not using RVM - just the version of Ruby running directly on the server.

Does anyone know the correct command to start nginx/passenger (not standalone) on Ubuntu?

And even a step further - how I can get mysqld and nginx/passenger to automatically load on a hard server restart?

Upvotes: 0

Views: 907

Answers (1)

Hongli
Hongli

Reputation: 18924

Capistrano does not restart the server because it actually creates a new app directory (/u/apps/.../releases/xxx), while Passenger Standalone is still running in the old app directory (/u/apps/.../releases/yyy). Therefore touching restart.txt doesn't work. Instead, you have to restart Passenger Standalone like this:

cd /path-to-previous-release && passenger stop -p 80
cd /path-to-current-release && passenger start -p 80 -e production

You mentioned you want to start nginx/passsenger. I assume that you mean the Nginx mode. Here's what you need to do:

  1. Install Phusion Passenger using the official Passenger APT repository.
  2. There is no step 2. If you did step 1, then the Ubuntu package will automatically configure Nginx to start at system boot, which will automatically start Passenger as well.

I don't understand why you ask how you can get mysqld to automatically start on a hard server restart. Mysqld is always started during system boot. You don't have to do anything.

Upvotes: 3

Related Questions