You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you package a Rails application on Packager.io, by default you'll end up with init scripts to run your application with the web server you defined in your Procfile. This allows you to install the package on any server and get your application running very easily with my-app scale web=1.
However, if you're already using Passenger for your deployments, you might want to keep it that way, in which case you can still benefit from the ease of installation provided by packages, but serve your application using Passenger.
In the rest of this article, we're assuming that nginx and Passenger are already installed on your server, and that your application name is my-app. You can very easily adapt the following instructions for apache2 + Passenger.
Add a new file to your repository
Passenger will need to know which ruby you want to use to load the application. We could directly point to the ruby binary embedded with your package, however it would not load any of the environment variables that you defined, which would not allow the application to start properly. The easiest way to fix this is to create a new file that will delegate any arguments to the CLI that comes with every package, which will take care of all of this for you.
For instance, you could create a new file in packaging/ruby with the following content:
Wait a few seconds until your new package is generated, then install it on your server with the usual instructions.
Update your nginx server configuration
We can now simply update the nginx configuration so that the passenger_ruby configuration option points to your application's ruby. A minimal nginx configuration would look like:
That's it! Passenger should now load and serve your application when you access http://my-server.com:80.
Bonus points: automatically migrate and restart your application after an update
Passenger provides a mechanism to restart your application by touching a specific file at tmp/restart.txt. We can choose to automate this process by adding a postinstall hook to our package, and we'll also automatically run the database migrations if a DATABASE_URL is properly set:
When you package a Rails application on Packager.io, by default you'll end up with init scripts to run your application with the web server you defined in your
Procfile
. This allows you to install the package on any server and get your application running very easily withmy-app scale web=1
.However, if you're already using Passenger for your deployments, you might want to keep it that way, in which case you can still benefit from the ease of installation provided by packages, but serve your application using Passenger.
In the rest of this article, we're assuming that nginx and Passenger are already installed on your server, and that your application name is
my-app
. You can very easily adapt the following instructions for apache2 + Passenger.Add a new file to your repository
Passenger will need to know which
ruby
you want to use to load the application. We could directly point to theruby
binary embedded with your package, however it would not load any of the environment variables that you defined, which would not allow the application to start properly. The easiest way to fix this is to create a new file that will delegate any arguments to the CLI that comes with every package, which will take care of all of this for you.For instance, you could create a new file in
packaging/ruby
with the following content:Then give it the right permissions, commit to your repository and push:
Wait a few seconds until your new package is generated, then install it on your server with the usual instructions.
Update your nginx server configuration
We can now simply update the nginx configuration so that the
passenger_ruby
configuration option points to your application'sruby
. A minimal nginx configuration would look like:Reload nginx:
That's it! Passenger should now load and serve your application when you access
http://my-server.com:80
.Bonus points: automatically migrate and restart your application after an update
Passenger provides a mechanism to restart your application by touching a specific file at
tmp/restart.txt
. We can choose to automate this process by adding a postinstall hook to our package, and we'll also automatically run the database migrations if aDATABASE_URL
is properly set:In your
.pkgr.yml
file add the following line:Now create a new file at
packaging/hooks/postinstall.sh
with the following content:Finally, add and commit these files to your repository and push to generate a new package:
Now, every time you install a new version of your package, migrations will be run and Passenger will restart your application.
Happy packaging!
The text was updated successfully, but these errors were encountered: